Skip to contentSkip to conversation

waitid10: Fix when coredumps are piped

PATCH In review Cyril Hrubis 2 participants 4 messages Mar 21, 2022 – Mar 22, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 waitid10: Fix when coredumps are piped

When coredumps are piped into a stdin of a program (the core_pattern starts with '|') the RLIMIT_CORE limits are not enforced.

This fixes the test expectation in the corner case that rlim_cur and rlim_max for RLIMIT_CORE are both set to 0 but the core pattern is set to dump core into a pipe where we previously assumed the core wouldn't be dumped.

---
 testcases/kernel/syscalls/waitid/waitid10.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/waitid/waitid10.c +4 -1
index 869ef18bd..e75edd07e 100644
@@ -45,14 +45,17 @@ static void run(void)
 static void setup(void)
 {
 	struct rlimit rlim;
+	char c;
 
 	SAFE_GETRLIMIT(RLIMIT_CORE, &rlim);
+	SAFE_FILE_SCANF("/proc/sys/kernel/core_pattern", "%c", &c);
 
 	if (rlim.rlim_cur)
 		return;
 
 	if (!rlim.rlim_max) {
-		core_dumps = 0;
+		if (c != '|')
+			core_dumps = 0;
 		return;
 	}
 
Signature · 5 lines
2.34.1


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

Hello

Quoted 38 lines · Cyril Hrubis

When coredumps are piped into a stdin of a program (the core_pattern starts with '|') the RLIMIT_CORE limits are not enforced.

This fixes the test expectation in the corner case that rlim_cur and rlim_max for RLIMIT_CORE are both set to 0 but the core pattern is set to dump core into a pipe where we previously assumed the core wouldn't be dumped.

---
 testcases/kernel/syscalls/waitid/waitid10.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/waitid/waitid10.c +4 -1
index 869ef18bd..e75edd07e 100644
@@ -45,14 +45,17 @@ static void run(void)
 static void setup(void)
 {
 	struct rlimit rlim;
+	char c;
 
 	SAFE_GETRLIMIT(RLIMIT_CORE, &rlim);
+	SAFE_FILE_SCANF("/proc/sys/kernel/core_pattern", "%c", &c);
 
 	if (rlim.rlim_cur)
 		return;
 
 	if (!rlim.rlim_max) {
-		core_dumps = 0;
+		if (c != '|')
+			core_dumps = 0;
 		return;
 	}
 
Signature · 1 line
2.34.1

BTW I thought that division by zero actually just resulted in zero or INT_MAX on some platforms? (e.g. ARM)

It's undefined behaviour, so I fail to see how this test has ever worked on some architectures. Perhaps we should dereference a null/invalid pointer instead?

Signature · 5 lines
Thank you,
Richard.

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

Hi!

Quoted 8 lines

BTW I thought that division by zero actually just resulted in zero or INT_MAX on some platforms? (e.g. ARM)

It's undefined behaviour, so I fail to see how this test has ever worked on some architectures. Perhaps we should dereference a null/invalid pointer instead?

That wouldn't work since we are trying to get SIGFPE not SIGSEGV.

See:

http://patchwork.ozlabs.org/project/ltp/patch/[email protected]/

Also if you can review this patch as well...

Signature · 5 lines
Cyril Hrubis
[email protected]

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