Skip to content

Commit e778361

Browse files
committed
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 <[email protected]> Cc: Eric Biederman <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Kees Cook <[email protected]> Cc: Iurii Zaikin <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent fb35342 commit e778361

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

kernel/umh.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232

3333
#include <trace/events/module.h>
3434

35-
#define CAP_BSET (void *)1
36-
#define CAP_PI (void *)2
37-
3835
static kernel_cap_t usermodehelper_bset = CAP_FULL_SET;
3936
static kernel_cap_t usermodehelper_inheritable = CAP_FULL_SET;
4037
static DEFINE_SPINLOCK(umh_sysctl_lock);
@@ -512,16 +509,11 @@ static int proc_cap_handler(struct ctl_table *table, int write,
512509
/*
513510
* convert from the global kernel_cap_t to the ulong array to print to
514511
* userspace if this is a read.
512+
*
513+
* Legacy format: capabilities are exposed as two 32-bit values
515514
*/
515+
cap = table->data;
516516
spin_lock(&umh_sysctl_lock);
517-
if (table->data == CAP_BSET)
518-
cap = &usermodehelper_bset;
519-
else if (table->data == CAP_PI)
520-
cap = &usermodehelper_inheritable;
521-
else
522-
BUG();
523-
524-
/* Legacy format: capabilities are exposed as two 32-bit values */
525517
cap_array[0] = (u32) cap->val;
526518
cap_array[1] = cap->val >> 32;
527519
spin_unlock(&umh_sysctl_lock);
@@ -555,14 +547,14 @@ static int proc_cap_handler(struct ctl_table *table, int write,
555547
struct ctl_table usermodehelper_table[] = {
556548
{
557549
.procname = "bset",
558-
.data = CAP_BSET,
550+
.data = &usermodehelper_bset,
559551
.maxlen = 2 * sizeof(unsigned long),
560552
.mode = 0600,
561553
.proc_handler = proc_cap_handler,
562554
},
563555
{
564556
.procname = "inheritable",
565-
.data = CAP_PI,
557+
.data = &usermodehelper_inheritable,
566558
.maxlen = 2 * sizeof(unsigned long),
567559
.mode = 0600,
568560
.proc_handler = proc_cap_handler,

0 commit comments

Comments
 (0)