* [BUG] mm: userfaultfd RWP drops a populated shmem PMD
@ 2026-10-20 11:07 shaos
2026-10-20 13:00 ` David Hildenbrand (Arm)
0 siblings, 1 reply; 2+ messages in thread
From: shaos @ 2026-10-20 11:07 UTC (permalink / raw)
To: akpm; +Cc: Mike Rapoport, David Hildenbrand, Peter Xu, linux-mm, linux-kernel
Hello,
UFFDIO_RWPROTECT_MODE_RWP can return success for a present shmem THP mapping while dropping the PMD mapping instead of leaving the populated page resident and write-protected. The next read refaults the page and completes without a UFFD_PAGEFAULT_FLAG_RWP event.
The PoC verifies ShmemPmdMapped=2048 kB immediately before the ioctl. After the successful ioctl, smaps reports Rss=0 and ShmemPmdMapped=0; the read completes with the original byte and no event. Re-arming the refaulted PTE and a separate 4 KiB shmem control both produce the expected RWP event. The observed issue is loss of the mapping and protection tracking, not corruption of the file contents.
The source path splits and clears the non-anonymous PMD for MM_CP_UFFD_RWP, but the retry does not repopulate a PTE table because pgtable_populate_needed() only recognizes MM_CP_UFFD_WP. The ioctl nevertheless returns success.
HEAD commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907
source version: Linux 7.3.0-rc7
architecture: x86-64
compiler: gcc 11.4.0, GNU ld 2.38
QEMU: 6.2.0
console output: https://gist.githubusercontent.com/shaos26/3c336ea98e1e8fe09b5270c3a82ca268/raw/da13df3db0c05df09952f74bedb457f57c53b78b/console-output.txt
kernel config: https://gist.githubusercontent.com/shaos26/3c336ea98e1e8fe09b5270c3a82ca268/raw/baa5ee61ce748667104c480560ab5116a100e3fd/kernel-config.txt
reproducer: https://gist.githubusercontent.com/shaos26/3c336ea98e1e8fe09b5270c3a82ca268/raw/420975783e9d5dd88bc4a69190d8ef194faf5fdc/poc.c
Build the kernel from the revision above with the attached config. Build the static PoC and initramfs from poc.c; the program is /init and creates the shmem mapping itself. A fresh-boot run used:
timeout 300 qemu-system-x86_64 -m 2G -smp 2 \
-kernel build/arch/x86/boot/bzImage -initrd initramfs.cpio.gz \
-append "console=ttyS0 panic=1 oops=panic loglevel=7 kfence.sample_interval=0" \
-nographic -no-reboot -monitor none
Two fresh boots reported RESULT=RWP_SHMEM_PMD_BYPASS_CONFIRMED and exited cleanly. The affected code appears unchanged in upstream master f47d223627f8; I have only reproduced it on v7.3-rc7. No privilege escalation, memory corruption, or guest escape is claimed.
Thanks,
shaos
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [BUG] mm: userfaultfd RWP drops a populated shmem PMD
2026-10-20 11:07 [BUG] mm: userfaultfd RWP drops a populated shmem PMD shaos
@ 2026-10-20 13:00 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 2+ messages in thread
From: David Hildenbrand (Arm) @ 2026-10-20 13:00 UTC (permalink / raw)
To: shaos, akpm; +Cc: Mike Rapoport, Peter Xu, linux-mm, linux-kernel
On 10/20/26 13:07, shaos wrote:
> Hello,
>
> UFFDIO_RWPROTECT_MODE_RWP can return success for a present shmem THP mapping while dropping the PMD mapping instead of leaving the populated page resident and write-protected. The next read refaults the page and completes without a UFFD_PAGEFAULT_FLAG_RWP event.
>
> The PoC verifies ShmemPmdMapped=2048 kB immediately before the ioctl. After the successful ioctl, smaps reports Rss=0 and ShmemPmdMapped=0; the read completes with the original byte and no event. Re-arming the refaulted PTE and a separate 4 KiB shmem control both produce the expected RWP event. The observed issue is loss of the mapping and protection tracking, not corruption of the file contents.
>
> The source path splits and clears the non-anonymous PMD for MM_CP_UFFD_RWP, but the retry does not repopulate a PTE table because pgtable_populate_needed() only recognizes MM_CP_UFFD_WP. The ioctl nevertheless returns success.
>
> HEAD commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907
> source version: Linux 7.3.0-rc7
> architecture: x86-64
> compiler: gcc 11.4.0, GNU ld 2.38
> QEMU: 6.2.0
>
> console output: https://gist.githubusercontent.com/shaos26/3c336ea98e1e8fe09b5270c3a82ca268/raw/da13df3db0c05df09952f74bedb457f57c53b78b/console-output.txt
> kernel config: https://gist.githubusercontent.com/shaos26/3c336ea98e1e8fe09b5270c3a82ca268/raw/baa5ee61ce748667104c480560ab5116a100e3fd/kernel-config.txt
> reproducer: https://gist.githubusercontent.com/shaos26/3c336ea98e1e8fe09b5270c3a82ca268/raw/420975783e9d5dd88bc4a69190d8ef194faf5fdc/poc.c
>
> Build the kernel from the revision above with the attached config. Build the static PoC and initramfs from poc.c; the program is /init and creates the shmem mapping itself. A fresh-boot run used:
>
> timeout 300 qemu-system-x86_64 -m 2G -smp 2 \
> -kernel build/arch/x86/boot/bzImage -initrd initramfs.cpio.gz \
> -append "console=ttyS0 panic=1 oops=panic loglevel=7 kfence.sample_interval=0" \
> -nographic -no-reboot -monitor none
>
> Two fresh boots reported RESULT=RWP_SHMEM_PMD_BYPASS_CONFIRMED and exited cleanly. The affected code appears unchanged in upstream master f47d223627f8; I have only reproduced it on v7.3-rc7. No privilege escalation, memory corruption, or guest escape is claimed.
>
> Thanks,
>
> shaos
>
https://lore.kernel.org/all/20261019010934.697895-1-samarth.colleges@gmail.com/
--
Cheers,
David
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-20 13:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-20 11:07 [BUG] mm: userfaultfd RWP drops a populated shmem PMD shaos
2026-10-20 13:00 ` David Hildenbrand (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®