Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

umh: simplify the capability pointer logic

The usermodehelper code uses two fake pointers for the two capability
cases: CAP_BSET for reading and writing 'usermodehelper_bset', and
CAP_PI to read and write 'usermodehelper_inheritable'.

This seems to be a completely unnecessary indirection, since we could
instead just use the pointers themselves, and never have to do any "if
this then that" kind of logic.

So just get rid of the fake pointer values, and use the real pointer
values instead.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Kees Cook <keescook@chromium.org>
Cc: Iurii Zaikin <yzaikin@google.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

+5 -13
+5 -13
kernel/umh.c
··· 32 32 33 33 #include <trace/events/module.h> 34 34 35 - #define CAP_BSET (void *)1 36 - #define CAP_PI (void *)2 37 - 38 35 static kernel_cap_t usermodehelper_bset = CAP_FULL_SET; 39 36 static kernel_cap_t usermodehelper_inheritable = CAP_FULL_SET; 40 37 static DEFINE_SPINLOCK(umh_sysctl_lock); ··· 509 512 /* 510 513 * convert from the global kernel_cap_t to the ulong array to print to 511 514 * userspace if this is a read. 515 + * 516 + * Legacy format: capabilities are exposed as two 32-bit values 512 517 */ 518 + cap = table->data; 513 519 spin_lock(&umh_sysctl_lock); 514 - if (table->data == CAP_BSET) 515 - cap = &usermodehelper_bset; 516 - else if (table->data == CAP_PI) 517 - cap = &usermodehelper_inheritable; 518 - else 519 - BUG(); 520 - 521 - /* Legacy format: capabilities are exposed as two 32-bit values */ 522 520 cap_array[0] = (u32) cap->val; 523 521 cap_array[1] = cap->val >> 32; 524 522 spin_unlock(&umh_sysctl_lock); ··· 547 555 struct ctl_table usermodehelper_table[] = { 548 556 { 549 557 .procname = "bset", 550 - .data = CAP_BSET, 558 + .data = &usermodehelper_bset, 551 559 .maxlen = 2 * sizeof(unsigned long), 552 560 .mode = 0600, 553 561 .proc_handler = proc_cap_handler, 554 562 }, 555 563 { 556 564 .procname = "inheritable", 557 - .data = CAP_PI, 565 + .data = &usermodehelper_inheritable, 558 566 .maxlen = 2 * sizeof(unsigned long), 559 567 .mode = 0600, 560 568 .proc_handler = proc_cap_handler,