Skip to content

Commit b48345a

Browse files
rgbriggspcmoore
authored andcommitted
audit: deliver signal_info regarless of syscall
When a process signals the audit daemon (shutdown, rotate, resume, reconfig) but syscall auditing is not enabled, we still want to know the identity of the process sending the signal to the audit daemon. Move audit_signal_info() out of syscall auditing to general auditing but create a new function audit_signal_info_syscall() to take care of the syscall dependent parts for when syscall auditing is enabled. Please see the github kernel audit issue linux-audit/audit-kernel#111 Signed-off-by: Richard Guy Briggs <rgb@redhat.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent a188339 commit b48345a

5 files changed

Lines changed: 46 additions & 19 deletions

File tree

‎include/linux/audit.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
196196
}
197197

198198
extern u32 audit_enabled;
199+
200+
extern int audit_signal_info(int sig, struct task_struct *t);
201+
199202
#else /* CONFIG_AUDIT */
200203
static inline __printf(4, 5)
201204
void audit_log(struct audit_context *ctx, gfp_t gfp_mask, int type,
@@ -249,6 +252,12 @@ static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
249252
}
250253

251254
#define audit_enabled AUDIT_OFF
255+
256+
static inline int audit_signal_info(int sig, struct task_struct *t)
257+
{
258+
return 0;
259+
}
260+
252261
#endif /* CONFIG_AUDIT */
253262

254263
#ifdef CONFIG_AUDIT_COMPAT_GENERIC

‎kernel/audit.c‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,6 +2273,33 @@ int audit_set_loginuid(kuid_t loginuid)
22732273
return rc;
22742274
}
22752275

2276+
/**
2277+
* audit_signal_info - record signal info for shutting down audit subsystem
2278+
* @sig: signal value
2279+
* @t: task being signaled
2280+
*
2281+
* If the audit subsystem is being terminated, record the task (pid)
2282+
* and uid that is doing that.
2283+
*/
2284+
int audit_signal_info(int sig, struct task_struct *t)
2285+
{
2286+
kuid_t uid = current_uid(), auid;
2287+
2288+
if (auditd_test_task(t) &&
2289+
(sig == SIGTERM || sig == SIGHUP ||
2290+
sig == SIGUSR1 || sig == SIGUSR2)) {
2291+
audit_sig_pid = task_tgid_nr(current);
2292+
auid = audit_get_loginuid(current);
2293+
if (uid_valid(auid))
2294+
audit_sig_uid = auid;
2295+
else
2296+
audit_sig_uid = uid;
2297+
security_task_getsecid(current, &audit_sig_sid);
2298+
}
2299+
2300+
return audit_signal_info_syscall(t);
2301+
}
2302+
22762303
/**
22772304
* audit_log_end - end one audit record
22782305
* @ab: the audit_buffer

‎kernel/audit.h‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ extern const char *audit_tree_path(struct audit_tree *tree);
299299
extern void audit_put_tree(struct audit_tree *tree);
300300
extern void audit_kill_trees(struct audit_context *context);
301301

302-
extern int audit_signal_info(int sig, struct task_struct *t);
302+
extern int audit_signal_info_syscall(struct task_struct *t);
303303
extern void audit_filter_inodes(struct task_struct *tsk,
304304
struct audit_context *ctx);
305305
extern struct list_head *audit_killed_trees(void);
@@ -330,7 +330,11 @@ extern struct list_head *audit_killed_trees(void);
330330
#define audit_tree_path(rule) "" /* never called */
331331
#define audit_kill_trees(context) BUG()
332332

333-
#define audit_signal_info(s, t) AUDIT_DISABLED
333+
static inline int audit_signal_info_syscall(struct task_struct *t)
334+
{
335+
return 0;
336+
}
337+
334338
#define audit_filter_inodes(t, c) AUDIT_DISABLED
335339
#endif /* CONFIG_AUDITSYSCALL */
336340

‎kernel/auditsc.c‎

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,30 +2360,17 @@ void __audit_ptrace(struct task_struct *t)
23602360
}
23612361

23622362
/**
2363-
* audit_signal_info - record signal info for shutting down audit subsystem
2364-
* @sig: signal value
2363+
* audit_signal_info_syscall - record signal info for syscalls
23652364
* @t: task being signaled
23662365
*
23672366
* If the audit subsystem is being terminated, record the task (pid)
23682367
* and uid that is doing that.
23692368
*/
2370-
int audit_signal_info(int sig, struct task_struct *t)
2369+
int audit_signal_info_syscall(struct task_struct *t)
23712370
{
23722371
struct audit_aux_data_pids *axp;
23732372
struct audit_context *ctx = audit_context();
2374-
kuid_t uid = current_uid(), auid, t_uid = task_uid(t);
2375-
2376-
if (auditd_test_task(t) &&
2377-
(sig == SIGTERM || sig == SIGHUP ||
2378-
sig == SIGUSR1 || sig == SIGUSR2)) {
2379-
audit_sig_pid = task_tgid_nr(current);
2380-
auid = audit_get_loginuid(current);
2381-
if (uid_valid(auid))
2382-
audit_sig_uid = auid;
2383-
else
2384-
audit_sig_uid = uid;
2385-
security_task_getsecid(current, &audit_sig_sid);
2386-
}
2373+
kuid_t t_uid = task_uid(t);
23872374

23882375
if (!audit_signals || audit_dummy_context())
23892376
return 0;

‎kernel/signal.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <linux/posix-timers.h>
4545
#include <linux/livepatch.h>
4646
#include <linux/cgroup.h>
47+
#include <linux/audit.h>
4748

4849
#define CREATE_TRACE_POINTS
4950
#include <trace/events/signal.h>
@@ -53,7 +54,6 @@
5354
#include <asm/unistd.h>
5455
#include <asm/siginfo.h>
5556
#include <asm/cacheflush.h>
56-
#include "audit.h" /* audit_signal_info() */
5757

5858
/*
5959
* SLAB caches for signal bits.

0 commit comments

Comments
 (0)