Re: [PATCH 4/9] ARM: syscall: always store thread_info->syscall

From: Russell King - ARM Linux admin
Date: Fri Oct 30 2020 - 12:53:47 EST


On Fri, Oct 30, 2020 at 04:49:14PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@xxxxxxxx>
>
> The system call number is used in a a couple of places, in particular
> ptrace, seccomp and /proc/<pid>/syscall.
>
> The last one apparently never worked reliably on ARM for tasks
> that are not currently getting traced.
>
> Storing the syscall number in the normal entry path makes it work,
> as well as allowing us to see if the current system call is for
> OABI compat mode, which is the next thing I want to hook into.

I'm not sure this patch is correct.

Tracing the existing code for OABI:

asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
{
current_thread_info()->syscall = scno;

/* Legacy ABI only. */
USER( ldr scno, [saved_pc, #-4] ) @ get SWI instruction
bic scno, scno, #0xff000000 @ mask off SWI op-code
eor scno, scno, #__NR_SYSCALL_BASE @ check OS number
tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls?
bne __sys_trace

__sys_trace:
mov r1, scno
add r0, sp, #S_OFF
bl syscall_trace_enter

So, thread_info->syscall does not include __NR_SYSCALL_BASE. The
reason for this is the code that makes use of that via syscall_get_nr().
kernel/trace/trace_syscalls.c:

syscall_nr = trace_get_syscall_nr(current, regs);
if (syscall_nr < 0 || syscall_nr >= NR_syscalls)
return;

and NR_syscalls is the number of syscalls, which doesn't include the
__NR_SYSCALL_BASE offset.

So, I think this patch actually breaks OABI.

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!