LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Dianzhang Chen <dianzhangchen0@gmail.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: cl@linux.com, penberg@kernel.org, rientjes@google.com,
	iamjoonsoo.kim@lge.com, akpm@linux-foundation.org,
	linux-mm@kvack.org, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] mm/slab_common.c: fix possible spectre-v1 in kmalloc_slab()
Date: Thu, 30 May 2019 13:21:23 +0800	[thread overview]
Message-ID: <CAFbcbMAKOSjZzCumK3iGxBGL1Bjf+Qx==87F8A9xPBy5msj+Dw@mail.gmail.com> (raw)
In-Reply-To: <20190529194852.GA23461@bombadil.infradead.org>

thanks, i think your suggestion is ok.
in my previous method is easy to understand for spectre  logic,
but your suggestion is more sense to use of array_index_nospec.



On Thu, May 30, 2019 at 3:48 AM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Wed, May 29, 2019 at 08:37:28PM +0800, Dianzhang Chen wrote:
> > The `size` in kmalloc_slab() is indirectly controlled by userspace via syscall: poll(defined in fs/select.c), hence leading to a potential exploitation of the Spectre variant 1 vulnerability.
> > The `size` can be controlled from: poll -> do_sys_poll -> kmalloc -> __kmalloc -> kmalloc_slab.
> >
> > Fix this by sanitizing `size` before using it to index size_index.
>
> I think it makes more sense to sanitize size in size_index_elem(),
> don't you?
>
>  static inline unsigned int size_index_elem(unsigned int bytes)
>  {
> -       return (bytes - 1) / 8;
> +       return array_index_nospec((bytes - 1) / 8, ARRAY_SIZE(size_index));
>  }
>
> (untested)

  reply	other threads:[~2019-05-30  5:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-29 12:37 Dianzhang Chen
2019-05-29 16:25 ` Michal Hocko
2019-05-29 16:39   ` Dianzhang Chen
2019-05-29 17:49     ` Michal Hocko
2019-05-30  5:20       ` Dianzhang Chen
2019-05-30  6:24         ` Michal Hocko
2019-05-30  7:01           ` Dianzhang Chen
2019-05-29 19:48 ` Matthew Wilcox
2019-05-30  5:21   ` Dianzhang Chen [this message]
2019-05-29 20:31 Alexey Dobriyan
2019-05-30  0:04 ` Matthew Wilcox

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='CAFbcbMAKOSjZzCumK3iGxBGL1Bjf+Qx==87F8A9xPBy5msj+Dw@mail.gmail.com' \
    --to=dianzhangchen0@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=willy@infradead.org \
    --subject='Re: [PATCH] mm/slab_common.c: fix possible spectre-v1 in kmalloc_slab()' \
    /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

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).