linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: Dianzhang Chen <dianzhangchen0@gmail.com>
Cc: akpm@linux-foundation.org, 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
Subject: Re: [PATCH] kernel/sys.c: fix possible spectre-v1 in do_prlimit()
Date: Mon, 27 May 2019 10:38:52 +0300	[thread overview]
Message-ID: <20190527073852.GK11013@uranus> (raw)
In-Reply-To: <1558941788-969-1-git-send-email-dianzhangchen0@gmail.com>

On Mon, May 27, 2019 at 03:23:08PM +0800, Dianzhang Chen wrote:
> 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;

Could you please explain in details how array_index_nospec is different
from resource >= RLIM_NLIMITS? Since I don't get how it is related to
spectre issue.

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

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-27  7:23 [PATCH] kernel/sys.c: fix possible spectre-v1 in do_prlimit() Dianzhang Chen
2019-05-27  7:38 ` Cyrill Gorcunov [this message]
     [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=20190527073852.GK11013@uranus \
    --to=gorcunov@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=dianzhangchen0@gmail.com \
    --cc=ebiederm@xmission.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;
as well as URLs for NNTP newsgroup(s).