From: David Hildenbrand <david@redhat.com>
To: Jakub Acs <acsjakub@amazon.de>, linux-fsdevel@vger.kernel.org
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
"Vlastimil Babka" <vbabka@suse.cz>,
"Lorenzo Stoakes" <lorenzo.stoakes@oracle.com>,
"Jinjiang Tu" <tujinjiang@huawei.com>,
"Suren Baghdasaryan" <surenb@google.com>,
"Penglei Jiang" <superman.xpt@gmail.com>,
"Mark Brown" <broonie@kernel.org>,
"Baolin Wang" <baolin.wang@linux.alibaba.com>,
"Ryan Roberts" <ryan.roberts@arm.com>,
"Andrei Vagin" <avagin@gmail.com>,
"Michał Mirosław" <mirq-linux@rere.qmqm.pl>,
"Stephen Rothwell" <sfr@canb.auug.org.au>,
"Muhammad Usama Anjum" <usama.anjum@collabora.com>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v3] fs/proc/task_mmu: check p->vec_buf for NULL
Date: Mon, 22 Sep 2025 10:43:59 +0200 [thread overview]
Message-ID: <715052fa-2459-4785-87fa-04c8cf30debb@redhat.com> (raw)
In-Reply-To: <20250922082206.6889-1-acsjakub@amazon.de>
On 22.09.25 10:22, Jakub Acs wrote:
> When PAGEMAP_SCAN ioctl invoked with vec_len = 0 reaches
> pagemap_scan_backout_range(), kernel panics with null-ptr-deref:
>
> [ 44.936808] Oops: general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] SMP DEBUG_PAGEALLOC KASAN NOPTI
> [ 44.937797] KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
> [ 44.938391] CPU: 1 UID: 0 PID: 2480 Comm: reproducer Not tainted 6.17.0-rc6 #22 PREEMPT(none)
> [ 44.939062] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014
> [ 44.939935] RIP: 0010:pagemap_scan_thp_entry.isra.0+0x741/0xa80
>
> <snip registers, unreliable trace>
>
> [ 44.946828] Call Trace:
> [ 44.947030] <TASK>
> [ 44.949219] pagemap_scan_pmd_entry+0xec/0xfa0
> [ 44.952593] walk_pmd_range.isra.0+0x302/0x910
> [ 44.954069] walk_pud_range.isra.0+0x419/0x790
> [ 44.954427] walk_p4d_range+0x41e/0x620
> [ 44.954743] walk_pgd_range+0x31e/0x630
> [ 44.955057] __walk_page_range+0x160/0x670
> [ 44.956883] walk_page_range_mm+0x408/0x980
> [ 44.958677] walk_page_range+0x66/0x90
> [ 44.958984] do_pagemap_scan+0x28d/0x9c0
> [ 44.961833] do_pagemap_cmd+0x59/0x80
> [ 44.962484] __x64_sys_ioctl+0x18d/0x210
> [ 44.962804] do_syscall_64+0x5b/0x290
> [ 44.963111] entry_SYSCALL_64_after_hwframe+0x76/0x7e
>
> vec_len = 0 in pagemap_scan_init_bounce_buffer() means no buffers are
> allocated and p->vec_buf remains set to NULL.
>
> This breaks an assumption made later in pagemap_scan_backout_range(),
> that page_region is always allocated for p->vec_buf_index.
>
> Fix it by explicitly checking p->vec_buf for NULL before dereferencing.
>
> Other sites that might run into same deref-issue are already (directly
> or transitively) protected by checking p->vec_buf.
>
> Note:
> From PAGEMAP_SCAN man page, it seems vec_len = 0 is valid when no output
> is requested and it's only the side effects caller is interested in,
> hence it passes check in pagemap_scan_get_args().
>
> This issue was found by syzkaller.
>
> Fixes: 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and optionally clear info about PTEs")
> Signed-off-by: Jakub Acs <acsjakub@amazon.de>
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers
David / dhildenb
prev parent reply other threads:[~2025-09-22 8:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-22 8:22 [PATCH v3] fs/proc/task_mmu: check p->vec_buf for NULL Jakub Acs
2025-09-22 8:39 ` Muhammad Usama Anjum
2025-09-22 8:43 ` David Hildenbrand [this message]
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=715052fa-2459-4785-87fa-04c8cf30debb@redhat.com \
--to=david@redhat.com \
--cc=acsjakub@amazon.de \
--cc=akpm@linux-foundation.org \
--cc=avagin@gmail.com \
--cc=baolin.wang@linux.alibaba.com \
--cc=broonie@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mirq-linux@rere.qmqm.pl \
--cc=ryan.roberts@arm.com \
--cc=sfr@canb.auug.org.au \
--cc=stable@vger.kernel.org \
--cc=superman.xpt@gmail.com \
--cc=surenb@google.com \
--cc=tujinjiang@huawei.com \
--cc=usama.anjum@collabora.com \
--cc=vbabka@suse.cz \
/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;
as well as URLs for NNTP newsgroup(s).