Skip to contentSkip to conversation

Added new_behavior flag to detect kernel version Kernel >= 6.11: Tests that creat() succeeds (write to executed file allowed)

PATCH In review [email protected] 4 participants 5 messages Apr 8 – Apr 28

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Added new_behavior flag to detect kernel version Kernel >= 6.11: Tests that creat() succeeds (write to executed file allowed)

From: lekshmi-cpillai <[email protected]>

---
 testcases/kernel/syscalls/creat/creat07.c | 38 ++++++++++++++++-------
 1 file changed, 27 insertions(+), 11 deletions(-)
testcases/kernel/syscalls/creat/creat07.c +27 -11
index c7b85ee69..762022301 100644
@@ -19,6 +19,8 @@
 
 #define TEST_APP "creat07_child"
 
+static int new_behavior;
+
 static void verify_creat(void)
 {
 	pid_t pid;
@@ -33,16 +35,26 @@ static void verify_creat(void)
 
 	TEST(creat(TEST_APP, O_WRONLY));
 
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "creat() succeeded unexpectedly");
-		return;
+	if (new_behavior) {
+		/* Kernel >= 6.11: write to executed file is allowed */
+		if (TST_RET != -1) {
+			SAFE_CLOSE(TST_RET);
+			tst_res(TPASS, "creat() succeeded as expected (new behavior)");
+		} else {
+			tst_res(TFAIL | TTERRNO, "creat() failed unexpectedly");
+		}
+	} else {
+		/* Kernel < 6.11: write to executed file returns ETXTBSY */
+		if (TST_RET != -1) {
+			tst_res(TFAIL, "creat() succeeded unexpectedly");
+			SAFE_CLOSE(TST_RET);
+		} else if (TST_ERR == ETXTBSY) {
+			tst_res(TPASS, "creat() received ETXTBSY");
+		} else {
+			tst_res(TFAIL | TTERRNO, "creat() failed unexpectedly");
+		}
 	}
 
-	if (TST_ERR == ETXTBSY)
-		tst_res(TPASS, "creat() received EXTBSY");
-	else
-		tst_res(TFAIL | TTERRNO, "creat() failed unexpectedly");
-
 	SAFE_KILL(pid, SIGKILL);
 	SAFE_WAITPID(pid, NULL, 0);
 }
@@ -50,9 +62,13 @@ static void verify_creat(void)
 static void setup(void)
 {
 	if ((tst_kvercmp(6, 11, 0)) >= 0) {
-		tst_brk(TCONF, "Skipping test, write to executed file is "
-			"allowed since 6.11-rc1.\n"
-			"2a010c412853 (\"fs: don't block i_writecount during exec\")");
+		new_behavior = 1;
+		tst_res(TINFO, "Testing new behavior: write to executed file is "
+			"allowed since 6.11-rc1 (2a010c412853)");
+	} else {
+		new_behavior = 0;
+		tst_res(TINFO, "Testing old behavior: write to executed file "
+			"returns ETXTBSY");
 	}
 }
 
Signature · 5 lines
2.39.1


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

Hi!

Quoted 44 lines
testcases/kernel/syscalls/creat/creat07.c +20 -8
+static int new_behavior;
+
 static void verify_creat(void)
 {
 	pid_t pid;
@@ -33,16 +35,26 @@ static void verify_creat(void)
 
 	TEST(creat(TEST_APP, O_WRONLY));
 
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "creat() succeeded unexpectedly");
-		return;
+	if (new_behavior) {
+		/* Kernel >= 6.11: write to executed file is allowed */
+		if (TST_RET != -1) {
+			SAFE_CLOSE(TST_RET);
+			tst_res(TPASS, "creat() succeeded as expected (new behavior)");
+		} else {
+			tst_res(TFAIL | TTERRNO, "creat() failed unexpectedly");
+		}
+	} else {
+		/* Kernel < 6.11: write to executed file returns ETXTBSY */
+		if (TST_RET != -1) {
+			tst_res(TFAIL, "creat() succeeded unexpectedly");
+			SAFE_CLOSE(TST_RET);
+		} else if (TST_ERR == ETXTBSY) {
+			tst_res(TPASS, "creat() received ETXTBSY");
+		} else {
+			tst_res(TFAIL | TTERRNO, "creat() failed unexpectedly");
+		}
 	}
 
-	if (TST_ERR == ETXTBSY)
-		tst_res(TPASS, "creat() received EXTBSY");
-	else
-		tst_res(TFAIL | TTERRNO, "creat() failed unexpectedly");
-
 	SAFE_KILL(pid, SIGKILL);
 	SAFE_WAITPID(pid, NULL, 0);
 }
@@ -50,9 +62,13 @@ static void verify_creat(void)
 static void setup(void)
 {
 	if ((tst_kvercmp(6, 11, 0)) >= 0) {

testcases/kernel/syscalls/creat/creat07.c static void verify_creat(void) · line 71

Quoted 10 lines
testcases/kernel/syscalls/creat/creat07.c +7 -3
-		tst_brk(TCONF, "Skipping test, write to executed file is "
-			"allowed since 6.11-rc1.\n"
-			"2a010c412853 (\"fs: don't block i_writecount during exec\")");
+		new_behavior = 1;
+		tst_res(TINFO, "Testing new behavior: write to executed file is "
+			"allowed since 6.11-rc1 (2a010c412853)");
+	} else {
+		new_behavior = 0;
+		tst_res(TINFO, "Testing old behavior: write to executed file "
+			"returns ETXTBSY");

Apart from the code being ugly and having way too much verbose messages the test is likely broken with -i 2 command line option on newer kernels.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

PATCH 1/1 Added new_behavior flag to detect kernel version Kernel >= 6.11: Tests that creat() succeeds (write to executed file allowed)

In reply to [email protected]

From: lekshmi-cpillai <[email protected]>

---
 testcases/kernel/syscalls/creat/creat07.c | 38 ++++++++++++++++-------
 1 file changed, 27 insertions(+), 11 deletions(-)
testcases/kernel/syscalls/creat/creat07.c +27 -11
index c7b85ee69..762022301 100644
@@ -19,6 +19,8 @@
 
 #define TEST_APP "creat07_child"
 
+static int new_behavior;
+
 static void verify_creat(void)
 {
 	pid_t pid;
@@ -33,16 +35,26 @@ static void verify_creat(void)
 
 	TEST(creat(TEST_APP, O_WRONLY));
 
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "creat() succeeded unexpectedly");
-		return;
+	if (new_behavior) {
+		/* Kernel >= 6.11: write to executed file is allowed */
+		if (TST_RET != -1) {
+			SAFE_CLOSE(TST_RET);
+			tst_res(TPASS, "creat() succeeded as expected (new behavior)");
+		} else {
+			tst_res(TFAIL | TTERRNO, "creat() failed unexpectedly");
+		}
+	} else {
+		/* Kernel < 6.11: write to executed file returns ETXTBSY */
+		if (TST_RET != -1) {
+			tst_res(TFAIL, "creat() succeeded unexpectedly");
+			SAFE_CLOSE(TST_RET);
+		} else if (TST_ERR == ETXTBSY) {
+			tst_res(TPASS, "creat() received ETXTBSY");
+		} else {
+			tst_res(TFAIL | TTERRNO, "creat() failed unexpectedly");
+		}
 	}
 
-	if (TST_ERR == ETXTBSY)
-		tst_res(TPASS, "creat() received EXTBSY");
-	else
-		tst_res(TFAIL | TTERRNO, "creat() failed unexpectedly");
-
 	SAFE_KILL(pid, SIGKILL);
 	SAFE_WAITPID(pid, NULL, 0);
 }
@@ -50,9 +62,13 @@ static void verify_creat(void)
 static void setup(void)
 {
 	if ((tst_kvercmp(6, 11, 0)) >= 0) {
-		tst_brk(TCONF, "Skipping test, write to executed file is "
-			"allowed since 6.11-rc1.\n"
-			"2a010c412853 (\"fs: don't block i_writecount during exec\")");
+		new_behavior = 1;
+		tst_res(TINFO, "Testing new behavior: write to executed file is "
+			"allowed since 6.11-rc1 (2a010c412853)");
+	} else {
+		new_behavior = 0;
+		tst_res(TINFO, "Testing old behavior: write to executed file "
+			"returns ETXTBSY");
 	}
 }
 
Signature · 5 lines
2.39.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi Lekshmi,

Quoted 1 line · lekshmi-cpillai

Added new_behavior flag to detect kernel version Kernel >= 6.11: Tests that creat() succeeds (write to executed file allowed)

Use imperative mood in the subject: "creat07: Support both old and new write-to-executed-file behavior". Also add a commit body explaining why the change is needed — that the previous tst_brk(TCONF) silently skipped the test on all kernels >= 6.11 instead of verifying the allowed behavior. Finally, the Signed-off-by tag is missing.

Quoted 1 line

+static int new_behavior;

[...]

testcases/kernel/syscalls/creat/creat07.c static void verify_creat(void) · line 65

Quoted 4 lines
testcases/kernel/syscalls/creat/creat07.c +1 -3
-               tst_brk(TCONF, "Skipping test, write to executed file is "
-                       "allowed since 6.11-rc1.\n"
-                       "2a010c412853 (\"fs: don't block i_writecount during exec\")");
+               new_behavior = 1;

The logic change is correct. However the doc comment at the top of the file still only mentions ETXTBSY — update it to describe both behaviors.

[...]

Pre-existing issues noticed in the surrounding code (not introduced by this patch):

- creat07.c:35 — O_WRONLY (value 1) is passed as the mode argument to creat(); the second parameter is mode_t, not open flags — likely intended to be 0600.

---
Note:

Our agent completed the review of the patch. The full review can be found at: https://github.com/linux-test-project/ltp-agent/actions/runs/24705759346

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
#4 lore raw
In reply to [email protected]

Hi,

Quoted 77 lines

From: lekshmi-cpillai <[email protected]>

---
 testcases/kernel/syscalls/creat/creat07.c | 38 ++++++++++++++++-------
 1 file changed, 27 insertions(+), 11 deletions(-)
testcases/kernel/syscalls/creat/creat07.c +27 -11
index c7b85ee69..762022301 100644
@@ -19,6 +19,8 @@
 
 #define TEST_APP "creat07_child"
 
+static int new_behavior;
+
 static void verify_creat(void)
 {
 	pid_t pid;
@@ -33,16 +35,26 @@ static void verify_creat(void)
 
 	TEST(creat(TEST_APP, O_WRONLY));
 
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "creat() succeeded unexpectedly");
-		return;
+	if (new_behavior) {
+		/* Kernel >= 6.11: write to executed file is allowed */
+		if (TST_RET != -1) {
+			SAFE_CLOSE(TST_RET);
+			tst_res(TPASS, "creat() succeeded as expected (new behavior)");
+		} else {
+			tst_res(TFAIL | TTERRNO, "creat() failed unexpectedly");
+		}
+	} else {
+		/* Kernel < 6.11: write to executed file returns ETXTBSY */
+		if (TST_RET != -1) {
+			tst_res(TFAIL, "creat() succeeded unexpectedly");
+			SAFE_CLOSE(TST_RET);
+		} else if (TST_ERR == ETXTBSY) {
+			tst_res(TPASS, "creat() received ETXTBSY");
+		} else {
+			tst_res(TFAIL | TTERRNO, "creat() failed unexpectedly");
+		}
 	}
 
-	if (TST_ERR == ETXTBSY)
-		tst_res(TPASS, "creat() received EXTBSY");
-	else
-		tst_res(TFAIL | TTERRNO, "creat() failed unexpectedly");
-
 	SAFE_KILL(pid, SIGKILL);
 	SAFE_WAITPID(pid, NULL, 0);
 }
@@ -50,9 +62,13 @@ static void verify_creat(void)
 static void setup(void)
 {
 	if ((tst_kvercmp(6, 11, 0)) >= 0) {
-		tst_brk(TCONF, "Skipping test, write to executed file is "
-			"allowed since 6.11-rc1.\n"
-			"2a010c412853 (\"fs: don't block i_writecount during exec\")");
+		new_behavior = 1;
+		tst_res(TINFO, "Testing new behavior: write to executed file is "
+			"allowed since 6.11-rc1 (2a010c412853)");
+	} else {
+		new_behavior = 0;
+		tst_res(TINFO, "Testing old behavior: write to executed file "
+			"returns ETXTBSY");
 	}
 }
 
Signature · 5 lines
2.39.1


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

There's too much going on in these nested statements. The new_behavior is not needed, we only need to save the error code (-1 or ETXTBSY) inside a static variable.

If it's not -1, TST_EXP_ERR() can be used. Otherwise we print a TPASS.

The kernel version is printed before every test execution, so there's no need to show any information about it.

Also test it with -i parameter. The test is likely broken with this patch.

Kind Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

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