From: Matthew Wilcox <willy@infradead.org>
To: Kees Cook <keescook@chromium.org>
Cc: Vlastimil Babka <vbabka@suse.cz>,
Anders Roxell <anders.roxell@linaro.org>,
kernel test robot <oliver.sang@intel.com>,
Andrew Morton <akpm@linux-foundation.org>,
David Rientjes <rientjes@google.com>,
Marco Elver <elver@google.com>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
linux-mm@kvack.org, Andrey Konovalov <andreyknvl@gmail.com>,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH v4] mempool: Do not use ksize() for poisoning
Date: Mon, 31 Oct 2022 15:40:47 +0000 [thread overview]
Message-ID: <Y1/sf9xranqeCeBo@casper.infradead.org> (raw)
In-Reply-To: <202210310821.9F7AA27D12@keescook>
On Mon, Oct 31, 2022 at 08:22:50AM -0700, Kees Cook wrote:
> On Mon, Oct 31, 2022 at 03:12:33PM +0000, Matthew Wilcox wrote:
> > On Mon, Oct 31, 2022 at 04:00:25PM +0100, Vlastimil Babka wrote:
> > > +++ b/mm/mempool.c
> > > @@ -57,8 +57,10 @@ static void __check_element(mempool_t *pool, void *element, size_t size)
> > > static void check_element(mempool_t *pool, void *element)
> > > {
> > > /* Mempools backed by slab allocator */
> > > - if (pool->free == mempool_free_slab || pool->free == mempool_kfree) {
> > > + if (pool->free == mempool_kfree) {
> > > __check_element(pool, element, (size_t)pool->pool_data);
> > > + } else if (pool->free == mempool_free_slab) {
> > > + __check_element(pool, element, kmem_cache_size(pool->pool_data));
> > > } else if (pool->free == mempool_free_pages) {
> > > /* Mempools backed by page allocator */
> > > int order = (int)(long)pool->pool_data;
> >
> > I had a quick look at this to be sure I understood what was going on,
> > and I found a grotesque bug that has been with us since the introduction
> > of check_element() in 2015.
> >
> > + if (pool->free == mempool_free_pages) {
> > + int order = (int)(long)pool->pool_data;
> > + void *addr = kmap_atomic((struct page *)element);
> > +
> > + __check_element(pool, addr, 1UL << (PAGE_SHIFT + order));
> > + kunmap_atomic(addr);
> >
> > kmap_atomic() and friends only map a single page. So this is all
> > nonsense for HIGHMEM kernels, GFP_HIGHMEM allocations and order > 0.
> > The consequence of doing that will be calling memset(POISON_INUSE)
> > on random pages that we don't own.
>
> Ah-ha! Thank you both! Seems like the first fix should be squashed and
> the latter one is separate? Or just put it all together?
Yes, I have no objection to Vlastimil's patch as-is. I haven't really
reviewed it, just used it as an excuse to look at this code. A fix for
the kmap_atomic() problem will necessarily be separate and should be
backported separately.
next prev parent reply other threads:[~2022-10-31 15:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-28 15:53 Kees Cook
2022-10-31 10:55 ` Anders Roxell
2022-10-31 15:00 ` Vlastimil Babka
2022-10-31 15:12 ` Matthew Wilcox
2022-10-31 15:22 ` Kees Cook
2022-10-31 15:40 ` Matthew Wilcox [this message]
2022-11-01 17:15 ` Kees Cook
2022-11-01 19:35 ` Vlastimil Babka
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=Y1/sf9xranqeCeBo@casper.infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=anders.roxell@linaro.org \
--cc=andreyknvl@gmail.com \
--cc=elver@google.com \
--cc=keescook@chromium.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=oliver.sang@intel.com \
--cc=rientjes@google.com \
--cc=vbabka@suse.cz \
--cc=vincenzo.frascino@arm.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