From: Greg Kroah-Hartman Date: Fri, 20 Jan 2023 10:03:20 +0000 (+0100) Subject: prlimit: do_prlimit needs to have a speculation check X-Git-Tag: baikal/aarch64/sdk5.9~169 X-Git-Url: https://git.baikalelectronics.ru/sdk/?a=commitdiff_plain;h=94528a2fd242ba2ed4cba5b9f803b5d88101303b;p=kernel.git 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 Tested-by: Jordy Zomer Suggested-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- diff --git a/kernel/sys.c b/kernel/sys.c index b075fe84eb5a5..f6d6ce8da3e4a 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -1534,6 +1534,8 @@ 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;