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>
diff --git a/samples/kobject/kobject-example.c b/samples/kobject/kobject-example.c
index 86ea0c3..01562e0 100644
--- a/samples/kobject/kobject-example.c
+++ b/samples/kobject/kobject-example.c
@@ -40,8 +40,9 @@
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 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);
/*
diff --git a/samples/kobject/kset-example.c b/samples/kobject/kset-example.c
index 5dce351..ab5e447 100644
--- a/samples/kobject/kset-example.c
+++ b/samples/kobject/kset-example.c
@@ -124,8 +124,9 @@
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 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