From: sashiko-bot@kernel.org
To: "Gregory Price (Meta)" <gourry@gourry.net>, linux-mm@kvack.org
Cc: kernel-team@meta.com, david@kernel.org, ziy@nvidia.com,
joshua.hahnjy@gmail.com, rakie.kim@sk.com,
ying.huang@linux.alibaba.com, akpm@linux-foundation.org,
arnd@arndb.de, larips <larips950@gmail.com>
Subject: Re: [PATCH] mm/mempolicy: limit compat bitmap reads to the source nodemask
Date: Wed, 18 Nov 2026 10:20:05 +0000 [thread overview]
Message-ID: <sashiko-outbox-220674@kernel.org> (raw)
In-Reply-To: <20261117101910.1820066-1-gourry@gourry.net>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mm/mempolicy: compat buffer overflow in copy_nodes_to_user()
when maxnode=65
--
commit f6a3a5979382343bb522ac36af5733f2e67acb24
Author: Gregory Price (Meta) <gourry@gourry.net>
mm/mempolicy: limit compat bitmap reads to the source nodemask
This commit bounds the bitmap size passed to compat_put_bitmap() in
copy_nodes_to_user() by MAX_NUMNODES to prevent reading past the kernel
nodemask on the stack.
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index fb627b37afcbb..7cfcb6b49c542 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -1738,7 +1738,8 @@ static int copy_nodes_to_user(unsigned long __user *mask, unsigned long maxnode,
>
> if (compat)
> return compat_put_bitmap((compat_ulong_t __user *)mask,
> - nodes_addr(*nodes), maxnode);
> + nodes_addr(*nodes),
> + min(maxnode, MAX_NUMNODES));
>
> return copy_to_user(mask, nodes_addr(*nodes), copy) ? -EFAULT : 0;
> }
[Severity: Medium]
Can this still write 4 bytes past the caller's userspace nodemask buffer
when MAX_NUMNODES > 64?
In the mempolicy ABI, maxnode is 1-based, so a 32-bit caller with a
64-bit (8-byte) buffer passes maxnode = 65:
mm/mempolicy.c:copy_nodes_to_user() {
unsigned long copy = ALIGN(maxnode-1, 64) / 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);
if (copy > nbytes) {
...
maxnode = nr_node_ids;
}
On a kernel with CONFIG_NODES_SHIFT > 6 (for example MAX_NUMNODES = 1024)
running on a machine where 33 <= nr_node_ids <= 64, both copy and nbytes
are 8, so the copy > nbytes clamp is skipped and min(maxnode, MAX_NUMNODES)
evaluates to 65. compat_put_bitmap() then aligns bitmap_size = 65 up to
96 bits (three compat_ulong_t words) and writes 12 bytes to mask,
overwriting 4 bytes past the 8-byte userspace buffer or failing with
-EFAULT at a page boundary.
Since kernel_get_mempolicy() already rejects maxnode < nr_node_ids and the
copy > nbytes block zeroes any trailing bytes up to copy, passing
nr_node_ids (or maxnode - 1 after clamping) to compat_put_bitmap() would
bound both the kernel stack read and the userspace write.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117101910.1820066-1-gourry@gourry.net?part=1
prev parent reply other threads:[~2026-11-18 10:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 10:19 [PATCH] mm/mempolicy: limit compat bitmap reads to the source nodemask Gregory Price (Meta)
2026-11-17 11:10 ` David Hildenbrand (Arm)
2026-11-17 12:44 ` Arnd Bergmann
2026-11-17 13:51 ` Arnd Bergmann
2026-11-18 10:20 ` sashiko-bot [this message]
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=sashiko-outbox-220674@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=david@kernel.org \
--cc=gourry@gourry.net \
--cc=joshua.hahnjy@gmail.com \
--cc=kernel-team@meta.com \
--cc=larips950@gmail.com \
--cc=linux-mm@kvack.org \
--cc=rakie.kim@sk.com \
--cc=sashiko-reviews@lists.linux.dev \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.