[strace/strace] [RFC] Add 64-bit LoongArch support (PR #205)

Huacai Chen notifications at github.com
Sat Jan 8 07:40:49 UTC 2022


> > The problematic piece of kernel code is
> > ```
> >         if ((nr == -1UL) && (onr != -1UL))
> >                 goto out; /* Don't set -ENOSYS for SECCOMP */
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > Here the `Don't set -ENOSYS for SECCOMP` is the culprit: when the syscall is cancelled by ptrace/seccomp, the return value must be set properly to -ENOSYS.
> 
> This piece of code is correct for SECCOMP because the latter calls `syscall_set_return_value` itself.
> 
> Unfortunately, this approach is not applicable for ptrace: ptracer cannot set syscall return value on entering syscall because the register used for the return value is often used for other purposes. For example, on x86 it's also used for the syscall nr, and on loongarch it's also used for the first syscall argument.
> 
> I'm afraid `syscall_enter_from_user_mode` needs to be changed before it could be used on loongarch. Besides loongarch, the only architecture where `syscall_enter_from_user_mode` is used is x86 where `rax` is initialized to `-ENOSYS` before `syscall_enter_from_user_mode` is invoked.

Hi, could you please change do_syscall() to be like this and test ptrace/strace (I have tested seccomp)?
void noinstr do_syscall(struct pt_regs *regs)
{
        unsigned long nr;
        sys_call_fn syscall_fn;

        nr = regs->regs[11];

        /* Set for syscall restarting */
        if (nr < NR_syscalls)
                regs->regs[0] = nr + 1;

        regs->csr_era += 4;
        regs->orig_a0 = regs->regs[4];
        regs->regs[4] = -ENOSYS;
        nr = syscall_enter_from_user_mode(regs, nr);

        if (nr < NR_syscalls) {
                syscall_fn = sys_call_table[nr];
                regs->regs[4] = syscall_fn(regs->orig_a0, regs->regs[5], regs->regs[6],
                                           regs->regs[7], regs->regs[8], regs->regs[9]);
        }

        syscall_exit_to_user_mode(regs);
}




-- 
Reply to this email directly or view it on GitHub:
https://github.com/strace/strace/pull/205#issuecomment-1007902930
You are receiving this because you are subscribed to this thread.

Message ID: <strace/strace/pull/205/c1007902930 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20220107/06a665eb/attachment.htm>


More information about the Strace-devel mailing list