mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [BUG] mm: uffd-wp marker on a DAX file mapping: SIGBUS on write, endless refaults on read
@ 2026-11-17 12:17 Jingyi Sun
  0 siblings, 0 replies; only message in thread
From: Jingyi Sun @ 2026-11-17 12:17 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Mike Rapoport, Peter Xu
  Cc: Dan Williams, Matthew Wilcox, Jan Kara, Alistair Popple,
	linux-mm, nvdimm, linux-fsdevel, linux-kernel

Hi,

On a DAX-mounted file, a uffd-wp PTE marker installed with
UFFD_FEATURE_WP_ASYNC is treated as an already-mapped page when the
page is later faulted in, which makes writes fail with SIGBUS and
reads refault forever.

Path (v7.3-rc2, unchanged in v7.4-rc3 and mm-unstable):

  handle_pte_marker()
    pte_marker_handle_uffd_wp()
      do_pte_missing()
        ext4_dax_huge_fault() -> dax_iomap_fault() -> dax_fault_iter()
          vmf_insert_page_mkwrite()
            insert_page_into_pte_locked()

insert_page_into_pte_locked() only checks !pte_none(pteval) to decide
that something is already mapped. The uffd-wp marker is non-present
but not none, so:

 - write fault (mkwrite == true): pte_pfn() is called on the marker,
   which does not hold a PFN; the comparison with page_to_pfn(page)
   fails, WARN_ON_ONCE(!is_zero_pfn(...)) fires and -EFAULT is
   returned, so the task gets SIGBUS;
 - read fault (mkwrite == false): -EBUSY is returned, which becomes
   VM_FAULT_NOPAGE, the marker is never replaced and the task refaults
   on the same address forever (about 3.5 million faults in 20s in our
   test). The task stays killable.

vma_can_userfault() allows any memory type when only WP is requested
together with UFFD_FEATURE_WP_ASYNC, so DAX VMAs can get these markers.
Programs using async uffd-wp for dirty tracking (e.g. with
PAGEMAP_SCAN) on DAX files are therefore killed or stuck.

Reproducer (x86_64 in QEMU, v7.3-rc2, memmap=256M!512M as /dev/pmem0,
ext4 mounted with -o dax=always):

 1. create and fsync a file on the DAX mount (some pages written, one
    page left as a hole by ftruncate);
 2. mmap() it MAP_SHARED, PROT_READ|PROT_WRITE, without touching the
    pages;
 3. userfaultfd with UFFD_FEATURE_WP_ASYNC, UFFDIO_REGISTER with
    UFFDIO_REGISTER_MODE_WP over the mapping, then UFFDIO_WRITEPROTECT
    (MODE_WP) over the whole range; /proc/self/pagemap now shows
    uffd-wp=1, present=0 for the pages;
 4. write to a page: WARNING at mm/memory.c:2495 and SIGBUS (3/3 runs,
    both for an allocated block and for the hole);
    read from a page: the task never returns from the fault (3/3).

Controls behave normally on the same kernel: the same steps on DAX
without userfaultfd, and with userfaultfd on shmem instead of DAX.

As an attribution experiment only, treating a non-present PTE as none
in insert_page_into_pte_locked() makes both symptoms go away, but that
drops the write-protect state, so it is not a proposed fix. A proper
fix probably either installs the page while keeping the uffd-wp bit
(pte_mkuffd_wp()) when replacing a uffd-wp marker in the DAX insert
paths, or refuses uffd-wp on DAX VMAs in vma_can_userfault(). The
same !pte_none() pattern exists in insert_pfn() and in the PMD-level
insert path; those were not tested.

A similar present check was proposed in "mm: compare pfns only if the
entry is present when inserting pfns/pages" (RFC, June 2025), which
described the pte_pfn() on a non-present entry as not expected to cause
harm in practice; that hunk is not in mainline. The reproducer above
shows a user-visible effect. Note that returning -EBUSY for a
non-present entry alone would only turn the SIGBUS into the same
endless refault as in the read case.

Link: https://lore.kernel.org/all/20250617154345.2494405-4-david@redhat.com/

The issue was found with a research static analyzer for
cross-architecture dependency bugs (it flags calls to helpers such as
pte_pfn() that are only defined for present entries) and confirmed
with the QEMU reproducer above. I can share the full reproducer
program.

Thanks,
Jingyi Sun


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-17 12:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 12:17 [BUG] mm: uffd-wp marker on a DAX file mapping: SIGBUS on write, endless refaults on read Jingyi Sun

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®