[LTP] [PATCH v2] landlock04: Fix false TFAIL in _test_truncate() deny path
Avinesh Kumar
avinesh.kumar@suse.com
Mon Aug 24 15:57:21 CEST 2026
From: Avinesh Kumar <avinesh.kumar@suse.com>
commit 8643b01a68cf converted an intentionally-unchecked open() call
(used only to get an fd for the ftruncate() sub-test) into
TST_EXP_FD_OR_FAIL(), wrongly asserting it must fail with EACCES on
the deny path. Its outcome depends on other granted rights and isn't
guaranteed, causing a false TFAIL when it succeeded.
landlock_tester.h:257: TFAIL: open(FILE_TRUNCATE, O_WRONLY, PERM_MODE) invalid retval 4: SUCCESS (0)
Restore the unchecked open() on the deny path, keep SAFE_OPEN() on the
pass path, and only treat EACCES as an expected reason to skip the
ftruncate() sub-test.
Also fix SAFE_CLOSE(TST_RET) to SAFE_CLOSE(fd) for consistency.
Fixes: 8643b01a68cf ("tree: Use TST_EXP_PASS_OR_FAIL() and TST_EXP_FD_OR_FAIL()")
Signed-off-by: Avinesh Kumar <avinesh.kumar@suse.com>
---
testcases/kernel/syscalls/landlock/landlock_tester.h | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/testcases/kernel/syscalls/landlock/landlock_tester.h b/testcases/kernel/syscalls/landlock/landlock_tester.h
index f44721245144..904e43d7f930 100644
--- a/testcases/kernel/syscalls/landlock/landlock_tester.h
+++ b/testcases/kernel/syscalls/landlock/landlock_tester.h
@@ -254,7 +254,14 @@ static void _test_truncate(const int exp_err)
tst_res(TINFO, "Test truncating file");
TST_EXP_PASS_OR_FAIL(truncate(FILE_TRUNCATE, 10), exp_err);
- fd = TST_EXP_FD_OR_FAIL(open(FILE_TRUNCATE, O_WRONLY, PERM_MODE), exp_err);
+
+ if (!exp_err) {
+ fd = SAFE_OPEN(FILE_TRUNCATE, O_WRONLY, PERM_MODE);
+ } else {
+ fd = open(FILE_TRUNCATE, O_WRONLY, PERM_MODE);
+ if (fd == -1 && errno != EACCES)
+ tst_res(TFAIL | TERRNO, "open(%s, O_WRONLY) failed unexpectedly", FILE_TRUNCATE);
+ }
if (fd != -1) {
TST_EXP_PASS_OR_FAIL(ftruncate(fd, 10), exp_err);
SAFE_CLOSE(fd);
@@ -262,7 +269,7 @@ static void _test_truncate(const int exp_err)
fd = TST_EXP_FD_OR_FAIL(open(FILE_TRUNCATE, O_WRONLY | O_TRUNC, PERM_MODE), exp_err);
if (fd != -1)
- SAFE_CLOSE(TST_RET);
+ SAFE_CLOSE(fd);
}
static void tester_run_fs_rules(const int rules, const int result)
--
2.55.0
More information about the ltp
mailing list