Skip to content

Commit 42d5e37

Browse files
rgbriggspcmoore
authored andcommitted
audit: filter PATH records keyed on filesystem magic
Tracefs or debugfs were causing hundreds to thousands of PATH records to be associated with the init_module and finit_module SYSCALL records on a few modules when the following rule was in place for startup: -a always,exit -F arch=x86_64 -S init_module -F key=mod-load Provide a method to ignore these large number of PATH records from overwhelming the logs if they are not of interest. Introduce a new filter list "AUDIT_FILTER_FS", with a new field type AUDIT_FSTYPE, which keys off the filesystem 4-octet hexadecimal magic identifier to filter specific filesystem PATH records. An example rule would look like: -a never,filesystem -F fstype=0x74726163 -F key=ignore_tracefs -a never,filesystem -F fstype=0x64626720 -F key=ignore_debugfs Arguably the better way to address this issue is to disable tracefs and debugfs on boot from production systems. See: linux-audit/audit-kernel#16 See: linux-audit/audit-userspace#8 Test case: linux-audit/audit-testsuite#42 Signed-off-by: Richard Guy Briggs <rgb@redhat.com> [PM: fixed the whitespace damage in kernel/auditsc.c] Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent f7b5363 commit 42d5e37

3 files changed

Lines changed: 61 additions & 9 deletions

File tree

‎include/uapi/linux/audit.h‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@
155155
#define AUDIT_FILTER_WATCH 0x03 /* Apply rule to file system watches */
156156
#define AUDIT_FILTER_EXIT 0x04 /* Apply rule at syscall exit */
157157
#define AUDIT_FILTER_TYPE 0x05 /* Apply rule at audit_log_start */
158+
#define AUDIT_FILTER_FS 0x06 /* Apply rule at __audit_inode_child */
158159

159-
#define AUDIT_NR_FILTERS 6
160+
#define AUDIT_NR_FILTERS 7
160161

161162
#define AUDIT_FILTER_PREPEND 0x10 /* Prepend to front of list */
162163

@@ -256,6 +257,7 @@
256257
#define AUDIT_OBJ_LEV_HIGH 23
257258
#define AUDIT_LOGINUID_SET 24
258259
#define AUDIT_SESSIONID 25 /* Session ID */
260+
#define AUDIT_FSTYPE 26 /* FileSystem Type */
259261

260262
/* These are ONLY useful when checking
261263
* at syscall exit time (AUDIT_AT_EXIT). */
@@ -335,13 +337,15 @@ enum {
335337
#define AUDIT_FEATURE_BITMAP_EXCLUDE_EXTEND 0x00000008
336338
#define AUDIT_FEATURE_BITMAP_SESSIONID_FILTER 0x00000010
337339
#define AUDIT_FEATURE_BITMAP_LOST_RESET 0x00000020
340+
#define AUDIT_FEATURE_BITMAP_FILTER_FS 0x00000040
338341

339342
#define AUDIT_FEATURE_BITMAP_ALL (AUDIT_FEATURE_BITMAP_BACKLOG_LIMIT | \
340343
AUDIT_FEATURE_BITMAP_BACKLOG_WAIT_TIME | \
341344
AUDIT_FEATURE_BITMAP_EXECUTABLE_PATH | \
342345
AUDIT_FEATURE_BITMAP_EXCLUDE_EXTEND | \
343346
AUDIT_FEATURE_BITMAP_SESSIONID_FILTER | \
344-
AUDIT_FEATURE_BITMAP_LOST_RESET)
347+
AUDIT_FEATURE_BITMAP_LOST_RESET | \
348+
AUDIT_FEATURE_BITMAP_FILTER_FS)
345349

346350
/* deprecated: AUDIT_VERSION_* */
347351
#define AUDIT_VERSION_LATEST AUDIT_FEATURE_BITMAP_ALL

‎kernel/auditfilter.c‎

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ struct list_head audit_filter_list[AUDIT_NR_FILTERS] = {
5656
LIST_HEAD_INIT(audit_filter_list[3]),
5757
LIST_HEAD_INIT(audit_filter_list[4]),
5858
LIST_HEAD_INIT(audit_filter_list[5]),
59-
#if AUDIT_NR_FILTERS != 6
59+
LIST_HEAD_INIT(audit_filter_list[6]),
60+
#if AUDIT_NR_FILTERS != 7
6061
#error Fix audit_filter_list initialiser
6162
#endif
6263
};
@@ -67,6 +68,7 @@ static struct list_head audit_rules_list[AUDIT_NR_FILTERS] = {
6768
LIST_HEAD_INIT(audit_rules_list[3]),
6869
LIST_HEAD_INIT(audit_rules_list[4]),
6970
LIST_HEAD_INIT(audit_rules_list[5]),
71+
LIST_HEAD_INIT(audit_rules_list[6]),
7072
};
7173

7274
DEFINE_MUTEX(audit_filter_mutex);
@@ -263,6 +265,7 @@ static inline struct audit_entry *audit_to_entry_common(struct audit_rule_data *
263265
#endif
264266
case AUDIT_FILTER_USER:
265267
case AUDIT_FILTER_TYPE:
268+
case AUDIT_FILTER_FS:
266269
;
267270
}
268271
if (unlikely(rule->action == AUDIT_POSSIBLE)) {
@@ -338,6 +341,21 @@ static int audit_field_valid(struct audit_entry *entry, struct audit_field *f)
338341
entry->rule.listnr != AUDIT_FILTER_USER)
339342
return -EINVAL;
340343
break;
344+
case AUDIT_FSTYPE:
345+
if (entry->rule.listnr != AUDIT_FILTER_FS)
346+
return -EINVAL;
347+
break;
348+
}
349+
350+
switch(entry->rule.listnr) {
351+
case AUDIT_FILTER_FS:
352+
switch(f->type) {
353+
case AUDIT_FSTYPE:
354+
case AUDIT_FILTERKEY:
355+
break;
356+
default:
357+
return -EINVAL;
358+
}
341359
}
342360

343361
switch(f->type) {
@@ -391,6 +409,7 @@ static int audit_field_valid(struct audit_entry *entry, struct audit_field *f)
391409
return -EINVAL;
392410
/* FALL THROUGH */
393411
case AUDIT_ARCH:
412+
case AUDIT_FSTYPE:
394413
if (f->op != Audit_not_equal && f->op != Audit_equal)
395414
return -EINVAL;
396415
break;
@@ -910,10 +929,13 @@ static inline int audit_add_rule(struct audit_entry *entry)
910929
#ifdef CONFIG_AUDITSYSCALL
911930
int dont_count = 0;
912931

913-
/* If either of these, don't count towards total */
914-
if (entry->rule.listnr == AUDIT_FILTER_USER ||
915-
entry->rule.listnr == AUDIT_FILTER_TYPE)
932+
/* If any of these, don't count towards total */
933+
switch(entry->rule.listnr) {
934+
case AUDIT_FILTER_USER:
935+
case AUDIT_FILTER_TYPE:
936+
case AUDIT_FILTER_FS:
916937
dont_count = 1;
938+
}
917939
#endif
918940

919941
mutex_lock(&audit_filter_mutex);
@@ -989,10 +1011,13 @@ int audit_del_rule(struct audit_entry *entry)
9891011
#ifdef CONFIG_AUDITSYSCALL
9901012
int dont_count = 0;
9911013

992-
/* If either of these, don't count towards total */
993-
if (entry->rule.listnr == AUDIT_FILTER_USER ||
994-
entry->rule.listnr == AUDIT_FILTER_TYPE)
1014+
/* If any of these, don't count towards total */
1015+
switch(entry->rule.listnr) {
1016+
case AUDIT_FILTER_USER:
1017+
case AUDIT_FILTER_TYPE:
1018+
case AUDIT_FILTER_FS:
9951019
dont_count = 1;
1020+
}
9961021
#endif
9971022

9981023
mutex_lock(&audit_filter_mutex);

‎kernel/auditsc.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,10 +1869,33 @@ void __audit_inode_child(struct inode *parent,
18691869
struct inode *inode = d_backing_inode(dentry);
18701870
const char *dname = dentry->d_name.name;
18711871
struct audit_names *n, *found_parent = NULL, *found_child = NULL;
1872+
struct audit_entry *e;
1873+
struct list_head *list = &audit_filter_list[AUDIT_FILTER_FS];
1874+
int i;
18721875

18731876
if (!context->in_syscall)
18741877
return;
18751878

1879+
rcu_read_lock();
1880+
if (!list_empty(list)) {
1881+
list_for_each_entry_rcu(e, list, list) {
1882+
for (i = 0; i < e->rule.field_count; i++) {
1883+
struct audit_field *f = &e->rule.fields[i];
1884+
1885+
if (f->type == AUDIT_FSTYPE) {
1886+
if (audit_comparator(parent->i_sb->s_magic,
1887+
f->op, f->val)) {
1888+
if (e->rule.action == AUDIT_NEVER) {
1889+
rcu_read_unlock();
1890+
return;
1891+
}
1892+
}
1893+
}
1894+
}
1895+
}
1896+
}
1897+
rcu_read_unlock();
1898+
18761899
if (inode)
18771900
handle_one(inode);
18781901

0 commit comments

Comments
 (0)