Skip to contentSkip to conversation

syscalls/madvise11: Ignore unpoison failure under kernel lockdown

PATCH Superseded Martin Doucha 2 participants 4 messages Jun 7, 2023 – Jun 20, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscalls/madvise11: Ignore unpoison failure under kernel lockdown

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.

---
 testcases/kernel/syscalls/madvise/madvise11.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/madvise/madvise11.c +14 -1
index 2cb45d00a..e63e28f8a 100644
@@ -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;
 }
 
 /*
Signature · 5 lines
2.40.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 1/1
#1 lore raw

Hi Martin,

...

testcases/kernel/syscalls/madvise/madvise11.c static int open_unpoison_pfn(void) · line 337

Quoted 13 lines
testcases/kernel/syscalls/madvise/madvise11.c +12 -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");

nit: I'd print the return value as we do in safe_open():

		tst_brk(TBROK | TTERRNO, "Invalid open() return value %d", TST_RET);

Thanks for fixing this!

Kind regards,
Petr

Quoted 3 lines
testcases/kernel/syscalls/madvise/madvise11.c +2 -0
+
+	return TST_RET;
 }
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
Quoted 17 lines · Petr Vorel

Hi Martin,

...

testcases/kernel/syscalls/madvise/madvise11.c static int open_unpoison_pfn(void) · line 337

Quoted 13 lines
testcases/kernel/syscalls/madvise/madvise11.c +12 -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");

nit: I'd print the return value as we do in safe_open():

Quoted 1 line
		tst_brk(TBROK | TTERRNO, "Invalid open() return value %d", TST_RET);

Good point. Though TST_RET is long int so it should be %ld. Should I send a v2?

Signature · 11 lines
Martin Doucha   [email protected]
SW Quality Engineer
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
Quoted 20 lines · Petr Vorel
Quoted 17 lines

Hi Martin,

...

testcases/kernel/syscalls/madvise/madvise11.c static int open_unpoison_pfn(void) · line 337

Quoted 13 lines
testcases/kernel/syscalls/madvise/madvise11.c +12 -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");

nit: I'd print the return value as we do in safe_open():

Quoted 1 line
		tst_brk(TBROK | TTERRNO, "Invalid open() return value %d", TST_RET);
Quoted 2 lines

Good point. Though TST_RET is long int so it should be %ld. Should I send a v2?

Yes, please.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp