All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kernel/sys.c: fix possible spectre-v1 in do_prlimit()
@ 2019-05-27  7:23 Dianzhang Chen
  2019-05-27  7:38 ` Cyrill Gorcunov
  0 siblings, 1 reply; 7+ messages in thread
From: Dianzhang Chen @ 2019-05-27  7:23 UTC (permalink / raw)
  To: akpm
  Cc: gorcunov, kristina.martsenko, ebiederm, j.neuschaefer, jannh,
	mortonm, yang.shi, linux-kernel, Dianzhang Chen

The `resource` in do_prlimit() is controlled by userspace via syscall: setrlimit(defined in kernel/sys.c), hence leading to a potential exploitation of the Spectre variant 1 vulnerability.
The relevant code in do_prlimit() is as below:

if (resource >= RLIM_NLIMITS)
        return -EINVAL;
...
rlim = tsk->signal->rlim + resource;    // use resource as index
...
            *old_rlim = *rlim;

Fix this by sanitizing resource before using it to index tsk->signal->rlim.

Signed-off-by: Dianzhang Chen <dianzhangchen0@gmail.com>
---
 kernel/sys.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/sys.c b/kernel/sys.c
index bdbfe8d..7eba1ca 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1532,6 +1532,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;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-05-30  7:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAFbcbMATqCCpCR596FTaSdUV50nQSxDgXMd1ASgXu1CE+DJqTw@mail.gmail.com>
2019-05-28  7:10 ` [PATCH] kernel/sys.c: fix possible spectre-v1 in do_prlimit() Cyrill Gorcunov
2019-05-29  2:39   ` Dianzhang Chen
2019-05-29 12:18     ` Cyrill Gorcunov
2019-05-30  5:45       ` Dianzhang Chen
2019-05-30  7:58         ` Cyrill Gorcunov
2019-05-27  7:23 Dianzhang Chen
2019-05-27  7:38 ` Cyrill Gorcunov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.