csky: Fix a4/a5 restoration in syscall trace path
PATCH 1/1 csky: Fix a4/a5 restoration in syscall trace path
From: hlsong89 <[email protected]>
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 using the correct pt_regs offsets after adjusting sp.
Tested on: ck860f, linux-4.19.15, C-SKY abiv2
--- arch/csky/kernel/entry.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/csky/kernel/entry.S +2 -2
@@ -94,9 +94,9 @@ csky_syscall_trace: ldw a3, (sp, LSAVE_A3) #if defined(__CSKYABIV2__) subi sp, 8 - ldw r9, (sp, LSAVE_A4) + ldw r9, (sp, LSAVE_A4 + 8) stw r9, (sp, 0x0) - ldw r9, (sp, LSAVE_A5) + ldw r9, (sp, LSAVE_A5 + 8) stw r9, (sp, 0x4) jsr syscallid /* Do system call */ addi sp, 8
Signature · 1 line
2.25.1
Guo Ren
maintainerQuoted 46 lines · hlsong
From: hlsong89 <[email protected]>
The syscall trace path reloads syscall arguments from
pt_regsbefore 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_A4andLSAVE_A5. Since those offsets are relative to the originalpt_regsbase, 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 smallPTRACE_SYSCALLreproducer 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 using the correct
pt_regsoffsets after adjusting sp.Tested on: ck860f, linux-4.19.15, C-SKY abiv2
Signed-off-by hlsong89 <[email protected]>--- arch/csky/kernel/entry.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/csky/kernel/entry.S +2
-3@@ -94,9 +94,9 @@ csky_syscall_trace: ldw a3, (sp, LSAVE_A3) #if defined(__CSKYABIV2__) subi sp, 8 - ldw r9, (sp, LSAVE_A4) + ldw r9, (sp, LSAVE_A4 + 8) stw r9, (sp, 0x0) - ldw r9, (sp, LSAVE_A5) + ldw r9, (sp, LSAVE_A5 + 8) stw r9, (sp, 0x4) jsr syscallid /* Do system call */ addi sp, 8 --
Quoted 2 lines
2.25.1
Thx for the fixup, but "LSAVE_A4 + 8" is really confusing for read. How about:
arch/csky/kernel/entry.S +3 -3
@@ -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
Signature · 2 lines
Best Regards Guo Ren
PATCH v2 1/1 csky: Fix a4/a5 restoration in syscall trace path
From: hlsong89 <[email protected]>
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
---
Changes in v2:
- Use Guo Ren's suggested approach to handle the ABIv2 stack arguments.
- Tested with the ptrace+mmap reproducer.
arch/csky/kernel/entry.S | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/csky/kernel/entry.S +3 -3
@@ -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
base-commit: 5200f5f493f79f14bbdc349e402a40dfb32f23c8
Signature · 1 line
2.25.1
Quoted 54 lines · hlsong
From: hlsong89 <[email protected]>
The syscall trace path reloads syscall arguments from
pt_regsbefore 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_A4andLSAVE_A5. Since those offsets are relative to the originalpt_regsbase, 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 smallPTRACE_SYSCALLreproducer 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_regsbefore changing sp.Tested on: ck860f, linux-4.19.15, C-SKY abiv2
Suggested-by Guo Ren <[email protected]>Signed-off-by hlsong89 <[email protected]>---
Changes in v2:
- Use Guo Ren's suggested approach to handle the ABIv2 stack arguments.
- Tested with the ptrace+mmap reproducer.arch/csky/kernel/entry.S | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/csky/kernel/entry.S +3
-3@@ -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
Quoted 4 lines
base-commit:
5200f5f493f79f14bbdc349e402a40dfb32f23c8--
2.25.1
Applied, thx.
Signature · 2 lines
Best Regards Guo Ren
Hi Guo,
Sorry for the noise. I noticed that the patch was submitted with my short handle as the author / Signed-off-by name.
If it is still possible, could you please update it from:
hlsong <[email protected]>
to:
Hanlin Song <[email protected]>
Thanks,
Hanlin
Quoted 65 lines · Guo Ren <[email protected]> 于2026年5月21日周四 23:45写道:
Quoted 54 lines · hlsong
From: hlsong89 <[email protected]>
The syscall trace path reloads syscall arguments from
pt_regsbefore 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_A4andLSAVE_A5. Since those offsets are relative to the originalpt_regsbase, 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 smallPTRACE_SYSCALLreproducer 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_regsbefore changing sp.Tested on: ck860f, linux-4.19.15, C-SKY abiv2
Suggested-by Guo Ren <[email protected]>Signed-off-by hlsong89 <[email protected]>---
Changes in v2:
- Use Guo Ren's suggested approach to handle the ABIv2 stack arguments.
- Tested with the ptrace+mmap reproducer.arch/csky/kernel/entry.S | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/csky/kernel/entry.S +3
-3@@ -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 #elseQuoted 4 lines
base-commit:
5200f5f493f79f14bbdc349e402a40dfb32f23c8--
2.25.1Applied, thx.
--
Best Regards
Guo Ren
A message that is not in the archive (sent off-list or not yet received): CABvmTk2+kd9n7xwSK=nnDBK4nC62sS7Du-MVeY17XV-p9pRufQ@mail.gmail.com
Guo Ren
maintainerPlease resend this patch, thx.
Quoted 83 lines · George Patton
Hi Guo,
Sorry for the noise. I noticed that the patch was submitted with my short handle as the author / Signed-off-by name.
If it is still possible, could you please update it from:
hlsong <[email protected]>
to:
Hanlin Song <[email protected]>
Thanks,
HanlinQuoted 65 lines · Guo Ren <[email protected]> 于2026年5月21日周四 23:45写道:
Quoted 54 lines · hlsong
From: hlsong89 <[email protected]>
The syscall trace path reloads syscall arguments from
pt_regsbefore 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_A4andLSAVE_A5. Since those offsets are relative to the originalpt_regsbase, 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 smallPTRACE_SYSCALLreproducer 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_regsbefore changing sp.Tested on: ck860f, linux-4.19.15, C-SKY abiv2
Suggested-by Guo Ren <[email protected]>Signed-off-by hlsong89 <[email protected]>---
Changes in v2:
- Use Guo Ren's suggested approach to handle the ABIv2 stack arguments.
- Tested with the ptrace+mmap reproducer.arch/csky/kernel/entry.S | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/csky/kernel/entry.S +3
-3@@ -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 #elseQuoted 4 lines
base-commit:
5200f5f493f79f14bbdc349e402a40dfb32f23c8--
2.25.1Applied, thx.
--
Best Regards
Guo Ren
Signature · 2 lines
Best Regards Guo Ren
PATCH v3 1/1 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
---
Changes in v3:
- Use full real name for the author and Signed-off-by.
Changes in v2:
- Use Guo Ren's suggested approach to handle the ABIv2 stack arguments.
- Tested with the ptrace+mmap reproducer.
arch/csky/kernel/entry.S | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/csky/kernel/entry.S +3 -3
@@ -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
base-commit: 5200f5f493f79f14bbdc349e402a40dfb32f23c8
Signature · 1 line
2.25.1
Hi Guo,
Sorry to bother you.
Just following up on this v3. This resend only updates the author and Signed-off-by name as requested; the code is unchanged from v2.
Could you please let me know whether it is still queued, or if I should do anything else?
Thanks,
Hanlin
Applied:
https://github.com/c-sky/csky-linux/commit/fe69c03143c2720f89659c9727e4f472b9cf24a0
Quoted 13 lines · Hanlin Song
Hi Guo,
Sorry to bother you.
Just following up on this v3. This resend only updates the author and Signed-off-by name as requested; the code is unchanged from v2.
Could you please let me know whether it is still queued, or if I should do anything else?
Thanks,
Hanlin
Signature · 2 lines
Best Regards Guo Ren