CVE-2026-12365
Beschrijving NL
Er bestaat een use-after-free in de Zephyr werkvoorraad van de tweede generatie (kernel/work.c) bij het afhandelen van vertraagde werk time-outs. Wanneer de time-out van een vertraagd werkitem is opgeschort en de afhandelaar work_timeout() in vlucht is (geblokkeerd voor het verkrijgen van de werkvoorraad spinlock), wacht een gelijktijdige annulering niet tot die afhandelaar klaar is. In unschedule_locked() wordt de voorfixcode z_abort_timeout() genoemd, die voor een reeds aangekondigde record -EINVAL retourneert zonder deze te verwijderen; cancel_async_locked() observeert vervolgens het werk als inactief, dus zelfs k_work_cancel_delayable_sync() en k_work_flush_delayable () keren terug zonder de handler tijdens de vlucht te blokkeren. Omdat dit de API's zijn die de kernelheaderdocumenten gebruiken als de veilige manier om te annuleren voordat een k_work_delayable wordt vrijgegeven, kan een beller die het object onmiddellijk na een geslaagde synchronisatieannulering bevrijdt, de nog in behandeling zijnde handler racen. work_timeout() derefereert vervolgens het vrijgekomen record: het leest naar-> dticks via z_is_timeout_handler_canceled() en, als het vrijgemaakte slot opnieuw is gebruikt zodat de borgtochtcontrole mislukt, voert het een read-modify-write van wp->vlaggen (K_WORK_DELAYED_BIT) uit en dient het werk in tegen een verouderde dw- >queue pointer — een use-after-free lezen en schrijven. De k_work API is alleen kernel-modus (geen __syscall entry point), dus dit is een kernel-intern concurrency defect in plaats van een gebruikersruimte privilege escalatie. Triggering it requires an SMP build and a subsystem that schedules and then frees (or reschedules) a delayable work item in the narrow window while its timeout is announcing; an attacker able to influence the timing of such teardown (for example via connection churn driving subsystem timers) has a plausible but probabilistic path. The impact is kernel memory corruption or crash (denial of service). The fix makes unschedule_locked() wait, by spinning on z_try_abort_timeout() returning -EAGAIN while releasing and re-acquiring the work spinlock, until any in-flight handler completes before returning, and switches work_timeout() to atomic K_WORK_DELAYED_BIT ownership. This closes both the free-then-handler use-after-free and the related reschedule early-fire race.
Origineel (Engels) tonen
A use-after-free exists in the Zephyr second-generation work queue (kernel/work.c) in the handling of delayable work timeouts. When a delayable work item's timeout has been dequeued and its handler work_timeout() is in flight (blocked acquiring the work-queue spinlock), a concurrent cancellation does not wait for that handler to finish. In unschedule_locked() the pre-fix code called z_abort_timeout(), which for an already-announcing record returns -EINVAL without removing it; cancel_async_locked() then observes the work as idle, so even k_work_cancel_delayable_sync() and k_work_flush_delayable() return without blocking on the in-flight handler.
Because those are the APIs the kernel header documents as the safe way to cancel before freeing a k_work_delayable, a caller that frees the object immediately after a successful sync cancel can race the still-pending handler. work_timeout() subsequently dereferences the freed record: it reads to->dticks via z_is_timeout_handler_canceled() and, if the freed slot has been reused so the bail check fails, performs a read-modify-write of wp->flags (K_WORK_DELAYED_BIT) and submits work against a stale dw->queue pointer — a use-after-free read and write.
The k_work API is kernel-mode only (no __syscall entry point), so this is a kernel-internal concurrency defect rather than a userspace privilege escalation. Triggering it requires an SMP build and a subsystem that schedules and then frees (or reschedules) a delayable work item in the narrow window while its timeout is announcing; an attacker able to influence the timing of such teardown (for example via connection churn driving subsystem timers) has a plausible but probabilistic path. The impact is kernel memory corruption or crash (denial of service).
The fix makes unschedule_locked() wait, by spinning on z_try_abort_timeout() returning -EAGAIN while releasing and re-acquiring the work spinlock, until any in-flight handler completes before returning, and switches work_timeout() to atomic K_WORK_DELAYED_BIT ownership. This closes both the free-then-handler use-after-free and the related reschedule early-fire race.