Re: [PATCH] fs/proc/task_mmu: fix uninitialized read in pagemap_scan_push_range()

From: Lorenzo Stoakes (ARM)

Date: Wed Nov 18 2026 - 09:25:54 EST



You are missing cc's. Fixing this is easy with b4 [0] (the recommended way
of sending patches to mm):

$ b4 prep --auto-to-cc

Alternatively, you can use scripts/get_maintainer.pl:

$ scripts/get_maintainer.pl --nogit-fallback <files-or-patches>

[0]: https://b4.docs.kernel.org/en/latest/contributor/send.html

Specifically, the following appear to be missing:

linux-fsdevel@xxxxxxxxxxxxxxx
linux-mm@xxxxxxxxx
liam@xxxxxxxxxxxxx
jannh@xxxxxxxxxx
pfalcato@xxxxxxx

On Wed, Nov 18, 2026 at 05:39:58PM +0800, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@xxxxxxxxxxxxxxxxxxxx>
>
> PAGEMAP_SCAN ioctl accumulates struct page_region entries in a bounce
> buffer before copying them out to userspace. The bounce buffer is
> allocated with kmalloc() and only the first entry's ->start and ->end
> fields are reset, leaving its ->categories field uninitialized.
>
> pagemap_scan_push_range() decides whether an incoming range can be
> merged into the current entry with:
>
> if (addr == cur_buf->end && categories == cur_buf->categories)
>
> A scan starting at address 0 is accepted (arg->start is only checked
> for page alignment) and page 0 can be mapped when mmap_min_addr permits
> it. If the first matching page is then reported at address 0,
> addr == cur_buf->end == 0 holds and the uninitialized
> cur_buf->categories is read, so the merge decision depends on stale
> slab contents and KMSAN would flag an uninit-value use. No kernel data

Are you sure KMSAN would? Did you reproduce?

> can actually be disclosed, because the comparison only succeeds when
> the uninitialized value equals the categories that would be stored
> anyway.

This is too dense, can you simplify please?

This does basically amount to 'no actual issue in practice' :) please make that
clear.

>
> Fix this by zero-allocating the bounce buffer, which also makes the
> manual reset of the first entry redundant. The buffer is allocated
> once per ioctl invocation, so the additional zeroing cost is
> negligible.
>
> Fixes: 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and optionally clear info about PTEs")

I'm not sure even this is valid, since this doesn't actually amount to a real
world bug. But I guess debatable.

> Cc: <stable@xxxxxxxxxxxxxxx>

But this isn't debatable, no cc-stable, that's really silly. Zero impact = no
backports needed :)

> Cc: Muhammad Usama Anjum <usama.anjum@xxxxxxxxxxxxx>
> Signed-off-by: zhang jiao <zhangjiao2@xxxxxxxxxxxxxxxxxxxx>

In general the solution looks fine, but please make sure to cc the right people
and fix the commit message + tags. Thanks!

> ---
> fs/proc/task_mmu.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> index 22361607020d..4e552f9db8ba 100644
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -3082,11 +3082,10 @@ static int pagemap_scan_init_bounce_buffer(struct pagemap_scan_private *p)
>
> p->vec_buf_len = min_t(size_t, PAGEMAP_WALK_SIZE >> PAGE_SHIFT,
> p->arg.vec_len);
> - p->vec_buf = kmalloc_objs(*p->vec_buf, p->vec_buf_len);
> + p->vec_buf = kzalloc_objs(*p->vec_buf, p->vec_buf_len);
> if (!p->vec_buf)
> return -ENOMEM;
>
> - p->vec_buf->start = p->vec_buf->end = 0;
> p->vec_out = (struct page_region __user *)(long)p->arg.vec;
>
> return 0;
> --
> 2.33.0
>
>
>

--
Cheers, Lorenzo