HomeFreeBSD

setitimer: Fix exit race

Description

setitimer: Fix exit race

We use the p_itcallout callout, interlocked by the proc lock, to
schedule timeouts for the setitimer(2) system call. When a process
exits, the callout must be stopped before the process struct is
recycled.

Currently we attempt to stop the callout in exit1() with the call
_callout_stop_safe(&p->p_itcallout, CS_EXECUTING). If this call returns
0, then we sleep in order to drain the callout. However, this happens
only if the callout is not scheduled at all. If the callout thread is
blocked on the proc lock, then exit1() will not block and the callout
may execute after the process has fully exited, typically resulting in a
panic.

I cannot see a reason to use the CS_EXECUTING flag here. Instead, use
the regular callout_stop()/callout_drain() dance to halt the callout.

Reported by: ler
Tested by: ler, pho
Sponsored by: The FreeBSD Foundation

(cherry picked from commit b319171861464f6c445905e7649cb43bf9bc78be)

Details

Provenance
markjAuthored on Mar 23 2022, 4:36 PM
Parents
rG4a98047762f3: videomode: Fix a typo in an kernel message
Branches
Unknown
Tags
Unknown