landlock04: Fix false TFAIL in _test_truncate() deny path
PATCH 1/1 landlock04: Fix false TFAIL in _test_truncate() deny path
From: Avinesh Kumar <[email protected]>
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. Also fix SAFE_CLOSE(TST_RET) to SAFE_CLOSE(fd) for consistency.
--- testcases/kernel/syscalls/landlock/landlock_tester.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/landlock/landlock_tester.h +3 -2
@@ -254,7 +254,8 @@ 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); + fd = exp_err ?open (FILE_TRUNCATE ,O_WRONLY ,PERM_MODE ) + :SAFE_OPEN (FILE_TRUNCATE ,O_WRONLY ,PERM_MODE );if (fd !=-1 ) {TST_EXP_PASS_OR_FAIL (ftruncate (fd,10 ), exp_err);SAFE_CLOSE (fd);
@@ -262,7 +263,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)
Signature · 5 lines
2.55.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Avinesh,
testcases/kernel/syscalls/landlock/landlock_tester.h static void _test_truncate(const int exp_err) · line 259
Quoted 5 lines · Avinesh Kumar
landlock04: Fix false TFAIL in
_test_truncate()deny pathtestcases/kernel/syscalls/landlock/landlock_tester.h +2
-0+ fd = exp_err ?open (FILE_TRUNCATE ,O_WRONLY ,PERM_MODE ) + :SAFE_OPEN (FILE_TRUNCATE ,O_WRONLY ,PERM_MODE );if (fd !=-1 ) {
Could the deny branch report open() errors other than EACCES? EACCES is an expected reason to skip ftruncate() when write access is denied, but open(2) can also fail with EMFILE, ENFILE, or ENOMEM. Those failures currently take the same fd == -1 path, silently skip the ftruncate() assertion, and let the variant pass without testing it.
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/1 landlock04: Fix false TFAIL in _test_truncate() deny path
From: Avinesh Kumar <[email protected]>
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.
--- testcases/kernel/syscalls/landlock/landlock_tester.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/landlock/landlock_tester.h +9 -2
@@ -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)
Signature · 5 lines
2.55.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Avinesh,
Quoted 1 line · Avinesh Kumar
landlock04: Fix false TFAIL in
_test_truncate()deny path
Verdict - Reviewed
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Avinesh,
Thanks for the fix, merged!
I'm sorry for introducing the regression (I tested whole landlock part, but obviously wrongly when this one slipped in).
...
testcases/kernel/syscalls/landlock/landlock_tester.h static void _test_truncate(const int exp_err) · line 263
Quoted 9 lines
testcases/kernel/syscalls/landlock/landlock_tester.h +7
-1TST_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 );
nit: there still could have been TST_EXP_FD_OR_FAIL() for else part:
fd = TST_EXP_FD_OR_FAIL(open(FILE_TRUNCATE, O_WRONLY, PERM_MODE), exp_err);
I personally prefer these shortening macros, but maybe they aren't that much readable when others don't use it. Therefore merged as is.
Kind regards,
Petr
Quoted 11 lines
testcases/kernel/syscalls/landlock/landlock_tester.h +2
-1+ }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); }
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp