2.5 capability.c cleanup
Subsystems (2)
PATCH 1/1 2.5 capability.c cleanup
Linus et al,
I started looking into a couple FIXMEs in kernel/capability.c and I ended up with a fairly largish patch (although not quite so much changes to object code).
First, it is unsafe to touch task->cap_* while not holding task_capability_lock. The most notable occurrence of this is sys_access which saves the current cap_* values, changes them, does its business, then restores them. In between all this they can change and then restored to old values. Unfortunately we cannot just grab the lock here since the function can sleep - I marked this with a FIXME for now.
Second, I formalized the locking rules with task_capability_lock. I declared the lock in include/linux/capability.h so other code can grab it.
Finally, there is a whole boatload of code cleanup:
- remove conditional locking/unlocking - that is just gross
- don't pointlessly grab the read_lock twice
- add/remove/edit comments
- change some types (int -> pid_t, etc)
- static inline two small functions that are called only once each
- remove two FIXMEs
- general code cleanup for readability and performance
TODO:
- fix sys_access and other cap_* accesses
- do something about the annoying oddball 5-space indentation in kernel/capability.c !!
Patch is against 2.5.19, please apply.
Robert Love
fs/open.c +8 -1
@@ -338,7 +338,14 @@ current->fsuid = current->uid; current->fsgid = current->gid; -/* Clear the capabilities if we switch to a non-root user */ +/* +* Clear the capabilities if we switch to a non-root user +* +* FIXME: There is a race here against sys_capset. The +* capabilities can change yet we will restore the old +* value below. We should hold task_capabilities_lock, +* but we cannot because user_path_walk can sleep. +*/ if (current->uid)cap_clear (current->cap_effective);else
include/linux/capability.h +4 -0
@@ -41,6 +41,10 @@#ifdef __KERNEL__ +#include <linux/spinlock.h> + +extern spinlock_t task_capability_lock; +/* #define STRICT_CAP_T_TYPECHECKS */ #ifdef STRICT_CAP_T_TYPECHECKS
kernel/capability.c +74 -92
279 lines not on this page · raw message