Skip to content

Commit 139dbe5

Browse files
committed
arm64: syscall: Expand the comment about ptrace and syscall(-1)
If a task executes syscall(-1), we intercept this early and force x0 to be -ENOSYS so that we don't need to distinguish this scenario from one where the scno is -1 because a tracer wants to skip the system call using ptrace. With the return value set, the return path is the same as the skip case. Although there is a one-line comment noting this in el0_svc_common(), it misses out most of the detail. Expand the comment to describe a bit more about what is going on. Cc: Mark Rutland <[email protected]> Cc: Keno Fischer <[email protected]> Cc: Luis Machado <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent 59ee987 commit 139dbe5

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

arch/arm64/kernel/syscall.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,21 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr,
124124
user_exit();
125125

126126
if (has_syscall_work(flags)) {
127-
/* set default errno for user-issued syscall(-1) */
127+
/*
128+
* The de-facto standard way to skip a system call using ptrace
129+
* is to set the system call to -1 (NO_SYSCALL) and set x0 to a
130+
* suitable error code for consumption by userspace. However,
131+
* this cannot be distinguished from a user-issued syscall(-1)
132+
* and so we must set x0 to -ENOSYS here in case the tracer doesn't
133+
* issue the skip and we fall into trace_exit with x0 preserved.
134+
*
135+
* This is slightly odd because it also means that if a tracer
136+
* sets the system call number to -1 but does not initialise x0,
137+
* then x0 will be preserved for all system calls apart from a
138+
* user-issued syscall(-1). However, requesting a skip and not
139+
* setting the return value is unlikely to do anything sensible
140+
* anyway.
141+
*/
128142
if (scno == NO_SYSCALL)
129143
regs->regs[0] = -ENOSYS;
130144
scno = syscall_trace_enter(regs);

0 commit comments

Comments
 (0)