summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanlin Song <pgeorge8929@gmail.com>2026-05-22 11:18:24 +0800
committerGuo Ren (Alibaba DAMO Academy) <guoren@kernel.org>2026-07-02 17:26:58 -0400
commitabb81e5ce7d995baa41556b8125fa59e28ba3be8 (patch)
tree52067e2784cfeb624ff035fa2848bbcad90c43c0
parentdc59e4fea9d83f03bad6bddf3fa2e52491777482 (diff)
downloadlinux-next-abb81e5ce7d995baa41556b8125fa59e28ba3be8.tar.gz
linux-next-abb81e5ce7d995baa41556b8125fa59e28ba3be8.zip
csky: Fix a4/a5 restoration in syscall trace path
The syscall trace path reloads syscall arguments from pt_regs before calling the syscall handler. On C-SKY ABIv2, the 5th and 6th syscall arguments are prepared as stack arguments before invoking syscallid. The current code adjusts sp before loading LSAVE_A4 and LSAVE_A5. Since those offsets are relative to the original pt_regs base, loading them after changing sp fetches the wrong slots. As a result, traced syscalls that use the 5th or 6th argument may receive corrupted arguments. This is visible with mmap2(), which takes six arguments. A small PTRACE_SYSCALL reproducer opens a file and maps one page with: mmap(NULL, 4096, PROT_READ | PROT_EXEC, MAP_PRIVATE, fd, 0) Before the fix, the traced child fails the mmap and exits with 12. After the fix, the mapping succeeds and the child exits with 0. Fix the trace path by loading a4/a5 from pt_regs before changing sp. Tested on: ck860f, linux-4.19.15, C-SKY abiv2 Fixes: e0bbb53843b5 ("csky: Fixup abiv2 syscall_trace break a4 & a5") Suggested-by: Guo Ren <guoren@kernel.org> Signed-off-by: Hanlin Song <pgeorge8929@gmail.com> Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
-rw-r--r--arch/csky/kernel/entry.S6
1 files changed, 3 insertions, 3 deletions
diff --git a/arch/csky/kernel/entry.S b/arch/csky/kernel/entry.S
index c68cdcc76d60..3261f46f2244 100644
--- a/arch/csky/kernel/entry.S
+++ b/arch/csky/kernel/entry.S
@@ -93,11 +93,11 @@ csky_syscall_trace:
ldw a2, (sp, LSAVE_A2)
ldw a3, (sp, LSAVE_A3)
#if defined(__CSKYABIV2__)
- subi sp, 8
ldw r9, (sp, LSAVE_A4)
+ ldw r10, (sp, LSAVE_A5)
+ subi sp, 8
stw r9, (sp, 0x0)
- ldw r9, (sp, LSAVE_A5)
- stw r9, (sp, 0x4)
+ stw r10, (sp, 0x4)
jsr syscallid /* Do system call */
addi sp, 8
#else