* [PATCH] fs/proc/task_mmu: fix uninitialized read in pagemap_scan_push_range()
@ 2026-11-18 9:39 zhangjiao2
2026-11-18 14:25 ` Lorenzo Stoakes (ARM)
0 siblings, 1 reply; 2+ messages in thread
From: zhangjiao2 @ 2026-11-18 9:39 UTC (permalink / raw)
To: akpm
Cc: ljs, david, surenb, vbabka, kas, dave.hansen, mirq-linux, arnd,
sfr, usama.anjum, avagin, stable, linux-kernel, trivial,
zhang jiao, Muhammad Usama Anjum
From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
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
can actually be disclosed, because the comparison only succeeds when
the uninitialized value equals the categories that would be stored
anyway.
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")
Cc: <stable@vger.kernel.org>
Cc: Muhammad Usama Anjum <usama.anjum@collabora.com>
Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
---
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] fs/proc/task_mmu: fix uninitialized read in pagemap_scan_push_range()
2026-11-18 9:39 [PATCH] fs/proc/task_mmu: fix uninitialized read in pagemap_scan_push_range() zhangjiao2
@ 2026-11-18 14:25 ` Lorenzo Stoakes (ARM)
0 siblings, 0 replies; 2+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-18 14:25 UTC (permalink / raw)
To: zhangjiao2
Cc: akpm, david, surenb, vbabka, kas, dave.hansen, mirq-linux, arnd,
sfr, usama.anjum, avagin, stable, linux-kernel, trivial,
Muhammad Usama Anjum
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@vger.kernel.org
linux-mm@kvack.org
liam@infradead.org
jannh@google.com
pfalcato@suse.de
On Wed, Nov 18, 2026 at 05:39:58PM +0800, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
>
> 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@vger.kernel.org>
But this isn't debatable, no cc-stable, that's really silly. Zero impact = no
backports needed :)
> Cc: Muhammad Usama Anjum <usama.anjum@collabora.com>
> Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-18 14:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 9:39 [PATCH] fs/proc/task_mmu: fix uninitialized read in pagemap_scan_push_range() zhangjiao2
2026-11-18 14:25 ` Lorenzo Stoakes (ARM)
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®