summaryrefslogtreecommitdiffstats
path: root/kernel/sys.c
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-01-20 11:03:20 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-01-24 07:24:34 +0100
commit91185568c99d60534bacf38439846103962d1e2c (patch)
tree082b5806ef01a6460ce8843bb9c6e6d3a1c72e8c /kernel/sys.c
parent08bf23c33979e0f44ff9ad1849c08067c7c3a46b (diff)
downloadlinux-stable-91185568c99d60534bacf38439846103962d1e2c.tar.gz
linux-stable-91185568c99d60534bacf38439846103962d1e2c.tar.bz2
linux-stable-91185568c99d60534bacf38439846103962d1e2c.zip
prlimit: do_prlimit needs to have a speculation check
commit 739790605705ddcf18f21782b9c99ad7d53a8c11 upstream. do_prlimit() adds the user-controlled resource value to a pointer that will subsequently be dereferenced. In order to help prevent this codepath from being used as a spectre "gadget" a barrier needs to be added after checking the range. Reported-by: Jordy Zomer <jordyzomer@google.com> Tested-by: Jordy Zomer <jordyzomer@google.com> Suggested-by: Linus Torvalds <torvalds@linuxfoundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'kernel/sys.c')
-rw-r--r--kernel/sys.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/kernel/sys.c b/kernel/sys.c
index 5fd54bf0e886..88b31f096fb2 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1442,6 +1442,8 @@ static int do_prlimit(struct task_struct *tsk, unsigned int resource,
if (resource >= RLIM_NLIMITS)
return -EINVAL;
+ resource = array_index_nospec(resource, RLIM_NLIMITS);
+
if (new_rlim) {
if (new_rlim->rlim_cur > new_rlim->rlim_max)
return -EINVAL;