<p></p>
<blockquote>
<blockquote>
<p dir="auto">The problematic piece of kernel code is</p>
<pre><code>        if ((nr == -1UL) && (onr != -1UL))
                goto out; /* Don't set -ENOSYS for SECCOMP */
</code></pre>
<p dir="auto">Here the <code>Don't set -ENOSYS for SECCOMP</code> is the culprit: when the syscall is cancelled by ptrace/seccomp, the return value must be set properly to -ENOSYS.</p>
</blockquote>
<p dir="auto">This piece of code is correct for SECCOMP because the latter calls <code>syscall_set_return_value</code> itself.</p>
<p dir="auto">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.</p>
<p dir="auto">I'm afraid <code>syscall_enter_from_user_mode</code> needs to be changed before it could be used on loongarch. Besides loongarch, the only architecture where <code>syscall_enter_from_user_mode</code> is used is x86 where <code>rax</code> is initialized to <code>-ENOSYS</code> before <code>syscall_enter_from_user_mode</code> is invoked.</p>
</blockquote>
<p dir="auto">Hi, could you please change do_syscall() to be like this and test ptrace/strace (I have tested seccomp)?<br>
void noinstr do_syscall(struct pt_regs *regs)<br>
{<br>
unsigned long nr;<br>
sys_call_fn syscall_fn;</p>
<pre><code>    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);
</code></pre>
<p dir="auto">}</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/strace/strace/pull/205#issuecomment-1007902930">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AOVBTR6RJWIXWEU26MOSXODUU7TADANCNFSM5KYUVD5Q">unsubscribe</a>.<br />Triage notifications on the go with GitHub Mobile for <a href="https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675">iOS</a> or <a href="https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub">Android</a>.
<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AOVBTR3EGJ3J7QJG46LU3BDUU7TADA5CNFSM5KYUVD52YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOHQJWBUQ.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><strace/strace/pull/205/c1007902930</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/strace/strace/pull/205#issuecomment-1007902930",
"url": "https://github.com/strace/strace/pull/205#issuecomment-1007902930",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>