Linux Test Project
 help / color / mirror / Atom feed
From: Jan Polensky <japo@linux.ibm.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v1 1/1] thp04: Skip when FOLL_FORCE writes are disabled
Date: Tue, 26 May 2026 17:08:13 +0200	[thread overview]
Message-ID: <20260526150813.201280-1-japo@linux.ibm.com> (raw)

Since commit 41e8149c8892 ("proc: add config & param to block forcing
mem writes"), /proc/self/mem writes using FOLL_FORCE can be blocked by
CONFIG_PROC_MEM_NO_FORCE or proc_mem_force_write=0 as a security
hardening measure.

On such systems, thp04 fails with EIO during the /proc/self/mem write.
This is expected kernel behavior, not a real test failure.

Add a pre-flight write check in setup() and return TCONF on EIO, with
an explanation that FOLL_FORCE writes are disabled by kernel hardening.

This makes thp04 skip on hardened systems instead of reporting a false
failure.

Signed-off-by: Jan Polensky <japo@linux.ibm.com>
---
 testcases/kernel/mem/thp/thp04.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/testcases/kernel/mem/thp/thp04.c b/testcases/kernel/mem/thp/thp04.c
index 16d766c349b7..a5748c09cb70 100644
--- a/testcases/kernel/mem/thp/thp04.c
+++ b/testcases/kernel/mem/thp/thp04.c
@@ -73,6 +73,7 @@ static void *alloc_zero_page(void *baseaddr)
 static void setup(void)
 {
 	size_t i;
+	int test_val = 0;
 
 	thp_size = tst_get_hugepage_size();
 
@@ -93,6 +94,28 @@ static void setup(void)
 	writefd = SAFE_OPEN("/proc/self/mem", O_RDWR);
 	readfd = SAFE_OPEN("/proc/self/mem", O_RDWR);
 
+	/*
+	 * Test if /proc/self/mem write with FOLL_FORCE works. Since kernel commit
+	 * 41e8149c8892 ("proc: add config & param to block forcing mem writes")
+	 * (Aug 2024), writes can be blocked by CONFIG_PROC_MEM_NO_FORCE or
+	 * proc_mem_force_write=0 boot param.
+	 */
+	TEST(lseek(writefd, (off_t)write_ptr, SEEK_SET));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "lseek on /proc/self/mem failed");
+
+	TEST(write(writefd, &test_val, sizeof(test_val)));
+	if (TST_RET == -1) {
+		if (TST_ERR == EIO) {
+			tst_brk(TCONF,
+				"/proc/self/mem write with FOLL_FORCE is disabled. "
+				"This is a kernel security feature (commit 41e8149c8892). "
+				"To enable: boot with proc_mem_force_write=1 or "
+				"rebuild kernel with CONFIG_PROC_MEM_FORCE_WRITE=y");
+		}
+		tst_brk(TBROK | TTERRNO, "test write to /proc/self/mem failed");
+	}
+
 	fzsync_pair.exec_loops = 100000;
 	tst_fzsync_pair_init(&fzsync_pair);
 }
-- 
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

             reply	other threads:[~2026-05-26 15:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-26 15:08 Jan Polensky [this message]
2026-05-26 15:32 ` [LTP] thp04: Skip when FOLL_FORCE writes are disabled linuxtestproject.agent
2026-05-26 16:09 ` [LTP] [PATCH v1 1/1] " Cyril Hrubis

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=20260526150813.201280-1-japo@linux.ibm.com \
    --to=japo@linux.ibm.com \
    --cc=ltp@lists.linux.it \
    /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