Public bug reported:
== Summary ==
seccomp:seccomp_bpf in ubuntu_kernel_selftests failed on stonking 7.3.0-12.13
generic ppc64el:
- 11 of 112 subtests fail (pass:89 fail:11 skip:12): 10
global.user_notification_* subtests and TRACE_syscall.seccomp.syscall_faked.
- Reproduced by hand on a 7.3.0-12-generic ppc64le machine. A seccomp user
notification reply with a successful value (error=0, val=12345) makes the
intercepted syscall return 0 instead of 12345. A reply with an error (-EPERM)
works correctly.
- The same assertions fail on stonking 7.3.0-5.5 (e.g. syscall_faked "Expected
45000 == syscall(207) (0)", user_notification_sync "Expected ret (0) ==
USER_NOTIF_MAGIC"), so this is not new in 7.3.0-12.13.
- On 7.0.0-27-generic (no CONFIG_GENERIC_ENTRY in its config) the same
seccomp_bpf binary passes user_notification_basic, user_notification_sync and
syscall_faked, and the reproducer below returns 12345.
== Reproducer ==
Build with "gcc -w -o un un.c" and run as a normal user.
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <sys/prctl.h>
#include <linux/seccomp.h>
#include <linux/filter.h>
#include <stddef.h>
static int run(int err, long val)
{
int p[2], q[2]; pipe(p); pipe(q);
pid_t pid = fork();
if (pid == 0) {
struct sock_filter f[] = {
BPF_STMT(BPF_LD|BPF_W|BPF_ABS, offsetof(struct
seccomp_data, nr)),
BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_getppid, 0, 1),
BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_USER_NOTIF),
BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
};
struct sock_fprog prog = { .len = 4, .filter = f };
prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
int l = syscall(__NR_seccomp, SECCOMP_SET_MODE_FILTER,
SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);
write(p[1], &l, sizeof l);
char c; read(q[0], &c, 1);
errno = 0;
long r = syscall(__NR_getppid);
printf(" child: syscall(getppid) = %ld errno=%d\n", r, errno);
fflush(stdout); _exit(0);
}
int cfd; read(p[0], &cfd, sizeof cfd);
int pf = syscall(__NR_pidfd_open, pid, 0);
int l = syscall(__NR_pidfd_getfd, pf, cfd, 0);
if (l < 0) { perror("pidfd_getfd"); return 1; }
write(q[1], "g", 1);
struct seccomp_notif req; memset(&req, 0, sizeof req);
if (ioctl(l, SECCOMP_IOCTL_NOTIF_RECV, &req)) { perror("recv"); return
1; }
struct seccomp_notif_resp resp = { .id = req.id, .error = err, .val =
val };
if (ioctl(l, SECCOMP_IOCTL_NOTIF_SEND, &resp)) { perror("send"); return
1; }
int st; waitpid(pid, &st, 0);
return 0;
}
int main(void)
{
printf("reply val=12345 error=0:\n"); run(0, 12345);
printf("reply error=-EPERM:\n"); run(-EPERM, 0);
return 0;
}
Result on 7.3.0-12-generic (ppc64le):
reply val=12345 error=0:
child: syscall(getppid) = 0 errno=0
reply error=-EPERM:
child: syscall(getppid) = -1 errno=1
Result on 7.0.0-27-generic (ppc64le):
reply val=12345 error=0:
child: syscall(getppid) = 12345 errno=0
reply error=-EPERM:
child: syscall(getppid) = -1 errno=1
== Analysis (hypothesis, based on reading the source; the fix has not been
tested) ==
The expectations in seccomp_bpf.c are correct (e.g. the child does exit(ret !=
USER_NOTIF_MAGIC)), so the kernel is the failing layer.
In arch/powerpc/kernel/syscall.c (Ubuntu-7.3.0-12.13, lines 21-27),
system_call_exception() does:
if (unlikely(!syscall_enter_from_user_mode_randomize_stack(regs, &r0))) {
clear_thread_flag(TIF_SYSCALL_RET);
return syscall_get_error(current, regs);
}
if (unlikely(test_and_clear_thread_flag(TIF_SYSCALL_RET)))
return syscall_get_error(current, regs);
syscall_get_error() (arch/powerpc/include/asm/syscall.h) returns only an
error code and returns 0 for a non-error value. The return value of
system_call_exception() is passed to syscall_exit_prepare(), which
stores it in regs->result and regs->gpr[3], so a successful value set by
seccomp/ptrace appears to be replaced by 0. Injecting an errno works
(e.g. TRACE_syscall.seccomp.syscall_errno passes), which is consistent
with this.
Two paths lead there: seccomp user notification sets the value with
syscall_set_return_value() (which sets TIF_SYSCALL_RET), while the
ptrace-based syscall_faked test writes the registers with
PTRACE_SETREGSET and sets r0 to -1; I did not trace which of the two
branches above that case takes.
The code comes from "powerpc: Enable GENERIC_ENTRY feature"
(bee25f97ad24) and the follow-ups 69cb2be898be and 2c1dde8a69a3. Other
differences between 7.0.0-27 and 7.3.0-12 may exist, so GENERIC_ENTRY is
the suspected cause, not a proven one. No fix has been tried: no kernel
was rebuilt.
Upstream (kernel.org mainline): v7.3, v7.4-rc4 and master (25faec9ce61c)
still return syscall_get_error() from system_call_exception() in the
same way. Between v7.3 and master the only commit touching
arch/powerpc/kernel/syscall.c, asm/syscall.h, interrupt.c,
interrupt_64.S or ptrace/ is 66236558dfac ("Avoid atomic
test_and_clear_thread_flag on fast path"), which does not change the
returned value. I did not search mailing lists, so a pending patch may
exist.
Not checked: the individual cause of each of the other
user_notification_* failures, and global.tsync_vs_dead_thread_leader,
which failed only on 7.3.0-5.5. On 7.0.0-27,
user_notification_child_pid_ns and user_notification_fault_recv fail
too, with a different error (seccomp NEW_LISTENER returns EACCES after
unshare(CLONE_NEWUSER|CLONE_NEWPID)); I did not investigate it and do
not consider it the same issue.
== Test Information ==
* SRU Cycle: sru-20261123
* Series: stonking
* Package: linux
* Kernel Version: 7.3.0-12.13
* Arch: ppc64el
* Cloud / Target: openstack
* Test Suite: ubuntu_kernel_selftests
* Test Case: seccomp:seccomp_bpf
== Failure Log ==
# # seccomp_bpf.c:3488:user_notification_basic:Expected 0 (0) ==
WEXITSTATUS(status) (1)
# # FAIL global.user_notification_basic
# not ok 37 global.user_notification_basic
# # seccomp_bpf.c:3713:user_notification_child_pid_ns:Expected 0 (0) ==
WEXITSTATUS(status) (1)
# not ok 42 global.user_notification_child_pid_ns
# # seccomp_bpf.c:3836:user_notification_fault_recv:Expected 0 (0) ==
WEXITSTATUS(status) (1)
# not ok 44 global.user_notification_fault_recv
# # user_notification_addfd: Test terminated by timeout
# not ok 50 global.user_notification_addfd
# # seccomp_bpf.c:4583:user_notification_sync:Expected ret (0) ==
USER_NOTIF_MAGIC (2147483647)
# # seccomp_bpf.c:4601:user_notification_sync:Expected status (256) == 0 (0)
# not ok 53 global.user_notification_sync
# # seccomp_bpf.c:4967:user_notification_wait_killable:Expected 0 (0) ==
WEXITSTATUS(status) (1)
# not ok 56 global.user_notification_wait_killable
# # seccomp_bpf.c:2253:syscall_faked:Expected 45000 (45000) == syscall(207) (0)
# # FAIL TRACE_syscall.seccomp.syscall_faked
# not ok 88 TRACE_syscall.seccomp.syscall_faked
# # FAILED: 101 / 112 tests passed.
# # Totals: pass:89 fail:11 xfail:0 xpass:0 skip:12 error:0
not ok 1 selftests: seccomp: seccomp_bpf # exit=1
** Affects: ubuntu-kernel-tests
Importance: Undecided
Status: New
** Affects: linux (Ubuntu)
Importance: Undecided
Status: New
** Tags: 7.3 generic openstack ppc64el sru-20261123 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/2176163
Title:
seccomp:seccomp_bpf in ubuntu_kernel_selftests failed on stonking
ppc64el (injected syscall return value becomes 0)
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu-kernel-tests/+bug/2176163/+subscriptions
--
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs