Skip to content

Commit de51098

Browse files
committed
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>
1 parent f92201c commit de51098

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

‎samples/kobject/kobject-example.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ static ssize_t foo_store(struct kobject *kobj, struct kobj_attribute *attr,
4040
return count;
4141
}
4242

43+
/* Sysfs attributes cannot be world-writable. */
4344
static struct kobj_attribute foo_attribute =
44-
__ATTR(foo, 0666, foo_show, foo_store);
45+
__ATTR(foo, 0664, foo_show, foo_store);
4546

4647
/*
4748
* 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,
7374
}
7475

7576
static struct kobj_attribute baz_attribute =
76-
__ATTR(baz, 0666, b_show, b_store);
77+
__ATTR(baz, 0664, b_show, b_store);
7778
static struct kobj_attribute bar_attribute =
78-
__ATTR(bar, 0666, b_show, b_store);
79+
__ATTR(bar, 0664, b_show, b_store);
7980

8081

8182
/*

‎samples/kobject/kset-example.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ static ssize_t foo_store(struct foo_obj *foo_obj, struct foo_attribute *attr,
124124
return count;
125125
}
126126

127+
/* Sysfs attributes cannot be world-writable. */
127128
static struct foo_attribute foo_attribute =
128-
__ATTR(foo, 0666, foo_show, foo_store);
129+
__ATTR(foo, 0664, foo_show, foo_store);
129130

130131
/*
131132
* 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,
157158
}
158159

159160
static struct foo_attribute baz_attribute =
160-
__ATTR(baz, 0666, b_show, b_store);
161+
__ATTR(baz, 0664, b_show, b_store);
161162
static struct foo_attribute bar_attribute =
162-
__ATTR(bar, 0666, b_show, b_store);
163+
__ATTR(bar, 0664, b_show, b_store);
163164

164165
/*
165166
* Create a group of attributes so that we can create and destroy them all

0 commit comments

Comments
 (0)