LoongArch: Preserve syscall nr across execve
Subsystems (2)
PATCH 1/1 LoongArch: Preserve syscall nr across execve
Currently, we store syscall nr in pt_regs::regs[11] and syscall execve accidentally overrides it during its execution:
sys_execve
-> do_execve
-> do_execveat_common
-> bprm_execve
-> exec_binprm
-> search_binary_handler
-> load_elf_binary
-> ELF_PLAT_INITELF_PLAT_INIT reset regs[11] to 0, later in syscall_exit_to_user_mode we get a wrong syscall nr. This breaks tool like execsnoop since it relies on execve tracepoints.
Skip pt_regs::regs[11] reset in ELF_PLAT_INIT to fix the issue.
--- arch/loongarch/include/asm/elf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/loongarch/include/asm/elf.h +1 -1
@@ -293,7 +293,7 @@ extern const char *__elf_platform;#define ELF_PLAT_INIT (_r, load_addr) do { \ _r->regs[1] = _r->regs[2] = _r->regs[3] = _r->regs[4] = 0; \ _r->regs[5] = _r->regs[6] = _r->regs[7] = _r->regs[8] = 0; \ - _r->regs[9] = _r->regs[10] = _r->regs[11] = _r->regs[12] = 0; \ + _r->regs[9] = _r->regs[10] =/* syscall nr */ _r->regs[12 ] =0 ; \ _r->regs[13 ] = _r->regs[14 ] = _r->regs[15 ] = _r->regs[16 ] =0 ; \ _r->regs[17 ] = _r->regs[18 ] = _r->regs[19 ] = _r->regs[20 ] =0 ; \ _r->regs[21 ] = _r->regs[22 ] = _r->regs[23 ] = _r->regs[24 ] =0 ; \
Signature · 1 line
2.27.0
Queued for loongarch-fixes, thanks.
Huacai
Quoted 40 lines · Hengqi Chen
Currently, we store syscall nr in pt_regs::regs[11] and syscall execve accidentally overrides it during its execution:
sys_execve -> do_execve -> do_execveat_common -> bprm_execve -> exec_binprm -> search_binary_handler -> load_elf_binary -> ELF_PLAT_INIT
ELF_PLAT_INITreset regs[11] to 0, later insyscall_exit_to_user_modewe get a wrong syscall nr. This breaks tool like execsnoop since it relies on execve tracepoints.Skip pt_regs::regs[11] reset in
ELF_PLAT_INITto fix the issue.Signed-off-by Hengqi Chen <[email protected]>--- arch/loongarch/include/asm/elf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/loongarch/include/asm/elf.h +1
-2@@ -293,7 +293,7 @@ extern const char *__elf_platform;#define ELF_PLAT_INIT (_r, load_addr) do { \ _r->regs[1] = _r->regs[2] = _r->regs[3] = _r->regs[4] = 0; \ _r->regs[5] = _r->regs[6] = _r->regs[7] = _r->regs[8] = 0; \ - _r->regs[9] = _r->regs[10] = _r->regs[11] = _r->regs[12] = 0; \ + _r->regs[9] = _r->regs[10] =/* syscall nr */ _r->regs[12 ] =0 ; \ _r->regs[13 ] = _r->regs[14 ] = _r->regs[15 ] = _r->regs[16 ] =0 ; \ _r->regs[17 ] = _r->regs[18 ] = _r->regs[19 ] = _r->regs[20 ] =0 ; \ _r->regs[21 ] = _r->regs[22 ] = _r->regs[23 ] = _r->regs[24 ] =0 ; \ --2.27.0