From: Matthew Wilcox <willy@infradead.org>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Anders Roxell <anders.roxell@linaro.org>,
Kees Cook <keescook@chromium.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:12:33 +0000 [thread overview]
Message-ID: <Y1/l4Tacaw738UaX@casper.infradead.org> (raw)
In-Reply-To: <13c4bd6e-09d3-efce-43a5-5a99be8bc96b@suse.cz>
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.
next prev parent reply other threads:[~2022-10-31 15:12 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 [this message]
2022-10-31 15:22 ` Kees Cook
2022-10-31 15:40 ` Matthew Wilcox
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/l4Tacaw738UaX@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