Linux C-SKY architecture development
 help / color / mirror / Atom feed
* [PATCH] csky: Fix a4/a5 restoration in syscall trace path
@ 2026-05-21  9:59 hlsong
  2026-05-21 10:15 ` Guo Ren
  0 siblings, 1 reply; 9+ messages in thread
From: hlsong @ 2026-05-21  9:59 UTC (permalink / raw)
  To: Guo Ren; +Cc: linux-csky, linux-kernel, hlsong89

From: hlsong89 <pgeorge8929@gmail.com>

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

Signed-off-by: hlsong89 <pgeorge8929@gmail.com>
---
 arch/csky/kernel/entry.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/csky/kernel/entry.S b/arch/csky/kernel/entry.S
index c68cdcc76..98692fc78 100644
--- a/arch/csky/kernel/entry.S
+++ b/arch/csky/kernel/entry.S
@@ -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
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-06-04 11:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-21  9:59 [PATCH] csky: Fix a4/a5 restoration in syscall trace path hlsong
2026-05-21 10:15 ` Guo Ren
2026-05-21 11:33   ` [PATCH v2] " hlsong
2026-05-21 15:44     ` Guo Ren
2026-05-21 10:29       ` Hanlin Song
     [not found]       ` <CABvmTk2+kd9n7xwSK=nnDBK4nC62sS7Du-MVeY17XV-p9pRufQ@mail.gmail.com>
2026-05-22  0:53         ` Guo Ren
2026-05-22  3:18           ` [PATCH v3] " Hanlin Song
2026-06-04  3:59             ` Hanlin Song
2026-06-04 11:44               ` Guo Ren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox