Page MenuHomeFreeBSD

syslogd: reap pipe children on config reload
ClosedPublic

Authored by bapt on Wed, Sep 2, 8:56 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Sep 23, 1:18 PM
Unknown Object (File)
Wed, Sep 23, 12:13 PM
Unknown Object (File)
Tue, Sep 22, 6:16 PM
Unknown Object (File)
Sun, Sep 20, 3:24 AM
Unknown Object (File)
Thu, Sep 17, 2:24 PM
Unknown Object (File)
Mon, Sep 14, 7:53 PM
Unknown Object (File)
Sun, Sep 13, 7:11 PM
Unknown Object (File)
Sun, Sep 13, 7:11 PM
Subscribers

Details

Summary

On SIGHUP reload, closelogfiles() frees each F_PIPE filed even when its
pipe process is still running. close_filed() sets f_type to F_UNUSED
before the check, so the condition f_type != F_PIPE is always true and
the filed is freed while its process descriptor is still on the dead
queue and registered in the kqueue. When the child later exits, the
NOTE_EXIT handler dereferences the freed filed (use-after-free) and
never closes the process descriptor, leaving the pipe child as a
persistent zombie.

Capture whether the filed is a pipe with an active process descriptor
before calling close_filed(), and defer the free in that case so the
NOTE_EXIT handler can reap the child and free the filed.

Test Plan

with

*.info         |exec /home/bapt/zombies.sh

the script being

#!/bin/sh
while read -r line; do
    :
done

We ensure the script is spawned:
logger -p info -t test "spawn"
pkill -HUP syslogd

here you are you have your zombies

restart syslogd, they are reaped properly.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

bapt requested review of this revision.Wed, Sep 2, 8:56 AM
bapt added a reviewer: markj.

I wrote a regression test case for this bug, will commit it after this patch lands.

Could you please add a Fixes tag to the commit log?

This revision is now accepted and ready to land.Wed, Sep 2, 2:32 PM
This revision was automatically updated to reflect the committed changes.