[PATCH RFC POC 07/50] csky: commit fds on syscall exit

From: Christian Brauner

Date: Tue Sep 15 2026 - 07:44:25 EST


Add TIF_FD_SLOTS and test it after the untraced system call has
stored its return value. A task that reserved descriptors joins the
traced path, where syscall_trace_exit() commits them before audit and
the ptrace exit stop.

Signed-off-by: Christian Brauner (Amutable) <brauner@xxxxxxxxxx>
---
arch/csky/include/asm/thread_info.h | 2 ++
arch/csky/kernel/entry.S | 9 +++++++++
arch/csky/kernel/ptrace.c | 4 ++++
3 files changed, 15 insertions(+)

diff --git a/arch/csky/include/asm/thread_info.h b/arch/csky/include/asm/thread_info.h
index fdd4f8ad45ac..59109ce64695 100644
--- a/arch/csky/include/asm/thread_info.h
+++ b/arch/csky/include/asm/thread_info.h
@@ -61,6 +61,7 @@ static inline struct thread_info *current_thread_info(void)
#define TIF_SYSCALL_TRACEPOINT 5 /* syscall tracepoint instrumentation */
#define TIF_SYSCALL_AUDIT 6 /* syscall auditing */
#define TIF_NOTIFY_SIGNAL 7 /* signal notifications exist */
+#define TIF_FD_SLOTS 8 /* syscall prepared descriptors */
#define TIF_POLLING_NRFLAG 16 /* poll_idle() is TIF_NEED_RESCHED */
#define TIF_MEMDIE 18 /* is terminating due to OOM killer */
#define TIF_RESTORE_SIGMASK 20 /* restore signal mask in do_signal() */
@@ -73,6 +74,7 @@ static inline struct thread_info *current_thread_info(void)
#define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
#define _TIF_NOTIFY_SIGNAL (1 << TIF_NOTIFY_SIGNAL)
+#define _TIF_FD_SLOTS (1 << TIF_FD_SLOTS)
#define _TIF_UPROBE (1 << TIF_UPROBE)
#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
#define _TIF_MEMDIE (1 << TIF_MEMDIE)
diff --git a/arch/csky/kernel/entry.S b/arch/csky/kernel/entry.S
index 3261f46f2244..6ff3074b9787 100644
--- a/arch/csky/kernel/entry.S
+++ b/arch/csky/kernel/entry.S
@@ -80,6 +80,15 @@ ENTRY(csky_systemcall)
jsr syscallid
#endif
stw a0, (sp, LSAVE_A0) /* Save return value */
+ /* descriptors reserved by the syscall are committed in syscall_trace_exit() */
+ mov r9, sp
+ bmaski r10, THREAD_SHIFT
+ andn r9, r10
+ ldw r10, (r9, TINFO_FLAGS)
+ lrw r9, _TIF_FD_SLOTS
+ and r10, r9
+ cmpnei r10, 0
+ bt 1f
jmpi ret_from_exception

csky_syscall_trace:
diff --git a/arch/csky/kernel/ptrace.c b/arch/csky/kernel/ptrace.c
index ee2867a1576e..b19fef9d396d 100644
--- a/arch/csky/kernel/ptrace.c
+++ b/arch/csky/kernel/ptrace.c
@@ -4,6 +4,7 @@
#include <linux/audit.h>
#include <linux/elf.h>
#include <linux/errno.h>
+#include <linux/file.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/ptrace.h>
@@ -335,6 +336,9 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)

asmlinkage void syscall_trace_exit(struct pt_regs *regs)
{
+ if (test_thread_flag(TIF_FD_SLOTS))
+ fd_slots_commit(regs);
+
audit_syscall_exit(regs);

if (test_thread_flag(TIF_SYSCALL_TRACE))

--
2.53.0