Skip to contentSkip to conversation

kernel: sysctl: ignore out-of-range taint bits introduced via kernel.tainted

PATCH Applied Rafael Aquini 2 participants 3 messages May 12, 2020 – May 13, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 kernel: sysctl: ignore out-of-range taint bits introduced via kernel.tainted

Users with SYS_ADMIN capability can add arbitrary taint flags to the running kernel by writing to /proc/sys/kernel/tainted or issuing the command 'sysctl -w kernel.tainted=...'. These interface, however, are open for any integer value and this might an invalid set of flags being committed to the tainted_mask bitset.

This patch introduces a simple way for proc_taint() to ignore any eventual invalid bit coming from the user input before committing those bits to the kernel tainted_mask.

---
Changelog:
v2: simplify the bit iterator within proc_taint(),
and silently drop out-of-range bits (akpm)

 kernel/sysctl.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
kernel/sysctl.c +2 -3
index 8a176d8727a3..fcd46fc41206 100644
@@ -2628,10 +2628,9 @@ static int proc_taint(struct ctl_table *table, int write,
 		 * to everyone's atomic.h for this
 		 */
 		int i;
-		for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
-			if ((tmptaint >> i) & 1)
+		for (i = 0; i < TAINT_FLAGS_COUNT; i++)
+			if ((1UL << i) & tmptaint)
 				add_taint(i, LOCKDEP_STILL_OK);
-		}
 	}
 
 	return err;
Signature · 1 line
2.25.4
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Rafael Aquini

Users with SYS_ADMIN capability can add arbitrary taint flags to the running kernel by writing to /proc/sys/kernel/tainted or issuing the command 'sysctl -w kernel.tainted=...'. These interface, however, are open for any integer value and this might an invalid set of flags being committed to the tainted_mask bitset.

Quoted 5 lines

This patch introduces a simple way for proc_taint() to ignore any eventual invalid bit coming from the user input before committing those bits to the kernel tainted_mask.

Luis

#2 lore raw
Quoted 4 lines · Luis Chamberlain
Quoted 3 lines · Rafael Aquini

Users with SYS_ADMIN capability can add arbitrary taint flags to the running kernel by writing to /proc/sys/kernel/tainted or issuing the command 'sysctl -w kernel.tainted=...'.

I just notice 2 minor 'screw ups' on my part in the commit log:

Quoted 1 line
Quoted 1 line

These interface, however, are open for any integer value

This one probably needs to be reprhased as:
"The interface, however, is ... "

Quoted 1 line
Quoted 1 line

and this might an invalid set of flags being committed to

and I'm missing a verb here, as it should read:
"and this might cause an invalid ... "

I hope these are easy fixes, in the pre-merge step. (Sorry!)

Quoted 10 lines
Quoted 7 lines

the tainted_mask bitset.

This patch introduces a simple way for proc_taint() to ignore any eventual invalid bit coming from the user input before committing those bits to the kernel tainted_mask.

Thanks!
-- Rafael