Skip to contentSkip to conversation

setrlimit05: Use another method to get bad address

PATCH Superseded Hongzhi.Song 2 participants 3 messages Nov 6, 2018

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 setrlimit05: Use another method to get bad address

V2:

    put tst_get_bad_add() to setup();

Hongzhi.Song (1):
kernel/syscall/setrlimit05.c: use a legal bad address for mips

 testcases/kernel/syscalls/setrlimit/setrlimit05.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
Signature · 1 line
2.8.1
#1 lore raw

PATCH v2 1/1 kernel/syscall/setrlimit05.c: use a legal bad address for mips

This testcase fails on mips32. The process is killed by SIGBUS which doesn't return EFAULT as expect.

This is because:
((void *)-1) is not a legal bad address which causes the process killed by SIGBUG on mips.

'tst_get_bad_addr()' returns an address that should work on mips and other arches.

---
 testcases/kernel/syscalls/setrlimit/setrlimit05.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/setrlimit/setrlimit05.c +9 -1
index e716722..92ff33c 100644
@@ -26,6 +26,8 @@
 
 #include "tst_test.h"
 
+static void *bad_addr;
+
 static void verify_setrlimit(void)
 {
 	int status;
@@ -33,7 +35,7 @@ static void verify_setrlimit(void)
 
 	pid = SAFE_FORK();
 	if (!pid) {
-		TEST(setrlimit(RLIMIT_NOFILE, (void *) -1));
+		TEST(setrlimit(RLIMIT_NOFILE, (struct rlimit *)bad_addr));
 		if (TST_RET != -1) {
 			tst_res(TFAIL, "setrlimit()  succeeded unexpectedly");
 			exit(0);
@@ -67,7 +69,13 @@ static void verify_setrlimit(void)
 	tst_res(TBROK, "child %s", tst_strstatus(status));
 }
 
+static void setup(void)
+{
+    bad_addr = tst_get_bad_addr(NULL);
+}
+
 static struct tst_test test = {
 	.test_all = verify_setrlimit,
 	.forks_child = 1,
+    .setup = setup,
 };
Signature · 1 line
2.8.1
#2 lore raw

PATCH v2 1/1 kernel/syscall/setrlimit05.c: use a legal bad address for mips

Hi!

Quoted 9 lines

This testcase fails on mips32. The process is killed by SIGBUS which doesn't return EFAULT as expect.

This is because:
((void *)-1) is not a legal bad address which causes the process killed by SIGBUG on mips.

'tst_get_bad_addr()' returns an address that should work on mips and other arches.

Generally looks good, minor nits pointed out below.

Quoted 19 lines
---
 testcases/kernel/syscalls/setrlimit/setrlimit05.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/setrlimit/setrlimit05.c +2 -0
index e716722..92ff33c 100644
@@ -26,6 +26,8 @@
 
 #include "tst_test.h"
 
+static void *bad_addr;
+
 static void verify_setrlimit(void)
 {
 	int status;

testcases/kernel/syscalls/setrlimit/setrlimit05.c static void verify_setrlimit(void) · line 38

Quoted 5 lines
testcases/kernel/syscalls/setrlimit/setrlimit05.c +1 -1
@@ -33,7 +35,7 @@ static void verify_setrlimit(void)
 
 	pid = SAFE_FORK();
 	if (!pid) {
-		TEST(setrlimit(RLIMIT_NOFILE, (void *) -1));
+		TEST(setrlimit(RLIMIT_NOFILE, (struct rlimit *)bad_addr));

^
This cast is not needed, in C void * pointer is converted to any other pointer automatically.

testcases/kernel/syscalls/setrlimit/setrlimit05.c static void verify_setrlimit(void) · line 74

Quoted 10 lines
testcases/kernel/syscalls/setrlimit/setrlimit05.c +3 -0
 		if (TST_RET != -1) {
 			tst_res(TFAIL, "setrlimit()  succeeded unexpectedly");
 			exit(0);
@@ -67,7 +69,13 @@ static void verify_setrlimit(void)
 	tst_res(TBROK, "child %s", tst_strstatus(status));
 }
 
+static void setup(void)
+{
+    bad_addr = tst_get_bad_addr(NULL);

You really should use tabs instead of spaces for indentation.

testcases/kernel/syscalls/setrlimit/setrlimit05.c static void verify_setrlimit(void) · line 80

Quoted 6 lines
testcases/kernel/syscalls/setrlimit/setrlimit05.c +3 -0
+}
+
 static struct tst_test test = {
 	.test_all = verify_setrlimit,
 	.forks_child = 1,
+    .setup = setup,

Here as well.

Quoted 7 lines
testcases/kernel/syscalls/setrlimit/setrlimit05.c +0 -0
 };
Signature · 5 lines
2.8.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]