Skip to content

Commit e77132e

Browse files
aquinitorvalds
authored andcommitted
kernel/sysctl.c: 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=...'. This interface, however, is open for any integer value and this might cause 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. Signed-off-by: Rafael Aquini <aquini@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Cc: Kees Cook <keescook@chromium.org> Cc: Iurii Zaikin <yzaikin@google.com> Cc: "Theodore Ts'o" <tytso@mit.edu> Link: http://lkml.kernel.org/r/20200512223946.888020-1-aquini@redhat.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 60c958d commit e77132e

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

‎kernel/sysctl.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -880,10 +880,9 @@ static int proc_taint(struct ctl_table *table, int write,
880880
* Poor man's atomic or. Not worth adding a primitive
881881
* to everyone's atomic.h for this
882882
*/
883-
for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
884-
if ((tmptaint >> i) & 1)
883+
for (i = 0; i < TAINT_FLAGS_COUNT; i++)
884+
if ((1UL << i) & tmptaint)
885885
add_taint(i, LOCKDEP_STILL_OK);
886-
}
887886
}
888887

889888
return err;

0 commit comments

Comments
 (0)