Skip to content

Commit e54dc24

Browse files
Amy GriffisAl Viro
authored andcommitted
[PATCH] audit signal recipients
When auditing syscalls that send signals, log the pid and security context for each target process. Optimize the data collection by adding a counter for signal-related rules, and avoiding allocating an aux struct unless we have more than one target process. For process groups, collect pid/context data in blocks of 16. Move the audit_signal_info() hook up in check_kill_permission() so we audit attempts where permission is denied. Signed-off-by: Amy Griffis <amy.griffis@hp.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 7f13da4 commit e54dc24

11 files changed

Lines changed: 206 additions & 29 deletions

File tree

‎arch/ia64/kernel/audit.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ static unsigned signal_class[] = {
2828
~0U
2929
};
3030

31+
int audit_classify_arch(int arch)
32+
{
33+
#ifdef CONFIG_IA32_SUPPORT
34+
if (arch == AUDIT_ARCH_I386)
35+
return 1;
36+
#endif
37+
return 0;
38+
}
39+
3140
int audit_classify_syscall(int abi, unsigned syscall)
3241
{
3342
#ifdef CONFIG_IA32_SUPPORT

‎arch/powerpc/kernel/audit.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ static unsigned signal_class[] = {
2828
~0U
2929
};
3030

31+
int audit_classify_arch(int arch)
32+
{
33+
#ifdef CONFIG_PPC64
34+
if (arch == AUDIT_ARCH_PPC)
35+
return 1;
36+
#endif
37+
return 0;
38+
}
39+
3140
int audit_classify_syscall(int abi, unsigned syscall)
3241
{
3342
#ifdef CONFIG_PPC64

‎arch/s390/kernel/audit.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ static unsigned signal_class[] = {
2828
~0U
2929
};
3030

31+
int audit_classify_arch(int arch)
32+
{
33+
#ifdef CONFIG_COMPAT
34+
if (arch == AUDIT_ARCH_S390)
35+
return 1;
36+
#endif
37+
return 0;
38+
}
39+
3140
int audit_classify_syscall(int abi, unsigned syscall)
3241
{
3342
#ifdef CONFIG_COMPAT

‎arch/sparc64/kernel/audit.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ static unsigned signal_class[] = {
2828
~0U
2929
};
3030

31+
int audit_classify_arch(int arch)
32+
{
33+
#ifdef CONFIG_SPARC32_COMPAT
34+
if (arch == AUDIT_ARCH_SPARC)
35+
return 1;
36+
#endif
37+
return 0;
38+
}
39+
3140
int audit_classify_syscall(int abi, unsigned syscall)
3241
{
3342
#ifdef CONFIG_SPARC32_COMPAT

‎arch/x86_64/kernel/audit.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ static unsigned signal_class[] = {
2828
~0U
2929
};
3030

31+
int audit_classify_arch(int arch)
32+
{
33+
#ifdef CONFIG_IA32_EMULATION
34+
if (arch == AUDIT_ARCH_I386)
35+
return 1;
36+
#endif
37+
return 0;
38+
}
39+
3140
int audit_classify_syscall(int abi, unsigned syscall)
3241
{
3342
#ifdef CONFIG_IA32_EMULATION

‎include/linux/audit.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ struct mqstat;
340340
#define AUDITSC_RESULT(x) ( ((long)(x))<0?AUDITSC_FAILURE:AUDITSC_SUCCESS )
341341
extern int __init audit_register_class(int class, unsigned *list);
342342
extern int audit_classify_syscall(int abi, unsigned syscall);
343+
extern int audit_classify_arch(int arch);
343344
#ifdef CONFIG_AUDITSYSCALL
344345
/* These are defined in auditsc.c */
345346
/* Public API */
@@ -458,6 +459,7 @@ static inline int audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)
458459
return 0;
459460
}
460461
extern int audit_n_rules;
462+
extern int audit_signals;
461463
#else
462464
#define audit_alloc(t) ({ 0; })
463465
#define audit_free(t) do { ; } while (0)
@@ -490,6 +492,7 @@ extern int audit_n_rules;
490492
#define audit_mq_getsetattr(d,s) ({ 0; })
491493
#define audit_ptrace(t) ((void)0)
492494
#define audit_n_rules 0
495+
#define audit_signals 0
493496
#endif
494497

495498
#ifdef CONFIG_AUDIT

‎kernel/audit.h‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct audit_krule {
8383
u32 field_count;
8484
char *filterkey; /* ties events to rules */
8585
struct audit_field *fields;
86+
struct audit_field *arch_f; /* quick access to arch field */
8687
struct audit_field *inode_f; /* quick access to an inode field */
8788
struct audit_watch *watch; /* associated watch */
8889
struct list_head rlist; /* entry in audit_watch.rules list */
@@ -131,17 +132,19 @@ extern void audit_handle_ievent(struct inotify_watch *, u32, u32, u32,
131132
extern int selinux_audit_rule_update(void);
132133

133134
#ifdef CONFIG_AUDITSYSCALL
134-
extern void __audit_signal_info(int sig, struct task_struct *t);
135-
static inline void audit_signal_info(int sig, struct task_struct *t)
135+
extern int __audit_signal_info(int sig, struct task_struct *t);
136+
static inline int audit_signal_info(int sig, struct task_struct *t)
136137
{
137-
if (unlikely(audit_pid && t->tgid == audit_pid))
138-
__audit_signal_info(sig, t);
138+
if (unlikely((audit_pid && t->tgid == audit_pid) ||
139+
(audit_signals && !audit_dummy_context())))
140+
return __audit_signal_info(sig, t);
141+
return 0;
139142
}
140143
extern enum audit_state audit_filter_inodes(struct task_struct *,
141144
struct audit_context *);
142145
extern void audit_set_auditable(struct audit_context *);
143146
#else
144-
#define audit_signal_info(s,t)
147+
#define audit_signal_info(s,t) AUDIT_DISABLED
145148
#define audit_filter_inodes(t,c) AUDIT_DISABLED
146149
#define audit_set_auditable(c)
147150
#endif

‎kernel/auditfilter.c‎

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,43 @@ int audit_match_class(int class, unsigned syscall)
311311
return classes[class][AUDIT_WORD(syscall)] & AUDIT_BIT(syscall);
312312
}
313313

314+
static inline int audit_match_class_bits(int class, u32 *mask)
315+
{
316+
int i;
317+
318+
if (classes[class]) {
319+
for (i = 0; i < AUDIT_BITMASK_SIZE; i++)
320+
if (mask[i] & classes[class][i])
321+
return 0;
322+
}
323+
return 1;
324+
}
325+
326+
static int audit_match_signal(struct audit_entry *entry)
327+
{
328+
struct audit_field *arch = entry->rule.arch_f;
329+
330+
if (!arch) {
331+
/* When arch is unspecified, we must check both masks on biarch
332+
* as syscall number alone is ambiguous. */
333+
return (audit_match_class_bits(AUDIT_CLASS_SIGNAL,
334+
entry->rule.mask) &&
335+
audit_match_class_bits(AUDIT_CLASS_SIGNAL_32,
336+
entry->rule.mask));
337+
}
338+
339+
switch(audit_classify_arch(arch->val)) {
340+
case 0: /* native */
341+
return (audit_match_class_bits(AUDIT_CLASS_SIGNAL,
342+
entry->rule.mask));
343+
case 1: /* 32bit on biarch */
344+
return (audit_match_class_bits(AUDIT_CLASS_SIGNAL_32,
345+
entry->rule.mask));
346+
default:
347+
return 1;
348+
}
349+
}
350+
314351
/* Common user-space to kernel rule translation. */
315352
static inline struct audit_entry *audit_to_entry_common(struct audit_rule *rule)
316353
{
@@ -429,6 +466,7 @@ static struct audit_entry *audit_rule_to_entry(struct audit_rule *rule)
429466
err = -EINVAL;
430467
goto exit_free;
431468
}
469+
entry->rule.arch_f = f;
432470
break;
433471
case AUDIT_PERM:
434472
if (f->val & ~15)
@@ -519,7 +557,6 @@ static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data,
519557
case AUDIT_FSGID:
520558
case AUDIT_LOGINUID:
521559
case AUDIT_PERS:
522-
case AUDIT_ARCH:
523560
case AUDIT_MSGTYPE:
524561
case AUDIT_PPID:
525562
case AUDIT_DEVMAJOR:
@@ -531,6 +568,9 @@ static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data,
531568
case AUDIT_ARG2:
532569
case AUDIT_ARG3:
533570
break;
571+
case AUDIT_ARCH:
572+
entry->rule.arch_f = f;
573+
break;
534574
case AUDIT_SUBJ_USER:
535575
case AUDIT_SUBJ_ROLE:
536576
case AUDIT_SUBJ_TYPE:
@@ -1221,6 +1261,9 @@ static inline int audit_add_rule(struct audit_entry *entry,
12211261
#ifdef CONFIG_AUDITSYSCALL
12221262
if (!dont_count)
12231263
audit_n_rules++;
1264+
1265+
if (!audit_match_signal(entry))
1266+
audit_signals++;
12241267
#endif
12251268
mutex_unlock(&audit_filter_mutex);
12261269

@@ -1294,6 +1337,9 @@ static inline int audit_del_rule(struct audit_entry *entry,
12941337
#ifdef CONFIG_AUDITSYSCALL
12951338
if (!dont_count)
12961339
audit_n_rules--;
1340+
1341+
if (!audit_match_signal(entry))
1342+
audit_signals--;
12971343
#endif
12981344
mutex_unlock(&audit_filter_mutex);
12991345

0 commit comments

Comments
 (0)