From: "Arnd Bergmann" <arnd@arndb.de>
To: "Gregory Price" <gourry@gourry.net>, linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com,
"David Hildenbrand (Red Hat)" <david@kernel.org>,
"Zi Yan" <ziy@nvidia.com>,
"Joshua Hahn" <joshua.hahnjy@gmail.com>,
rakie.kim@sk.com, "Ying Huang" <ying.huang@linux.alibaba.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
larips <larips950@gmail.com>,
stable@vger.kernel.org
Subject: Re: [PATCH] mm/mempolicy: limit compat bitmap reads to the source nodemask
Date: Tue, 17 Nov 2026 13:44:50 +0100 [thread overview]
Message-ID: <3b9d974c-18d3-4113-b7a6-1f785f19b318@app.fastmail.com> (raw)
In-Reply-To: <20261117101910.1820066-1-gourry@gourry.net>
On Tue, Nov 17, 2026, at 11:19, Gregory Price (Meta) wrote:
> A 32-bit get_mempolicy() call can read past the kernel's stack nodemask.
> With 64 possible nodes and maxnode=65, copy_nodes_to_user() computes an
> eight-byte copy, but compat_put_bitmap() reads two native words.
I don't quite follow the explanation yet:
if maxnode=65, shouldn't that result in copying 16 bytes on x86-64
and 12 bytes on compat mode?
It looks like compat mode adjusts the wrong variable and we should
be doing this instead:
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 6d662a9a8c74..f9a7be9f4432 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -1749,12 +1749,12 @@ static int get_nodes(nodemask_t *nodes, const unsigned long __user *nmask,
static int copy_nodes_to_user(unsigned long __user *mask, unsigned long maxnode,
nodemask_t *nodes)
{
- unsigned long copy = ALIGN(maxnode-1, 64) / 8;
+ unsigned long copy = ALIGN(maxnode-1, BITS_PER_LONG) / 8;
unsigned int nbytes = BITS_TO_LONGS(nr_node_ids) * sizeof(long);
bool compat = in_compat_syscall();
if (compat)
- nbytes = BITS_TO_COMPAT_LONGS(nr_node_ids) * sizeof(compat_long_t);
+ copy = ALIGN(maxnode-1, BITS_PER_COMPAT_LONG) / 8;
if (copy > nbytes) {
if (copy > PAGE_SIZE)
Now in the maxnode=65 example, it should clear 4 bytes and put copy
the 8 byte bitmap.
Arnd
next prev parent reply other threads:[~2026-11-17 12:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 10:19 Gregory Price (Meta)
2026-11-17 11:10 ` David Hildenbrand (Arm)
2026-11-17 12:44 ` Arnd Bergmann [this message]
2026-11-17 13:51 ` Arnd Bergmann
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=3b9d974c-18d3-4113-b7a6-1f785f19b318@app.fastmail.com \
--to=arnd@arndb.de \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=gourry@gourry.net \
--cc=joshua.hahnjy@gmail.com \
--cc=kernel-team@meta.com \
--cc=larips950@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rakie.kim@sk.com \
--cc=stable@vger.kernel.org \
--cc=ying.huang@linux.alibaba.com \
--cc=ziy@nvidia.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
all inboxes | Powered by JetHome®