mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mm/mempolicy: limit compat bitmap reads to the source nodemask
@ 2026-11-17 10:19 Gregory Price (Meta)
  2026-11-17 11:10 ` David Hildenbrand (Arm)
  2026-11-17 12:44 ` Arnd Bergmann
  0 siblings, 2 replies; 4+ messages in thread
From: Gregory Price (Meta) @ 2026-11-17 10:19 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-kernel, kernel-team, david, gourry, ziy, joshua.hahnjy,
	rakie.kim, ying.huang, akpm, arnd, larips, stable

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.

A kernel built with CONFIG_NODES_SHIFT=6 reports:

    BUG: KASAN: stack-out-of-bounds in compat_put_bitmap+0x113/0x120
    Read of size 8 at addr ff110000099afeb0 by task mpol32/246
    Call Trace:
     compat_put_bitmap+0x113/0x120
     copy_nodes_to_user+0x137/0x200
     __ia32_sys_get_mempolicy+0x1a6/0x280

Bound the compat bitmap read by MAX_NUMNODES.

Clamping every call to nr_node_ids would remove the extra userspace
word when the kernel nodemask is large enough to contain it, but this
keep that existing compat behavior while preventing reads beyond the
source allocation.

Reported-by: larips <larips950@gmail.com>
Fixes: e130242dc351 ("mm: simplify compat numa syscalls")
Cc: stable@vger.kernel.org
Signed-off-by: Gregory Price (Meta) <gourry@gourry.net>
---
 mm/mempolicy.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 79053ece02cd4..d9177c5504879 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -1715,7 +1715,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;
 }
-- 
2.53.1-Meta


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-17 13:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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

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®