Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Arnd Bergmann" <arnd@kernel.org>,
	"David Hildenbrand" <david@kernel.org>,
	"Gregory Price" <gourry@gourry.net>,
	"Andrew Morton" <akpm@linux-foundation.org>
Cc: "Arnd Bergmann" <arnd@arndb.de>, larips <larips950@gmail.com>,
	"Zi Yan" <ziy@nvidia.com>,
	"Joshua Hahn" <joshua.hahnjy@gmail.com>,
	"Rakie Kim" <rakie.kim@sk.com>,
	"Ying Huang" <ying.huang@linux.alibaba.com>,
	"Lorenzo Stoakes (ARM)" <ljs@kernel.org>,
	"Brendan Jackman" <brendan.jackman@linux.dev>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Jackie Liu" <liuyun01@kylinos.cn>,
	linux-mm@kvack.org, "Kees Cook" <kees+treewide@kernel.org>
Subject: Re: [PATCH 2/2] [v2] mm/mempolicy: replace copy_nodes_to_user() interface with put_nodes()
Date: Wed, 18 Nov 2026 21:16:56 +0000	[thread overview]
Message-ID: <sashiko-outbox-221984@kernel.org> (raw)
In-Reply-To: <20261117211635.2472067-2-arnd@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] mm/mempolicy: unadjusted nbytes for compat in put_nodes()
  leaves 4-byte gap
--

commit 2830eda1a2add7e034fa70931e6090d2764cf894
Author: Arnd Bergmann <arnd@arndb.de>

mm/mempolicy: replace copy_nodes_to_user() interface with put_nodes()

This commit renames copy_nodes_to_user() to put_nodes(), reorders its
arguments to match get_nodes(), and decrements maxnode once at the start
of the function.

> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index c10f9d4ba38f8..47bd36ac70787 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c

[ ... ]

> @@ -1717,15 +1717,18 @@ static int get_nodes(nodemask_t *nodes, const unsigned long __user *nmask,
>  }
>  
>  /* Copy a kernel node mask to user space */
> -static int copy_nodes_to_user(unsigned long __user *mask, unsigned long maxnode,
> -			      nodemask_t *nodes)
> +static int put_nodes(unsigned long __user *mask, nodemask_t *nodes,
> +		     unsigned long maxnode)
>  {
> -	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();
> +	unsigned long copy;
> +
> +	--maxnode; /* user space ABI uses number of bits plus 1 */
>  
> +	copy = ALIGN(maxnode, BITS_PER_LONG) / 8;
>  	if (compat)
> -		copy = ALIGN(maxnode-1, BITS_PER_COMPAT_LONG) / 8;
> +		copy = ALIGN(maxnode, BITS_PER_COMPAT_LONG) / 8;
>  
>  	if (copy > nbytes) {
>  		if (copy > PAGE_SIZE)
> @@ -1733,12 +1736,12 @@ static int copy_nodes_to_user(unsigned long __user *mask, unsigned long maxnode,
>  		if (clear_user((char __user *)mask + nbytes, copy - nbytes))
>  			return -EFAULT;
>  		copy = nbytes;
> -		maxnode = nr_node_ids+1;
> +		maxnode = nr_node_ids;
>  	}
>  
>  	if (compat)
>  		return compat_put_bitmap((compat_ulong_t __user *)mask,
> -					 nodes_addr(*nodes), maxnode-1);
> +					 nodes_addr(*nodes), maxnode);

[Severity: High]
Can this leave a 4-byte gap of uninitialized user memory in mask when
called from a 32-bit compat syscall?

nbytes is sized in unsigned long units (a multiple of 8 bytes on 64-bit
kernels) and is not adjusted for compat, whereas compat_put_bitmap()
rounds bitmap_size up to a 32-bit compat_ulong_t boundary:

kernel/compat.c:compat_put_bitmap() {
	/* align bitmap up to nearest compat_long_t boundary */
	bitmap_size = ALIGN(bitmap_size, BITS_PER_COMPAT_LONG);
	nr_compat_longs = BITS_TO_COMPAT_LONGS(bitmap_size);
    ...
}

When nr_node_ids spans an odd number of 32-bit words (for example, 1 to
32 nodes, where nbytes is 8) and a compat caller passes a buffer with
copy > nbytes, clear_user() zeroes starting at mask + nbytes while
compat_put_bitmap() with maxnode = nr_node_ids writes only nbytes - 4
bytes, leaving the 4 bytes at [nbytes - 4, nbytes) untouched.  In
addition, when maxnode is between 34 and 65 on such a system, copy is 8
(equal to nbytes), so the copy > nbytes check is skipped and maxnode is
not clamped to nr_node_ids.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117211635.2472067-1-arnd@kernel.org?part=2


  reply	other threads:[~2026-11-18 21:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 21:14 [PATCH 1/2] [v2] mm/mempolicy: fix copy_nodes_to_user() for odd inputs Arnd Bergmann
2026-11-17 21:14 ` [PATCH 2/2] [v2] mm/mempolicy: replace copy_nodes_to_user() interface with put_nodes() Arnd Bergmann
2026-11-18 21:16   ` sashiko-bot [this message]
2026-11-18  3:09 ` [PATCH 1/2] [v2] mm/mempolicy: fix copy_nodes_to_user() for odd inputs Gregory Price (Meta)
2026-11-18 21:16 ` sashiko-bot

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-221984@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=arnd@kernel.org \
    --cc=brendan.jackman@linux.dev \
    --cc=david@kernel.org \
    --cc=gourry@gourry.net \
    --cc=hannes@cmpxchg.org \
    --cc=joshua.hahnjy@gmail.com \
    --cc=kees+treewide@kernel.org \
    --cc=larips950@gmail.com \
    --cc=linux-mm@kvack.org \
    --cc=liuyun01@kylinos.cn \
    --cc=ljs@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox