Skip to content

Commit

Permalink
samples/kobject/: avoid world-writable sysfs files.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
rustyrussell committed May 14, 2014
1 parent f92201c commit de51098
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions samples/kobject/kobject-example.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);


/*
Expand Down
7 changes: 4 additions & 3 deletions samples/kobject/kset-example.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit de51098

Please sign in to comment.