mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: "Gregory Price (Meta)" <gourry@gourry.net>, linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com,
	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>,
	stable@vger.kernel.org
Subject: Re: [PATCH] mm/mempolicy: limit compat bitmap reads to the source nodemask
Date: Tue, 17 Nov 2026 12:10:57 +0100	[thread overview]
Message-ID: <366e3a1e-91c1-41c1-8a1f-f94124cd29e1@kernel.org> (raw)
In-Reply-To: <20261117101910.1820066-1-gourry@gourry.net>

On 11/17/26 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.
> 
> 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;
>  }

LGTM

Staring at this once more, I think it's all confusing how we handle
compat_put_bitmap() vs. copy_to_user(). with "copy" and "nbytes".


Likely we really should be working on bits, to then only align it up for the
copy_to_user() case.

I'll wait a bit for more review before picking this,


Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>


-- 
Cheers,

David

  reply	other threads:[~2026-11-17 11: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) [this message]
2026-11-17 12:44 ` Arnd Bergmann
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=366e3a1e-91c1-41c1-8a1f-f94124cd29e1@kernel.org \
    --to=david@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --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®