Public bug reported:

== Summary ==
ptrace:set_syscall_info in ubuntu_kernel_selftests failed on stonking 
7.3.0-11.12 generic exlcusively with ppc64e (passed with r/linux ppc64el):
- At an exit stop, PTRACE_GET_SYSCALL_INFO issued right after 
PTRACE_SET_SYSCALL_INFO returns 0 with errno unset (set_syscall_info.c:491).
- tools/testing/selftests/ptrace/set_syscall_info.c is identical in the 
stonking 7.3.0-11.12 and resolute 7.0.0-44.44 trees, so the difference comes 
from the kernel, not from the test.

A standalone reproducer shows that, after PTRACE_SET_SYSCALL_INFO on an
exit stop, the next system call made by the tracer itself is skipped and
returns 0. See Analysis.

== Test Information ==
* SRU Cycle: sru-20261109
* Series: stonking
* Package: linux
* Kernel Version: 7.3.0-11.12
* Arch: ppc64el
* Cloud / Target: openstack
* Test Suite: ubuntu_kernel_selftests
* Test Case: ptrace:set_syscall_info

== Failure Log ==
 Running 'timeout 2700s make run_tests -C ptrace TEST_PROGS=set_syscall_info 
TEST_GEN_PROGS= TEST_CUSTOM_PROGS='
 # timeout set to 45
 # selftests: ptrace: set_syscall_info
 # TAP version 13
 # 1..1
 # # Starting 1 tests from 1 test cases.
 # #  RUN           global.set_syscall_info ...
 # # set_syscall_info.c:491:set_syscall_info:Expected 0 (0) < (rc = 
sys_ptrace(PTRACE_GET_SYSCALL_INFO, tracee_pid, size, (uintptr_t) &info)) (0)
 # # set_syscall_info.c:494:set_syscall_info:wait #2: PTRACE_GET_SYSCALL_INFO 
#2: Success
 # # set_syscall_info: Test terminated by assertion
 # #          FAIL  global.set_syscall_info
 # not ok 1 global.set_syscall_info
 # # FAILED: 0 / 1 tests passed.
 # # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
 not ok 1 selftests: ptrace: set_syscall_info # exit=1

== Analysis ==
Reproduction (the unmodified selftest source from the stonking 7.3.0-11.12 
tree, built with gcc and run on VMs):

| Kernel | Arch | set_syscall_info | tracer's next getpid() after SET at an 
exit stop |
| stonking 7.3.0-11 | ppc64el | FAIL (line 491, rc=0) | 0 (skipped), the 
following call returns the real pid |
| resolute 7.0.0-44 | ppc64el | pass | real pid |

The last column comes from a small standalone program: the tracee loops
on getppid(); the tracer, at the first exit stop, does
PTRACE_GET_SYSCALL_INFO, then PTRACE_SET_SYSCALL_INFO with the same
info, then calls getpid() twice.

Verified by reading the sources (Ubuntu trees at the tags above, and upstream):
* 7.0.0-44.44 does not select GENERIC_ENTRY for powerpc. 7.3.0-11.12 does 
(arch/powerpc/Kconfig, annotations).
* In 7.3.0-11.12, arch/powerpc/include/asm/syscall.h: 
syscall_set_return_value() ends with set_thread_flag(TIF_SYSCALL_RET). The 
7.0.0-44.44 version of the function does not have it. This comes from upstream 
commit 69cb2be898be ("powerpc/syscall: Fix syscall skip handling for seccomp 
and ptrace").
* set_thread_flag() operates on current_thread_info() 
(include/linux/thread_info.h), i.e. on the task executing the call.
* kernel/ptrace.c: ptrace_set_syscall_info_exit() calls 
syscall_set_return_value(child, regs, ...). In that path current is the tracer, 
not the tracee, so the flag is set on the tracer.
* arch/powerpc/kernel/syscall.c: system_call_exception() does 
test_and_clear_thread_flag(TIF_SYSCALL_RET) and, if set, returns 
syscall_get_error(current, regs) without running the system call. For a 
non-error this is 0.
* So the tracer's next system call (the second PTRACE_GET_SYSCALL_INFO in the 
test) is skipped and returns 0 with errno unset, matching the log. The 
entry-stop path does not call syscall_set_return_value(), which is why only the 
exit-stop branch of the test fails (deduced from the source, not tested 
separately).
* Upstream status: up to v7.4-rc3, arch/powerpc/include/asm/syscall.h still has 
the unconditional set_thread_flag(TIF_SYSCALL_RET) and 
ptrace_set_syscall_info_exit() still passes child. I did not find a fix, but 
this was a path-based search of v7.3..v7.4-rc3 plus reading those two files at 
v7.4-rc3. I did not read the diffs of the other commits touching 
arch/powerpc/kernel/syscall.c and kernel/ptrace.c in that range, did not search 
commit messages, and did not check mailing lists for unmerged patches.

Hypotheses (not verified):
* A fix probably needs to avoid setting the flag on current when the target 
task is a different task (ptrace case). No patch was written or tested.
* Other tracer users of PTRACE_SET_SYSCALL_INFO on ppc64el may be affected the 
same way; not checked.
* Other architectures with GENERIC_ENTRY were not checked for the same pattern 
(the flag looks powerpc-specific).

** Affects: ubuntu-kernel-tests
     Importance: Undecided
         Status: New

** Affects: linux (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: 7.3 generic openstack ppc64el sru-20261109 stonking 
ubuntu-kernel-selftests

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2174998

Title:
  ptrace:set_syscall_info in ubuntu_kernel_selftests failed on stonking
  ppc64el (GET_SYSCALL_INFO returns 0 after SET)

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu-kernel-tests/+bug/2174998/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to