[LTP] [PATCH] syscalls/madvise11: Ignore unpoison failure under kernel lockdown

Martin Doucha mdoucha@suse.cz
Wed Jun 7 16:45:17 CEST 2023


When newer kernels are under lockdown, the unpoison-pfn sysfile
still appears writable to root but open() will always return EPERM.
This causes madvise11 to fail with TWARN during cleanup when run
with SecureBoot enabled.

Ignore the open(unpoison-pfn) failure due to lockdown and exit
successfully without cleanup. The test should not be skipped because
the leftover soft-offlined pages can trigger failures in later tests
and indirectly expose kernel bugs in hwpoison.

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
 testcases/kernel/syscalls/madvise/madvise11.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/madvise/madvise11.c b/testcases/kernel/syscalls/madvise/madvise11.c
index 2cb45d00a..e63e28f8a 100644
--- a/testcases/kernel/syscalls/madvise/madvise11.c
+++ b/testcases/kernel/syscalls/madvise/madvise11.c
@@ -323,7 +323,20 @@ static int open_unpoison_pfn(void)
 	if (!mnt)
 		return -1;
 
-	return SAFE_OPEN(debugfs_fp, O_WRONLY);
+	TEST(open(debugfs_fp, O_WRONLY));
+
+	if (TST_RET == -1 && TST_ERR == EPERM && tst_lockdown_enabled()) {
+		tst_res(TINFO,
+			"Cannot restore soft-offlined memory due to lockdown");
+		return TST_RET;
+	}
+
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "open(%s) failed", debugfs_fp);
+	else if (TST_RET < 0)
+		tst_brk(TBROK | TTERRNO, "Invalid open() return value");
+
+	return TST_RET;
 }
 
 /*
-- 
2.40.0



More information about the ltp mailing list