binfmt_elf: preserve original ELF e_flags for core dumps
authorSvetlana Parfenova <svetlana.parfenova@syntacore.com>
Mon, 1 Sep 2025 13:53:50 +0000 (20:53 +0700)
committerKees Cook <kees@kernel.org>
Thu, 4 Sep 2025 03:49:32 +0000 (20:49 -0700)
commit8c94db0ae97c72c253a615f990bd466b456e94f6
tree6314c271d881ad51b48e1169de596a74bd9d64e1
parenta728ce8ffbd27954fdb2826dcc15a6576e574b83
binfmt_elf: preserve original ELF e_flags for core dumps

Some architectures, such as RISC-V, use the ELF e_flags field to encode
ABI-specific information (e.g., ISA extensions, fpu support). Debuggers
like GDB rely on these flags in core dumps to correctly interpret
optional register sets. If the flags are missing or incorrect, GDB may
warn and ignore valid data, for example:

    warning: Unexpected size of section '.reg2/213' in core file.

This can prevent access to fpu or other architecture-specific registers
even when they were dumped.

Save the e_flags field during ELF binary loading (in load_elf_binary())
into the mm_struct, and later retrieve it during core dump generation
(in fill_note_info()). Kconfig option CONFIG_ARCH_HAS_ELF_CORE_EFLAGS
is introduced for architectures that require this behaviour.

Signed-off-by: Svetlana Parfenova <svetlana.parfenova@syntacore.com>
Link: https://lore.kernel.org/r/20250901135350.619485-1-svetlana.parfenova@syntacore.com
Signed-off-by: Kees Cook <kees@kernel.org>
arch/riscv/Kconfig
fs/Kconfig.binfmt
fs/binfmt_elf.c
include/linux/mm_types.h