From 8fa2e65a42a198aaf954b1185db9c77c3b4cc0f8 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Sat, 28 Nov 2026 10:00:42 -0500 Subject: [PATCH] fix(handoff): a fork record stays only for the pid's current process --- tools/nativeguest/hook/handoff.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/nativeguest/hook/handoff.c b/tools/nativeguest/hook/handoff.c index 495970268b..4887bf2aa6 100644 --- a/tools/nativeguest/hook/handoff.c +++ b/tools/nativeguest/hook/handoff.c @@ -154,10 +154,14 @@ static void ddh_forked_by(pid_t child, pid_t thread) { uint64_t seen = __atomic_load_n(slot, __ATOMIC_ACQUIRE); for (;;) { // A later child given the pid (this one reaped while its fork was being recorded) has - // recorded itself already: its record stays. Start times compared within their 19 bits. - if (seen && ddh_record_child(seen) == child && (seen & 0x80000) && (mine & 0x80000)) { - uint64_t theirs = seen & 0x7ffff, ours = mine & 0x7ffff; - if (theirs != ours && ((theirs - ours) & 0x7ffff) < 0x40000) return; + // recorded itself already: its record stays. It is that child's only while the process that + // has the pid now started when it says; any other record of the pid is an earlier child's. + if (seen && ddh_record_child(seen) == child && (seen & 0x80000) && (mine & 0x80000) && + (seen & 0x7ffff) != (mine & 0x7ffff)) { + saved = errno; + long now = ddh_start_time(child); + errno = saved; + if (now > 0 && ((uint64_t)now & 0x7ffff) == (seen & 0x7ffff)) return; } if (__atomic_compare_exchange_n(slot, &seen, mine, 0, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE)) return; }