samples/kobject/: avoid world-writable sysfs files.
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 14 May 2014 01:03:50 +0000 (10:33 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 14 May 2014 01:23:57 +0000 (10:53 +0930)
In line with practice for module parameters, we're adding a build-time
check that sysfs files aren't world-writable.

Cc: Greg Kroah-Hartman <greg@kroah.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
samples/kobject/kobject-example.c
samples/kobject/kset-example.c

index 86ea0c3ad97511e02a75003dc3c8556990b0e9a9..01562e0d499202a0005c61443f36bdf11a33160c 100644 (file)
@@ -40,8 +40,9 @@ static ssize_t foo_store(struct kobject *kobj, struct kobj_attribute *attr,
        return count;
 }
 
+/* Sysfs attributes cannot be world-writable. */
 static struct kobj_attribute foo_attribute =
-       __ATTR(foo, 0666, foo_show, foo_store);
+       __ATTR(foo, 0664, foo_show, foo_store);
 
 /*
  * More complex function where we determine which variable is being accessed by
@@ -73,9 +74,9 @@ static ssize_t b_store(struct kobject *kobj, struct kobj_attribute *attr,
 }
 
 static struct kobj_attribute baz_attribute =
-       __ATTR(baz, 0666, b_show, b_store);
+       __ATTR(baz, 0664, b_show, b_store);
 static struct kobj_attribute bar_attribute =
-       __ATTR(bar, 0666, b_show, b_store);
+       __ATTR(bar, 0664, b_show, b_store);
 
 
 /*
index 5dce351f131f8c154048124bc1bf3a6a32cb32c7..ab5e447ec23871b66b46049129dfaafc6f3f287d 100644 (file)
@@ -124,8 +124,9 @@ static ssize_t foo_store(struct foo_obj *foo_obj, struct foo_attribute *attr,
        return count;
 }
 
+/* Sysfs attributes cannot be world-writable. */
 static struct foo_attribute foo_attribute =
-       __ATTR(foo, 0666, foo_show, foo_store);
+       __ATTR(foo, 0664, foo_show, foo_store);
 
 /*
  * More complex function where we determine which variable is being accessed by
@@ -157,9 +158,9 @@ static ssize_t b_store(struct foo_obj *foo_obj, struct foo_attribute *attr,
 }
 
 static struct foo_attribute baz_attribute =
-       __ATTR(baz, 0666, b_show, b_store);
+       __ATTR(baz, 0664, b_show, b_store);
 static struct foo_attribute bar_attribute =
-       __ATTR(bar, 0666, b_show, b_store);
+       __ATTR(bar, 0664, b_show, b_store);
 
 /*
  * Create a group of attributes so that we can create and destroy them all