coredump testing suite
v10 cover coredump testing suite
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.
Add a coredump02 test that verifies ELF data after a coredump.
---
Changes in v10:
- add kernel-doc documentation for SAFE_FILE_VPRINTF()
- fix checkpatch formatting warnings in SAFE_FILE_VPRINTF() headers
- use TST_EXP_EQ_STR() to compare executable name in coredump02
- Link to v9: https://lore.kernel.org/[email protected]
Changes in v9:
- add SAFE_FILE_VPRINTF() helper in the test library
- factor out shared test logic into coredump_common.h
- use SAFE_FILE_VPRINTF() in set_pattern() to avoid intermediate buffers
- use struct tcase array for test case dispatch in coredump01
- return early in coredump01 if core file is missing before parsing ELF
- document root requirement in coredump02 description
- assert exactly one PT_NOTE segment in coredump02
- validate file bounds for PT_LOAD segments in coredump02
- use TST_EXP_EQ_STRN() to compare executable name in coredump02
- copy unaligned note descriptors to local stack structs to ensure 8-byte alignment
- Link to v8: https://lore.kernel.org/[email protected]
Changes in v8:
- check PT_LOAD data
- Link to v7: https://lore.kernel.org/[email protected]
Changes in v7:
- define a common header for the testing suite
- update commit message for coredump02
- Link to v6: https://lore.kernel.org/[email protected]
Changes in v6:
- coredump01 check Elf
- add coredump02 test for Elf validation
- Link to v5: https://lore.kernel.org/[email protected]
Changes in v5:
- resolve path from root for helper
- Link to v4: https://lore.kernel.org/[email protected]
Changes in v4:
- read back core_pattern after writing and abort with TBROK on mismatch
- read CONFIG_STATIC_USERMODEHELPER once in setup() and cache the result
- remove namespace visibility scaffolding and skip logic from verify_pipe_pattern()
- resolve helper path with tst_get_path() instead of /proc/self/exe readlink
- Link to v3: https://lore.kernel.org/[email protected]
Changes in v3:
- check for CONFIG_COREDUMP=y
- Link to v2: https://lore.kernel.org/[email protected]
Changes in v2:
- fix CI agent spotted errors
- Link to v1: https://lore.kernel.org/[email protected]
To: Linux Test Project <[email protected]>
---
Andrea Cervesato (3):
lib: Add SAFE_FILE_VPRINTF()
coredump01: New core_pattern specifiers test
coredump02: Verify ELF structure and notes
include/safe_file_ops_fn.h | 6 + include/tst_safe_file_ops.h | 14 ++ lib/safe_file_ops.c | 2 +- runtest/kernel_misc | 2 + testcases/kernel/Makefile | 1 + testcases/kernel/coredump/.gitignore | 3 + testcases/kernel/coredump/Makefile | 7 + testcases/kernel/coredump/coredump01.c | 162 +++++++++++++++++++++ testcases/kernel/coredump/coredump01_helper.c | 73 ++++++++++ testcases/kernel/coredump/coredump02.c | 196 ++++++++++++++++++++++++++ testcases/kernel/coredump/coredump_common.h | 52 +++++++ 11 files changed, 517 insertions(+), 1 deletion(-)
---
base-commit: 043bdc49af410f55ece6f61abcdaba7d9580f86a
change-id: 20260820-coredump-22fc731bde08
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v10 1/3 lib: Add SAFE_FILE_VPRINTF()
From: Andrea Cervesato <[email protected]>
Expose safe_file_vprintf() as SAFE_FILE_VPRINTF() macro to allow formatting directly into files with a va_list without requiring an intermediate buffer.
--- include/safe_file_ops_fn.h | 6 ++++++ include/tst_safe_file_ops.h | 14 ++++++++++++++ lib/safe_file_ops.c | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-)
include/safe_file_ops_fn.h +6 -0
@@ -20,6 +20,7 @@#include <sys/stat.h> #include <time.h> +#include <stdarg.h> #include "lapi/utime.h"
@@ -62,6 +63,11 @@ void safe_file_printf(const char *file, const int lineno, const char *path, const char *fmt, ...) __attribute__ ((format (printf, 5, 6))); +void safe_file_vprintf (const char *file,const int lineno, +void (*cleanup_fn)(void ), +const char *path,const char *fmt,va_list va) + __attribute__ ((format (printf,5 ,0 ))); +void safe_try_file_printf (const char *file,const int lineno,void (*cleanup_fn)(void ),const char *path,const char *fmt, ...) __attribute__ ((format (printf,5 ,6 )));
include/tst_safe_file_ops.h +14 -0
@@ -65,6 +65,20 @@ void safe_file_read_str(const char *file, const int lineno,safe_file_printf (__FILE__, __LINE__,NULL , \ (path), (fmt), ## __VA_ARGS__) +/** +* SAFE_FILE_VPRINTF() - Formats and writes a va_list argument into a file. +* +* Writes formatted output to the file at @path using the format string @fmt +* and variable arguments @va. Aborts the test with TBROK on failure. +* +* @path: A path to a file. +* @fmt: A printf format string. +* @va: A variable argument list. + */ +#define SAFE_FILE_VPRINTF (path, fmt, va) \ + safe_file_vprintf(__FILE__, __LINE__, NULL, \ + (path), (fmt), (va)) +/* Same as SAFE_FILE_PRINTF() but returns quietly if the path doesn't exist */ #define SAFE_TRY_FILE_PRINTF (path, fmt, ...) \ safe_try_file_printf(__FILE__, __LINE__, NULL, \
lib/safe_file_ops.c +1 -1
@@ -280,7 +280,7 @@ err:return 1 ; } -static void safe_file_vprintf (const char *file,const int lineno, +void safe_file_vprintf (const char *file,const int lineno,void (*cleanup_fn)(void ),const char *path,const char *fmt,va_list va) {
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] lib: Add SAFE_FILE_VPRINTF()
Hi Andrea,
Quoted 1 line · Andrea Cervesato
lib: Add
SAFE_FILE_VPRINTF()
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
PATCH v10 2/3 coredump01: New core_pattern specifiers test
In reply to Andrea CervesatoFrom: 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.
--- runtest/kernel_misc | 1 + testcases/kernel/Makefile | 1 + testcases/kernel/coredump/.gitignore | 2 + testcases/kernel/coredump/Makefile | 7 ++ testcases/kernel/coredump/coredump01.c | 162 ++++++++++++++++++++++++++ testcases/kernel/coredump/coredump01_helper.c | 73 ++++++++++++ testcases/kernel/coredump/coredump_common.h | 52 +++++++++ 7 files changed, 298 insertions(+)
runtest/kernel_misc +1 -0
@@ -17,3 +17,4 @@ zram02 zram02.sh zram03 zram03 umip_basic_test umip_basic_test aslr01 aslr01 +coredump01 coredump01
testcases/kernel/Makefile +1 -0
@@ -19,6 +19,7 @@ SUBDIRS += lib SUBDIRS += connectors \ containers \ controllers \ + coredump \ crypto \ device-drivers \ firmware \
testcases/kernel/coredump/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +/coredump01 +/coredump01_helper
testcases/kernel/coredump/Makefile new file +7 -0
@@ -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 +162 -0
162 lines not on this page · raw message
testcases/kernel/coredump/coredump01_helper.c new file +73 -0
73 lines not on this page · raw message
testcases/kernel/coredump/coredump_common.h new file +52 -0
52 lines not on this page · raw message
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v10 3/3 coredump02: Verify ELF structure and notes
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
LTP currently only tests core_pattern specifier expansion and basic ELF magic in coredump01, leaving the internal ELF structure and notes generated by the kernel unverified.
Add a test to verify that the kernel produces a valid ET_CORE ELF file with the expected PT_NOTE and PT_LOAD segments, and that the NT_PRPSINFO and NT_PRSTATUS notes contain the expected process name, PID, and terminating signal.
Root is required to set the system-wide core_pattern into the test's temporary directory.
--- runtest/kernel_misc | 1 + testcases/kernel/coredump/.gitignore | 1 + testcases/kernel/coredump/coredump02.c | 196 +++++++++++++++++++++++++++++++++ 3 files changed, 198 insertions(+)
runtest/kernel_misc +1 -0
@@ -18,3 +18,4 @@ zram03 zram03 umip_basic_test umip_basic_test aslr01 aslr01 coredump01 coredump01 +coredump02 coredump02
testcases/kernel/coredump/.gitignore +1 -0
@@ -1,2 +1,3 @@ /coredump01 /coredump01_helper +/coredump02
testcases/kernel/coredump/coredump02.c new file +196 -0
196 lines not on this page · raw message
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v10 3/3] coredump02: Verify ELF structure and notes
Hi!
testcases/kernel/coredump/coredump02.c line 92
Quoted 7 lines
testcases/kernel/coredump/coredump02.c new file +7
-0+static void handle_note (uint32_t type,const void *desc,size_t descsz,pid_t pid) +{ +if (type ==NT_PRPSINFO && descsz >=sizeof (struct elf_prpsinfo )) { +struct elf_prpsinfo info; + +memcpy (&info, desc,sizeof (info)); +TST_EXP_EQ_STR (info.pr_fname,"coredump02" );
I still do not see a reason why this can't be:
struct elf_prpsinfo *info = desc; TST_EXP_EQ_STR(info->pr_name, "coredump02");
testcases/kernel/coredump/coredump02.c line 101
Quoted 8 lines
testcases/kernel/coredump/coredump02.c new file +8
-0+ prpsinfo_seen =1 ; + }else if (type ==NT_PRSTATUS && descsz >=sizeof (struct elf_prstatus )) { +struct elf_prstatus st; + +memcpy (&st, desc,sizeof (st)); + +TST_EXP_EQ_LI (st.pr_pid, pid); +TST_EXP_EQ_LI (st.pr_cursig,SIGABRT );
And here as well.
Otherwise:
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v10 3/3] coredump02: Verify ELF structure and notes
Hi Cyril,
Quoted 11 lines
Hi!
testcases/kernel/coredump/coredump02.c line 92
Quoted 7 lines
testcases/kernel/coredump/coredump02.c new file +7
-0+static void handle_note (uint32_t type,const void *desc,size_t descsz,pid_t pid) +{ +if (type ==NT_PRPSINFO && descsz >=sizeof (struct elf_prpsinfo )) { +struct elf_prpsinfo info; + +memcpy (&info, desc,sizeof (info)); +TST_EXP_EQ_STR (info.pr_fname,"coredump02" );I still do not see a reason why this can't be:
Quoted 3 lines
struct elf_prpsinfo *info = desc; TST_EXP_EQ_STR(info->pr_name, "coredump02");
because ELF notes in Linux are only 4-byte padded, desc pointers are not guaranteed to be 8-byte aligned. Casting desc to struct elf_prpsinfo * or struct elf_prstatus * creates a misaligned pointer, which is undefined behavior in C.
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v10 3/3] coredump02: Verify ELF structure and notes
Hi!
Quoted 10 lines
Quoted 10 lines
testcases/kernel/coredump/coredump02.c line 92
Quoted 7 lines
testcases/kernel/coredump/coredump02.c new file +7
-0+static void handle_note (uint32_t type,const void *desc,size_t descsz,pid_t pid) +{ +if (type ==NT_PRPSINFO && descsz >=sizeof (struct elf_prpsinfo )) { +struct elf_prpsinfo info; + +memcpy (&info, desc,sizeof (info)); +TST_EXP_EQ_STR (info.pr_fname,"coredump02" );I still do not see a reason why this can't be:
Quoted 8 lines
Quoted 3 lines
struct elf_prpsinfo *info = desc; TST_EXP_EQ_STR(info->pr_name, "coredump02");because ELF notes in Linux are only 4-byte padded, desc pointers are not guaranteed to be 8-byte aligned. Casting desc to struct
elf_prpsinfo* or structelf_prstatus* creates a misaligned pointer, which is undefined behavior in C.
AFAIK the 4 byte padding may happen on x86_64 only for a historical reasons and x86_64 is at the same time capable of handling unaligned access. AArch64 should have 8 byte padding.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v10 3/3] coredump02: Verify ELF structure and notes
Quoted 3 lines
AFAIK the 4 byte padding may happen on
x86_64only for a historical reasons andx86_64is at the same time capable of handling unaligned access. AArch64 should have 8 byte padding.
yes, it happens only in x86_64, but I wouldn't rely too much on unaligned access handling if it's just few bytes copy away. code is 100% stable like this.
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v10 3/3] coredump02: Verify ELF structure and notes
Hi!
Quoted 7 lines
Quoted 3 lines
AFAIK the 4 byte padding may happen on
x86_64only for a historical reasons andx86_64is at the same time capable of handling unaligned access. AArch64 should have 8 byte padding.yes, it happens only in
x86_64, but I wouldn't rely too much on unaligned access handling if it's just few bytes copy away. code is 100% stable like this.
It looks like working around potentional bugs rather than anything else. The elements should be aligned so that they could be accessed on the targed architecture.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v10 3/3] coredump02: Verify ELF structure and notes
Quoted 4 lines
It looks like working around potentional bugs rather than anything else. The elements should be aligned so that they could be accessed on the targed architecture.
ok, I will send the next version with the cast
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp