Skip to contentSkip to conversation

coredump01: New core_pattern specifiers test

PATCH Superseded Andrea Cervesato 3 participants 3 messages Aug 20 – Aug 24

v1 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 coredump01: New core_pattern specifiers test

From: Andrea Cervesato <[email protected]>

LTP has no coverage for the core_pattern specifiers expansion, neither for the pipe flavor of core_pattern, where the kernel spawns a user space helper and writes the core dump into its standard input.

The new test verifies that %e, %p and %s are expanded both in the core file name and in the arguments of a piped helper, checking also that the helper really receives an ELF core dump.

Root is required to rewrite the system wide core_pattern, which is restored by the test library on all exit paths.

---
Add a simple coredump01 test that simulate a coredump and verify that it actually works. This is a small coverage that is missing inside LTP testing suite.

---
 runtest/kernel_misc                           |   1 +
 testcases/kernel/Makefile                     |   1 +
 testcases/kernel/coredump/.gitignore          |   2 +
 testcases/kernel/coredump/Makefile            |   7 ++
 testcases/kernel/coredump/coredump01.c        | 161 ++++++++++++++++++++++++++
 testcases/kernel/coredump/coredump01_helper.c |  66 +++++++++++
 6 files changed, 238 insertions(+)
runtest/kernel_misc +1 -0
index cc3562cb7..ecf9ee2a2 100644
@@ -17,3 +17,4 @@ zram02 zram02.sh
 zram03 zram03
 umip_basic_test umip_basic_test
 aslr01 aslr01
+coredump01 coredump01
testcases/kernel/Makefile +1 -0
index ac816e4e8..6b303c14b 100644
@@ -19,6 +19,7 @@ SUBDIRS			+= lib
 SUBDIRS			+= connectors \
 			   containers \
 			   controllers \
+			   coredump \
 			   crypto \
 			   device-drivers \
 			   firmware \
testcases/kernel/coredump/.gitignore new file +2 -0
new file mode 100644
index 000000000..cd0b51700
@@ -0,0 +1,2 @@
+/coredump01
+/coredump01_helper
testcases/kernel/coredump/Makefile new file +7 -0
new file mode 100644
index 000000000..951a3e976
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2026 Linux Test Project
+
+top_srcdir		?= ../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/coredump/coredump01.c new file +161 -0

161 lines not on this page · raw message

testcases/kernel/coredump/coredump01_helper.c new file +66 -0

66 lines not on this page · raw message

---
base-commit: e62b1a4731f9c458d65c2659d2f8bb58b93e6d6d
change-id: 20260820-coredump-22fc731bde08

Best regards,

Signature · 5 lines
Andrea Cervesato <[email protected]>


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

Hi Andrea,

Quoted 10 lines · Andrea Cervesato

coredump01: New core_pattern specifiers test

	ssize_t rval, i;
	int fd, elf;

	if (bytes >= 4 && !memcmp(magic, "\177ELF", 4))
		elf = 1;

	dprintf(fd, "exe=%s pid=%s sig=%s bytes=%lld elf=%d\n",
		argv[1], argv[2], argv[3], bytes, elf);

Could elf be initialized to zero? For short or non-ELF input the condition does not assign it, so dprintf() reads an indeterminate value. A nonzero value can make the test accept a malformed core stream as ELF.

Quoted 1 line
	SAFE_PRCTL(PR_GET_DUMPABLE, 1, 0, 0, 0);

Should this use PR_SET_DUMPABLE? PR_GET_DUMPABLE only returns the current state and ignores arg2, so this call does not ensure that abort() can produce a core dump.

Quoted 3 lines
	/* the kernel spawns the helper asynchronously */
	if (TST_RETRY_FN_EXP_BACKOFF(access(res, F_OK), TST_RETVAL_EQ0, HELPER_TIMEOUT)) {
		tst_res(TFAIL, "%s did not report any core dump", HELPER);

Could kernels with CONFIG_STATIC_USERMODEHELPER be rejected with TCONF before this check? In particular, an empty CONFIG_STATIC_USERMODEHELPER_PATH intentionally disables the helper, so this timeout reports TFAIL without testing specifier expansion.

Quoted 3 lines
	set_pattern("|%s/%s %%e %%p %%s %s/res.%%p", helper_dir, HELPER, cwd);

	len = SAFE_READLINK("/proc/self/exe", helper_dir, sizeof(helper_dir) - 1);

Could the pipe case require the initial mount namespace, or otherwise use paths visible there? The kernel resolves and runs a core_pattern pipe handler in the initial mount namespace. If LTP runs in another mount namespace, these helper and result paths may not exist there, producing a spurious TFAIL.

Quoted 8 lines

/*
* Core dump collector for the piped core_pattern tested by coredump01. *
* Avoiding the LTP API here is correct, since the kernel spawns the helper
* through ``call_usermodehelper()`` without the LTP IPC environment. */

int main(int argc, char *argv[])

Could this helper follow the LTP helper-binary convention by defining TST_NO_DEFAULT_MAIN and including tst_test.h? The missing IPC environment means it should avoid IPC-backed result calls, but does not require avoiding the helper API form itself.

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
#2 lore raw
Quoted 6 lines
Quoted 6 lines
	ssize_t rval, i;
	int fd, elf;

	if (bytes >= 4 && !memcmp(magic, "\177ELF", 4))
		elf = 1;
Quoted 6 lines
Quoted 2 lines
	dprintf(fd, "exe=%s pid=%s sig=%s bytes=%lld elf=%d\n",
		argv[1], argv[2], argv[3], bytes, elf);

Could elf be initialized to zero? For short or non-ELF input the condition does not assign it, so dprintf() reads an indeterminate value. A nonzero value can make the test accept a malformed core stream as ELF.

This can be fixed.

Quoted 7 lines
Quoted 2 lines
	SAFE_PRCTL(PR_GET_DUMPABLE, 1, 0, 0, 0);

Should this use PR_SET_DUMPABLE? PR_GET_DUMPABLE only returns the current state and ignores arg2, so this call does not ensure that abort() can produce a core dump.

Quoted 8 lines
Quoted 3 lines
	/* the kernel spawns the helper asynchronously */
	if (TST_RETRY_FN_EXP_BACKOFF(access(res, F_OK), TST_RETVAL_EQ0, HELPER_TIMEOUT)) {
		tst_res(TFAIL, "%s did not report any core dump", HELPER);

Could kernels with CONFIG_STATIC_USERMODEHELPER be rejected with TCONF before this check? In particular, an empty CONFIG_STATIC_USERMODEHELPER_PATH intentionally disables the helper, so this timeout reports TFAIL without testing specifier expansion.

This can be added in needs_kconfig.

Quoted 18 lines
Quoted 4 lines
	set_pattern("|%s/%s %%e %%p %%s %s/res.%%p", helper_dir, HELPER, cwd);

	len = SAFE_READLINK("/proc/self/exe", helper_dir, sizeof(helper_dir) - 1);

Could the pipe case require the initial mount namespace, or otherwise use paths visible there? The kernel resolves and runs a core_pattern pipe handler in the initial mount namespace. If LTP runs in another mount namespace, these helper and result paths may not exist there, producing a spurious TFAIL.

Quoted 7 lines

/*
* Core dump collector for the piped core_pattern tested by coredump01. *
* Avoiding the LTP API here is correct, since the kernel spawns the helper
* through ``call_usermodehelper()`` without the LTP IPC environment. */

Quoted 6 lines
Quoted 1 line

int main(int argc, char *argv[])

Could this helper follow the LTP helper-binary convention by defining TST_NO_DEFAULT_MAIN and including tst_test.h? The missing IPC environment means it should avoid IPC-backed result calls, but does not require avoiding the helper API form itself.

It doesn't make any sense. We can skip this one.

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

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