Skip to content

Commit

Permalink
Reap children before entering main event loop
Browse files Browse the repository at this point in the history
In the event we have thousands of audit trails to expuire, we go
through and expire each one, executing the audit_warn script. We
do not reap these children until we enter the main event loop.

This change adds a reap check right after the fork/exec operations,
if we have over 100 child processes that are waiting to be reaped,
do it. This hopefully fixes a denial of service condition when
starting up with many audit trail files.

In collaboration with:	asomers
Issue:	#35
  • Loading branch information
csjayp committed Jul 27, 2018
1 parent 01ba03b commit 0d082e6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions bin/auditd/audit_warn.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ auditwarnlog(char *args[])
/*
* Parent.
*/
auditd_check_and_reap();
return (0);
}

Expand Down
1 change: 1 addition & 0 deletions bin/auditd/auditd.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,6 @@ void auditd_terminate(void);
int auditd_config_controls(void);
void auditd_reap_children(void);

void auditd_check_and_reap(void);

#endif /* !_AUDITD_H_ */
6 changes: 6 additions & 0 deletions bin/auditd/auditd_darwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,3 +480,9 @@ auditd_relay_signal(int signal)
mach_msg(&(msg.header), MACH_SEND_MSG|MACH_SEND_TIMEOUT, sizeof(msg),
0, MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
}

void
auditd_check_and_reap(void)
{

}
17 changes: 17 additions & 0 deletions bin/auditd/auditd_fbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,20 @@ auditd_relay_signal(int signal)
sigalrms++;
}

/*
* We call auditd_check_and_reap() after the calls to fork() and exec()
* when running the audit_warn script to make sure we do not get a huge
* backlog of zombie processes when expiring large volumes of audit trails.
*
* Since this occurs upon reception of the signal in darwin, we only need to
* implement this for freebsd. In darwin it's a no-op
*/
void
auditd_check_and_reap(void)
{

if ((sigchlds - sigchlds_handled) > 100) {
sigchlds_handled = sigchlds;
auditd_reap_children();
}
}

0 comments on commit 0d082e6

Please sign in to comment.