mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-10-28 19:34:43 +01:00
syslogd: reap pipe children on config reload
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.
Reviewed by: markj
Fixes: 95381c0139 (syslogd: Use process descriptors)
Differential Revision: https://reviews.freebsd.org/D59319
This commit is contained in:
1 parent
ab420c44bc
commit
1a669b66dd
1 file changed
+9
-5
@@ -2549,6 +2549,7 @@ void
|
||||
closelogfiles(void)
|
||||
{
|
||||
struct filed *f;
|
||||
bool defer_free;
|
||||
|
||||
while (!STAILQ_EMPTY(&fhead)) {
|
||||
f = STAILQ_FIRST(&fhead);
|
||||
@@ -2558,6 +2559,13 @@ closelogfiles(void)
|
||||
if (f->f_prevcount)
|
||||
fprintlog_successive(f, 0);
|
||||
|
||||
/*
|
||||
* If a piped process is running, then defer the filed
|
||||
* cleanup until it exits. close_filed() below sets
|
||||
* f_type to F_UNUSED, so capture this before calling it.
|
||||
*/
|
||||
defer_free = (f->f_type == F_PIPE && f->f_procdesc != -1);
|
||||
|
||||
switch (f->f_type) {
|
||||
case F_FILE:
|
||||
case F_FORW:
|
||||
@@ -2585,11 +2593,7 @@ closelogfiles(void)
|
||||
free(f->f_prop_filter);
|
||||
}
|
||||
|
||||
/*
|
||||
* If a piped process is running, then defer the filed
|
||||
* cleanup until it exits.
|
||||
*/
|
||||
if (f->f_type != F_PIPE || f->f_procdesc == -1)
|
||||
if (!defer_free)
|
||||
free(f);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user