From: Hengqi Chen <hengqi.chen@gmail.com>
To: loongarch@lists.linux.dev
Cc: chenhuacai@kernel.org, kernel@xen0n.name, hengqi.chen@gmail.com
Subject: [PATCH] LoongArch: Preserve syscall nr across execve
Date: Mon, 4 Dec 2023 05:37:45 +0000 [thread overview]
Message-ID: <20231204053745.3153-1-hengqi.chen@gmail.com> (raw)
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_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.
Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
---
arch/loongarch/include/asm/elf.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/loongarch/include/asm/elf.h b/arch/loongarch/include/asm/elf.h
index b9a4ab54285c..fb9261164a34 100644
--- a/arch/loongarch/include/asm/elf.h
+++ b/arch/loongarch/include/asm/elf.h
@@ -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
next reply other threads:[~2023-12-04 5:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-04 5:37 Hengqi Chen [this message]
2023-12-04 7:41 ` [PATCH] LoongArch: Preserve syscall nr across execve Huacai Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231204053745.3153-1-hengqi.chen@gmail.com \
--to=hengqi.chen@gmail.com \
--cc=chenhuacai@kernel.org \
--cc=kernel@xen0n.name \
--cc=loongarch@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).