From ec281db0d1233930dba9b203416ebe063b9b3e1b Mon Sep 17 00:00:00 2001 From: MaxsTechReview Date: Wed, 2 Dec 2026 16:32:38 -0500 Subject: [PATCH] fix(nativeguest): restore desktop startup after child handoff (#3594) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Keep handed-off children on the guest hook’s standard wait path. Verified the exact signed PR build on a Pocket Fit Elite: the desktop reached READY with KWin, Xwayland, and Plasma running. --- tools/nativeguest/hook/privileged.c | 21 +++++++++++++++ tools/tests/test_native_hook_handoff.py | 35 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/tools/nativeguest/hook/privileged.c b/tools/nativeguest/hook/privileged.c index 2a4a4dc2e1..14ef7c6654 100644 --- a/tools/nativeguest/hook/privileged.c +++ b/tools/nativeguest/hook/privileged.c @@ -339,6 +339,13 @@ __asm__(".globl setrlimit64\n" ".set setrlimit64, setrlimit\n"); #endif #endif +#ifndef CLONE_PIDFD +#define CLONE_PIDFD 0x00001000 +#endif +#ifndef P_PIDFD +#define P_PIDFD 3 +#endif + #ifndef SECCOMP_SET_MODE_STRICT #define SECCOMP_SET_MODE_STRICT 0 #endif @@ -639,6 +646,20 @@ long syscall(long number, ...) { } #endif +#ifdef __NR_clone + if (number == __NR_clone && (arg1 & CLONE_PIDFD)) { + errno = EINVAL; + return -1; + } +#endif + +#ifdef __NR_waitid + if (number == __NR_waitid && (int)arg1 == P_PIDFD) { + errno = EINVAL; + return -1; + } +#endif + #ifdef __NR_clone3 if (number == __NR_clone3) { errno = ENOSYS; diff --git a/tools/tests/test_native_hook_handoff.py b/tools/tests/test_native_hook_handoff.py index bf4d0e2586..3e9f5bec74 100644 --- a/tools/tests/test_native_hook_handoff.py +++ b/tools/tests/test_native_hook_handoff.py @@ -1111,6 +1111,34 @@ int main(void) { # A worker's program with its table at fd 1000 (kept, as 900 and 901 are): a dup2() onto the pidfd # lets go of 900 while another thread's close_range(899, 2000) is between its parts, held there by the # hook's test gate. The kept fds above 900 stay open. +PIDFD_PROBE = r""" +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include + +int main(void) { + errno = 0; + long r = syscall(SYS_waitid, 3, INT_MAX, NULL, WEXITED | WNOHANG, NULL); + printf("waitid\t%ld %d\n", r, errno); + int pidfd = -1; + errno = 0; + r = syscall(SYS_clone, 0x00001000 | SIGCHLD, NULL, &pidfd, NULL, 0); + if (r == 0) _exit(9); + printf("clone\t%ld %d %d\n", r < 0 ? -1L : 1L, errno, pidfd); + if (r > 0) waitpid((pid_t)r, NULL, 0); + r = syscall(SYS_clone, SIGCHLD, NULL, NULL, NULL, 0); + if (r == 0) _exit(7); + int status = 0; + printf("fork\t%d\n", r > 0 && waitpid((pid_t)r, &status, 0) == r && WIFEXITED(status) ? WEXITSTATUS(status) : -1); + return 0; +} +""" + DUPRACE = r""" #define _GNU_SOURCE #include @@ -2217,6 +2245,13 @@ class NativeHookHandoffTest(unittest.TestCase): pass_fds=(table,)) return parent, dict(line.split("\t", 1) for line in out.stdout.splitlines() if "\t" in line), out + def test_a_guest_sees_no_pidfd_support_so_its_waits_go_through_the_handoff(self): + parent, result, out = self.run_worker_program("pidfd", PIDFD_PROBE) + self.assertEqual(0, out.returncode, out.stderr) + self.assertEqual("-1 %d" % errno.EINVAL, result.get("waitid"), out.stdout + out.stderr) + self.assertEqual("-1 %d -1" % errno.EINVAL, result.get("clone"), out.stdout) + self.assertEqual("7", result.get("fork"), out.stdout) + def test_a_dup2_onto_the_parents_pidfd_while_a_close_range_runs_closes_no_kept_fd(self): parent, result, out = self.run_worker_program("duprace", DUPRACE, table_fd=1000) self.assertEqual(0, out.returncode, out.stderr)