mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dianzhang Chen <dianzhangchen0@gmail.com>
To: akpm@linux-foundation.org
Cc: gorcunov@gmail.com, kristina.martsenko@arm.com,
	ebiederm@xmission.com, j.neuschaefer@gmx.net, jannh@google.com,
	mortonm@chromium.org, yang.shi@linux.alibaba.com,
	linux-kernel@vger.kernel.org,
	Dianzhang Chen <dianzhangchen0@gmail.com>
Subject: [PATCH] kernel/sys.c: fix possible spectre-v1 in do_prlimit()
Date: Mon, 27 May 2019 15:23:08 +0800	[thread overview]
Message-ID: <1558941788-969-1-git-send-email-dianzhangchen0@gmail.com> (raw)

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


             reply	other threads:[~2019-05-27  7:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-27  7:23 Dianzhang Chen [this message]
2019-05-27  7:38 ` Cyrill Gorcunov
     [not found] <CAFbcbMATqCCpCR596FTaSdUV50nQSxDgXMd1ASgXu1CE+DJqTw@mail.gmail.com>
2019-05-28  7:10 ` 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1558941788-969-1-git-send-email-dianzhangchen0@gmail.com \
    --to=dianzhangchen0@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=gorcunov@gmail.com \
    --cc=j.neuschaefer@gmx.net \
    --cc=jannh@google.com \
    --cc=kristina.martsenko@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mortonm@chromium.org \
    --cc=yang.shi@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®