All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nikolai Dokutovich <ndokutovich@gmail.com>
To: David Hildenbrand <david@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: Shuah Khan <shuah@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Mike Rapoport <rppt@kernel.org>, Michal Hocko <mhocko@suse.com>,
	linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Nikolai Dokutovich <ndokutovich@gmail.com>
Subject: [PATCH v3 0/3] selftests/mm: skip tests when FOLL_FORCE writes are denied
Date: Mon, 30 Nov 2026 20:39:47 +0300	[thread overview]
Message-ID: <20261130173950.41003-1-ndokutovich@gmail.com> (raw)

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 permission belongs to the kernel and the calling task,
not to the mapping, so the probe takes no protection argument: it maps one
read-only page and writes a byte through /proc/self/mem.  A refused forced
write copies zero bytes and mem_rw() reports that as -EIO, but any other
zero-byte remote access reports the same, so -EIO can indicate a refusal
without proving one.  Only the two decisive results are cached; anything
else is inconclusive, returns allowed and is not cached, so the test below
still runs and can fail.

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 with this series on x86_64 against 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 probe skips, 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 probe
returned EIO", and no other test changes its result.

Changes in v3:
 - Reduce the probe to bool proc_mem_force_write_allowed(void), taking no
   protection argument and caching the answer internally, as David
   Hildenbrand asked.
 - Call it at the entry of each affected test instead of caching the result
   in mkdirty's main().


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          | 10 ++++
 tools/testing/selftests/mm/vm_util.c          | 47 +++++++++++++++++++
 tools/testing/selftests/mm/vm_util.h          | 17 +++++++
 4 files changed, 79 insertions(+)

-- 
2.43.0


             reply	other threads:[~2026-11-30 17:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 17:39 Nikolai Dokutovich [this message]
2026-11-30 17:39 ` [PATCH v3 1/3] selftests/mm: add a probe for FOLL_FORCE writes through /proc/self/mem Nikolai Dokutovich
2026-12-01  7:04   ` xu.xin
2026-12-01 16:22   ` David Hildenbrand (Arm)
2026-11-30 17:39 ` [PATCH v3 2/3] selftests/mm: skip the mkdirty ptrace write tests without FOLL_FORCE Nikolai Dokutovich
2026-12-01  7:06   ` xu.xin
2026-12-01 16:23   ` David Hildenbrand (Arm)
2026-11-30 17:39 ` [PATCH v3 3/3] selftests/mm: skip the ksm PROT_NONE test " Nikolai Dokutovich
2026-12-01  7:07   ` xu.xin
2026-12-01  7:15   ` xu.xin
2026-12-01 16:23     ` David Hildenbrand (Arm)
2026-12-01 19:17     ` Nikolai Dokutovich

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=20261130173950.41003-1-ndokutovich@gmail.com \
    --to=ndokutovich@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=rppt@kernel.org \
    --cc=shuah@kernel.org \
    --cc=vbabka@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.