The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [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 related	[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