mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] selftests/mm: skip tests when FOLL_FORCE writes are denied
@ 2026-11-29  4:00 Nikolai Dokutovich
  2026-11-29  4:00 ` [PATCH 1/3] selftests/mm: add a probe for FOLL_FORCE writes through /proc/self/mem Nikolai Dokutovich
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Nikolai Dokutovich @ 2026-11-29  4:00 UTC (permalink / raw)
  To: David Hildenbrand, Andrew Morton
  Cc: Shuah Khan, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Michal Hocko, linux-mm, linux-kselftest, linux-kernel,
	Nikolai Dokutovich

A write through /proc/self/mem into a mapping that is not writable is
performed by the kernel as a forced write.  Since commit
41e8149c8892 ("proc: add config & param to block forcing mem writes")
such a write is refused unless the writing task is tracing the target
task, the kernel was built with CONFIG_PROC_MEM_ALWAYS_FORCE, or it was
booted with proc_mem.force_override=always.  Commit
599bbba5a36f ("proc: make PROC_MEM_FORCE_PTRACE the Kconfig default") made
the refusal the default.

Commit a3907a3169d0 ("selftests/mm: specify requirement for
PROC_MEM_ALWAYS_FORCE=y") set CONFIG_PROC_MEM_ALWAYS_FORCE=y in mm/config.
That fragment is merged into the kernel configuration only when it is
requested, so a test binary run against a distribution kernel is not
covered, and mkdirty and the ksm PROT_NONE test then report failures
instead of skipping:

    not ok 1 write() failed
    not ok 5 ptrace write failed

The first patch adds a probe to vm_util that reports whether such a write
is permitted.  The kernel reports a refused forced write as -EIO, because
the transfer copies zero bytes and mem_rw() maps that to -EIO.  The same
error also covers any other zero-byte remote access, so the probe treats
-EIO as a refusal but returns a distinct value for every other outcome:
the tests skip only on -EIO, and once the probe is allowed a real fault in
the test below still fails.

This is deliberately not a check of errno on the tests' own write: that
was raised in the April discussion of the mm/config fix, and checking the
result of the operation under test cannot tell a policy refusal from a
failure of the operation itself.  The probe isolates the question, and
the test then either runs unchanged or is skipped at its entry.

Tested on x86_64 with a kernel built from this base whose .config has
CONFIG_PROC_MEM_FORCE_PTRACE=y, CONFIG_CHECKPOINT_RESTORE=n,
CONFIG_USERFAULTFD=n, CONFIG_KSM=y:

  default boot
    mkdirty              pass:3 skip:3 (2 EIO from the probe, 1 no uffd)
    ksm_functional_tests pass:8 skip:2 (test_prot_none, 1 no uffd)

  boot with proc_mem.force_override=always
    mkdirty              pass:5 skip:1 (no uffd)
    ksm_functional_tests pass:9 skip:1 (no uffd)

When the probe causes a skip, it is reported as "FOLL_FORCE write into
a ... mapping returned EIO", and no other test changes its result.


Nikolai Dokutovich (3):
  selftests/mm: add a probe for FOLL_FORCE writes through /proc/self/mem
  selftests/mm: skip the mkdirty ptrace write tests without FOLL_FORCE
  selftests/mm: skip the ksm PROT_NONE test without FOLL_FORCE

 .../selftests/mm/ksm_functional_tests.c       |  5 +++
 tools/testing/selftests/mm/mkdirty.c          | 13 ++++++
 tools/testing/selftests/mm/vm_util.c          | 42 +++++++++++++++++++
 tools/testing/selftests/mm/vm_util.h          | 16 +++++++
 4 files changed, 76 insertions(+)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread
* [PATCH 0/3] selftests/mm: skip tests when FOLL_FORCE writes are denied
@ 2026-11-29  4:00 Nikolai Dokutovich
  2026-11-29  4:00 ` [PATCH 3/3] selftests/mm: skip the ksm PROT_NONE test without FOLL_FORCE Nikolai Dokutovich
  0 siblings, 1 reply; 5+ messages in thread
From: Nikolai Dokutovich @ 2026-11-29  4:00 UTC (permalink / raw)
  To: David Hildenbrand, Andrew Morton
  Cc: Shuah Khan, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Michal Hocko, linux-mm, linux-kselftest, linux-kernel,
	Nikolai Dokutovich

A write through /proc/self/mem into a mapping that is not writable is
performed by the kernel as a forced write.  Since commit
41e8149c8892 ("proc: add config & param to block forcing mem writes")
such a write is refused unless the writing task is tracing the target
task, the kernel was built with CONFIG_PROC_MEM_ALWAYS_FORCE, or it was
booted with proc_mem.force_override=always.  Commit
599bbba5a36f ("proc: make PROC_MEM_FORCE_PTRACE the Kconfig default") made
the refusal the default.

Commit a3907a3169d0 ("selftests/mm: specify requirement for
PROC_MEM_ALWAYS_FORCE=y") set CONFIG_PROC_MEM_ALWAYS_FORCE=y in mm/config.
That fragment is merged into the kernel configuration only when it is
requested, so a test binary run against a distribution kernel is not
covered, and mkdirty and the ksm PROT_NONE test then report failures
instead of skipping:

    not ok 1 write() failed
    not ok 5 ptrace write failed

The first patch adds a probe to vm_util that reports whether such a write
is permitted.  The kernel reports a refused forced write as -EIO, because
the transfer copies zero bytes and mem_rw() maps that to -EIO.  The same
error also covers any other zero-byte remote access, so the probe treats
-EIO as a refusal but returns a distinct value for every other outcome:
the tests skip only on -EIO, and once the probe is allowed a real fault in
the test below still fails.

This is deliberately not a check of errno on the tests' own write: that
was raised in the April discussion of the mm/config fix, and checking the
result of the operation under test cannot tell a policy refusal from a
failure of the operation itself.  The probe isolates the question, and
the test then either runs unchanged or is skipped at its entry.

Tested on x86_64 with a kernel built from this base whose .config has
CONFIG_PROC_MEM_FORCE_PTRACE=y, CONFIG_CHECKPOINT_RESTORE=n,
CONFIG_USERFAULTFD=n, CONFIG_KSM=y:

  default boot
    mkdirty              pass:3 skip:3 (2 EIO from the probe, 1 no uffd)
    ksm_functional_tests pass:8 skip:2 (test_prot_none, 1 no uffd)

  boot with proc_mem.force_override=always
    mkdirty              pass:5 skip:1 (no uffd)
    ksm_functional_tests pass:9 skip:1 (no uffd)

When the probe causes a skip, it is reported as "FOLL_FORCE write into
a ... mapping returned EIO", and no other test changes its result.


Nikolai Dokutovich (3):
  selftests/mm: add a probe for FOLL_FORCE writes through /proc/self/mem
  selftests/mm: skip the mkdirty ptrace write tests without FOLL_FORCE
  selftests/mm: skip the ksm PROT_NONE test without FOLL_FORCE

 .../selftests/mm/ksm_functional_tests.c       |  5 +++
 tools/testing/selftests/mm/mkdirty.c          | 13 ++++++
 tools/testing/selftests/mm/vm_util.c          | 42 +++++++++++++++++++
 tools/testing/selftests/mm/vm_util.h          | 16 +++++++
 4 files changed, 76 insertions(+)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-29  4:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29  4:00 [PATCH 0/3] selftests/mm: skip tests when FOLL_FORCE writes are denied Nikolai Dokutovich
2026-11-29  4:00 ` [PATCH 1/3] selftests/mm: add a probe for FOLL_FORCE writes through /proc/self/mem Nikolai Dokutovich
2026-11-29  4:00 ` [PATCH 2/3] selftests/mm: skip the mkdirty ptrace write tests without FOLL_FORCE Nikolai Dokutovich
2026-11-29  4:00 ` [PATCH 3/3] selftests/mm: skip the ksm PROT_NONE test " Nikolai Dokutovich
2026-11-29  4:00 [PATCH 0/3] selftests/mm: skip tests when FOLL_FORCE writes are denied Nikolai Dokutovich
2026-11-29  4:00 ` [PATCH 3/3] selftests/mm: skip the ksm PROT_NONE test without FOLL_FORCE Nikolai Dokutovich

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®