Skip to content

Commit 8d77c0f

Browse files
committed
Make all plugins ignore SIGTERM if not from auditd
1 parent 1083af6 commit 8d77c0f

File tree

5 files changed

+43
-16
lines changed

5 files changed

+43
-16
lines changed

ChangeLog

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
- Add support for "exec" action in max_log_file_action in auditd
66
- Refactor auparse code to be multi-thread safe
77
- Add memory pool to netlink event processing to reduce memory churn
8-
- Make af_unix plugin ignore SIGTERM if not from auditd
8+
- Make all plugins ignore SIGTERM if not from auditd (issue #469)
99

1010
4.0.5
1111
- Rework audisp queue to be lockless

audisp/plugins/remote/audisp-remote.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,15 @@ gss_ctx_id_t my_context;
120120

121121
/*
122122
* SIGTERM handler
123+
*
124+
* Only honor the signal if it comes from the parent process so that other
125+
* tasks (cough, systemctl, cough) can't make the plugin exit without
126+
* the dispatcher in agreement. Otherwise it will restart the plugin.
123127
*/
124-
static void term_handler( int sig )
128+
static void term_handler(int sig, siginfo_t *info, void *ucontext)
125129
{
130+
if (info && info->si_pid != getppid())
131+
return;
126132
stop = 1;
127133
}
128134

@@ -499,8 +505,6 @@ int main(int argc, char *argv[])
499505
sa.sa_flags = 0;
500506
sigemptyset(&sa.sa_mask);
501507
/* Set handler for the ones we care about */
502-
sa.sa_handler = term_handler;
503-
sigaction(SIGTERM, &sa, NULL);
504508
sa.sa_handler = hup_handler;
505509
sigaction(SIGHUP, &sa, NULL);
506510
sa.sa_handler = user1_handler;
@@ -509,6 +513,9 @@ int main(int argc, char *argv[])
509513
sigaction(SIGUSR2, &sa, NULL);
510514
sa.sa_handler = child_handler;
511515
sigaction(SIGCHLD, &sa, NULL);
516+
sa.sa_sigaction = term_handler;
517+
sa.sa_flags = SA_SIGINFO;
518+
sigaction(SIGTERM, &sa, NULL);
512519
if (load_config(&config, CONFIG_FILE))
513520
return 6;
514521

audisp/plugins/syslog/audisp-syslog.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,15 @@ static int interpret = 0;
4444

4545
/*
4646
* SIGTERM handler
47+
*
48+
* Only honor the signal if it comes from the parent process so that other
49+
* tasks (cough, systemctl, cough) can't make the plugin exit without
50+
* the dispatcher in agreement. Otherwise it will restart the plugin.
4751
*/
48-
static void term_handler( int sig )
52+
static void term_handler(int sig, siginfo_t *info, void *ucontext)
4953
{
54+
if (info && info->si_pid != getppid())
55+
return;
5056
stop = 1;
5157
}
5258

@@ -220,10 +226,11 @@ int main(int argc, const char *argv[])
220226
sa.sa_flags = 0;
221227
sigemptyset(&sa.sa_mask);
222228
/* Set handler for the ones we care about */
223-
sa.sa_handler = term_handler;
224-
sigaction(SIGTERM, &sa, NULL);
225229
sa.sa_handler = hup_handler;
226230
sigaction(SIGHUP, &sa, NULL);
231+
sa.sa_sigaction = term_handler;
232+
sa.sa_flags = SA_SIGINFO;
233+
sigaction(SIGTERM, &sa, NULL);
227234

228235
#ifdef HAVE_LIBCAP_NG
229236
// Drop capabilities

audisp/plugins/zos-remote/zos-remote-plugin.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,17 @@ static pthread_t submission_thread;
6060
pid_t mypid = 0;
6161

6262
/*
63-
* SIGTERM handler
63+
* SIGTERM handler
64+
*
65+
* Only honor the signal if it comes from the parent process so that other
66+
* tasks (cough, systemctl, cough) can't make the plugin exit without
67+
* the dispatcher in agreement. Otherwise it will restart the plugin.
6468
*/
65-
static void term_handler(int sig)
69+
static void term_handler(int sig, siginfo_t *info, void *ucontext)
6670
{
6771
UNUSED(sig);
68-
log_info("Got Termination signal - shutting down plugin");
72+
if (info && info->si_pid != getppid())
73+
return;
6974
stop = 1;
7075
nudge_queue();
7176
}
@@ -427,14 +432,15 @@ int main(int argc, char *argv[])
427432
*/
428433
sa.sa_flags = 0;
429434
sigemptyset(&sa.sa_mask);
430-
sa.sa_handler = term_handler;
431-
sigaction(SIGTERM, &sa, NULL);
432435
sa.sa_handler = hup_handler;
433436
sigaction(SIGHUP, &sa, NULL);
434437
sa.sa_handler = alarm_handler;
435438
sigaction(SIGALRM, &sa, NULL);
439+
sa.sa_sigaction = term_handler;
440+
sa.sa_flags = SA_SIGINFO;
441+
sigaction(SIGTERM, &sa, NULL);
436442

437-
/*
443+
/*
438444
* the main program accepts a single (optional) argument:
439445
* it's configuration file (this is NOT the plugin configuration
440446
* usually located at /etc/audit/plugins.d)

contrib/plugin/audisp-example.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,15 @@ static void handle_event(auparse_state_t *au,
6666

6767
/*
6868
* SIGTERM handler
69+
*
70+
* Only honor the signal if it comes from the parent process so that other
71+
* tasks (cough, systemctl, cough) can't make the plugin exit without
72+
* the dispatcher in agreement. Otherwise it will restart the plugin.
6973
*/
70-
static void term_handler(int sig)
74+
static void term_handler(int sig, siginfo_t *info, void *ucontext)
7175
{
76+
if (info && info->si_pid != getppid())
77+
return;
7278
stop = 1;
7379
}
7480

@@ -99,10 +105,11 @@ int main(int argc, char *argv[])
99105
sa.sa_flags = 0;
100106
sigemptyset(&sa.sa_mask);
101107
/* Set handler for the ones we care about */
102-
sa.sa_handler = term_handler;
103-
sigaction(SIGTERM, &sa, NULL);
104108
sa.sa_handler = hup_handler;
105109
sigaction(SIGHUP, &sa, NULL);
110+
sa.sa_sigaction = term_handler;
111+
sa.sa_flags = SA_SIGINFO;
112+
sigaction(SIGTERM, &sa, NULL);
106113
/* Set STDIN non-blocking */
107114
fcntl(0, F_SETFL, O_NONBLOCK);
108115

0 commit comments

Comments
 (0)