Commit b0a65b0cccd477b2fd8b7adad0ac39433df54829
Committed by
Rusty Russell
1 parent
18eb74fa94
Exists in
ti-lsk-linux-4.1.y
and in
10 other branches
param: do not set store func without write perm
When a module_param is defined without DAC write permissions, it can still be changed at runtime and updated. Drivers using a 0444 permission may be surprised that these values can still be changed. For drivers that want to allow updates, any S_IW* flag will set the "store" function as before. Drivers without S_IW* flags will have the "store" function unset, unforcing a read-only value. Drivers that wish neither "store" nor "get" can continue to use "0" for perms to stay out of sysfs entirely. Old behavior: # cd /sys/module/snd/parameters # ls -l total 0 -r--r--r-- 1 root root 4096 Dec 11 13:55 cards_limit -r--r--r-- 1 root root 4096 Dec 11 13:55 major -r--r--r-- 1 root root 4096 Dec 11 13:55 slots # cat major 116 # echo -1 > major -bash: major: Permission denied # chmod u+w major # echo -1 > major # cat major -1 New behavior: ... # chmod u+w major # echo -1 > major -bash: echo: write error: Input/output error Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Showing 1 changed file with 3 additions and 1 deletions Side-by-side Diff
kernel/params.c
... | ... | @@ -645,7 +645,9 @@ |
645 | 645 | sysfs_attr_init(&mk->mp->attrs[mk->mp->num].mattr.attr); |
646 | 646 | mk->mp->attrs[mk->mp->num].param = kp; |
647 | 647 | mk->mp->attrs[mk->mp->num].mattr.show = param_attr_show; |
648 | - mk->mp->attrs[mk->mp->num].mattr.store = param_attr_store; | |
648 | + /* Do not allow runtime DAC changes to make param writable. */ | |
649 | + if ((kp->perm & (S_IWUSR | S_IWGRP | S_IWOTH)) != 0) | |
650 | + mk->mp->attrs[mk->mp->num].mattr.store = param_attr_store; | |
649 | 651 | mk->mp->attrs[mk->mp->num].mattr.attr.name = (char *)name; |
650 | 652 | mk->mp->attrs[mk->mp->num].mattr.attr.mode = kp->perm; |
651 | 653 | mk->mp->num++; |