From: Matthew Wilcox <willy@infradead.org>
To: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>,
Alexander Potapenko <glider@google.com>,
Dmitry Vyukov <dvyukov@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
kasan-dev <kasan-dev@googlegroups.com>,
Linux Memory Management List <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] kasan: Fix tag for large allocations when using CONFIG_SLAB
Date: Fri, 1 Oct 2021 15:05:40 +0100 [thread overview]
Message-ID: <YVcVtNLnyJModOhn@casper.infradead.org> (raw)
In-Reply-To: <CA+fCnZfSUxToYKUfHwQT0r3bC9NYZNc2iC3PXv+GciuW0Fm79A@mail.gmail.com>
On Fri, Oct 01, 2021 at 03:29:29PM +0200, Andrey Konovalov wrote:
> On Fri, Oct 1, 2021 at 4:42 AM Matthew Wilcox (Oracle)
> <willy@infradead.org> wrote:
> >
> > If an object is allocated on a tail page of a multi-page slab, kasan
> > will get the wrong tagbecause page->s_mem is NULL for tail pages.
>
> Interesting. Is this a known property of tail pages? Why does this
> happen? I failed to find this exception in the code.
Yes, it's a known property of tail pages. kmem_getpages() calls
__alloc_pages_node() which returns a pointer to the head page.
All the tail pages are initialised to point to the head page.
Then in alloc_slabmgmt(), we set ->s_mem of the head page, but
we never set ->s_mem of the tail pages. Instead, we rely on
people always passing in the head page. I have a patch in the works
to change the type from struct page to struct slab so you can't
make this mistake. That was how I noticed this problem.
> The tag value won't really be "wrong", just unexpected. But if s_mem
> is indeed NULL for tail pages, your fix makes sense.
>
> > I'm not quite sure what the user-visible effect of this might be.
>
> Everything should work, as long as tag values are assigned
> consistently based on the object address.
OK, maybe this doesn't need to be backported then? Actually, why
subtract s_mem in the first place? Can we just avoid that for all
tag calculations?
next prev parent reply other threads:[~2021-10-01 14:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-01 2:41 Matthew Wilcox (Oracle)
2021-10-01 10:30 ` Marco Elver
2021-10-01 13:29 ` Andrey Konovalov
2021-10-01 14:05 ` Matthew Wilcox [this message]
2021-10-03 16:27 ` Andrey Konovalov
2021-10-03 16:27 ` Andrey Konovalov
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=YVcVtNLnyJModOhn@casper.infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@gmail.com \
--cc=dvyukov@google.com \
--cc=glider@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ryabinin.a.a@gmail.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