Skip to content

Commit 3eaafab

Browse files
GustavoARSilvaZhengShunQian
authored andcommitted
kernel/sys.c: fix potential Spectre v1 issue
commit 23d6aef upstream. `resource' can be controlled by user-space, hence leading to a potential exploitation of the Spectre variant 1 vulnerability. This issue was detected with the help of Smatch: kernel/sys.c:1474 __do_compat_sys_old_getrlimit() warn: potential spectre issue 'get_current()->signal->rlim' (local cap) kernel/sys.c:1455 __do_sys_old_getrlimit() warn: potential spectre issue 'get_current()->signal->rlim' (local cap) Fix this by sanitizing *resource* before using it to index current->signal->rlim Notice that given that speculation windows are large, the policy is to kill the speculation on the first load and not worry if it can be completed with a dependent load/store [1]. [1] https://marc.info/?l=linux-kernel&m=152449131114778&w=2 Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Gustavo A. R. Silva <[email protected]> Reviewed-by: Andrew Morton <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Dan Williams <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 842feee commit 3eaafab

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

kernel/sys.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
#include <linux/uidgid.h>
5656
#include <linux/cred.h>
5757

58+
#include <linux/nospec.h>
59+
5860
#include <linux/kmsg_dump.h>
5961
/* Move somewhere else to avoid recompiling? */
6062
#include <generated/utsrelease.h>
@@ -1313,6 +1315,7 @@ SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
13131315
if (resource >= RLIM_NLIMITS)
13141316
return -EINVAL;
13151317

1318+
resource = array_index_nospec(resource, RLIM_NLIMITS);
13161319
task_lock(current->group_leader);
13171320
x = current->signal->rlim[resource];
13181321
task_unlock(current->group_leader);

0 commit comments

Comments
 (0)