Commit de5109898a8a0cb001abcb6916bef4efa32bf39b

Authored by Rusty Russell
1 parent f92201c348

samples/kobject/: avoid world-writable sysfs files.

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>

Showing 2 changed files with 8 additions and 6 deletions Side-by-side Diff

samples/kobject/kobject-example.c
... ... @@ -40,8 +40,9 @@
40 40 return count;
41 41 }
42 42  
  43 +/* Sysfs attributes cannot be world-writable. */
43 44 static struct kobj_attribute foo_attribute =
44   - __ATTR(foo, 0666, foo_show, foo_store);
  45 + __ATTR(foo, 0664, foo_show, foo_store);
45 46  
46 47 /*
47 48 * More complex function where we determine which variable is being accessed by
48 49  
... ... @@ -73,9 +74,9 @@
73 74 }
74 75  
75 76 static struct kobj_attribute baz_attribute =
76   - __ATTR(baz, 0666, b_show, b_store);
  77 + __ATTR(baz, 0664, b_show, b_store);
77 78 static struct kobj_attribute bar_attribute =
78   - __ATTR(bar, 0666, b_show, b_store);
  79 + __ATTR(bar, 0664, b_show, b_store);
79 80  
80 81  
81 82 /*
samples/kobject/kset-example.c
... ... @@ -124,8 +124,9 @@
124 124 return count;
125 125 }
126 126  
  127 +/* Sysfs attributes cannot be world-writable. */
127 128 static struct foo_attribute foo_attribute =
128   - __ATTR(foo, 0666, foo_show, foo_store);
  129 + __ATTR(foo, 0664, foo_show, foo_store);
129 130  
130 131 /*
131 132 * More complex function where we determine which variable is being accessed by
132 133  
... ... @@ -157,9 +158,9 @@
157 158 }
158 159  
159 160 static struct foo_attribute baz_attribute =
160   - __ATTR(baz, 0666, b_show, b_store);
  161 + __ATTR(baz, 0664, b_show, b_store);
161 162 static struct foo_attribute bar_attribute =
162   - __ATTR(bar, 0666, b_show, b_store);
  163 + __ATTR(bar, 0664, b_show, b_store);
163 164  
164 165 /*
165 166 * Create a group of attributes so that we can create and destroy them all