From be4187faa8a48cfef572eba9e3882fb2134bdf67 Mon Sep 17 00:00:00 2001 From: Xiu Jianfeng Date: Thu, 20 Jul 2023 01:50:32 +0000 Subject: audit: include security.h unconditionally The ifdef-else logic is already in the header file, so include it unconditionally, no functional changes here. Signed-off-by: Xiu Jianfeng [PM: fixed misspelling in the subject] Signed-off-by: Paul Moore --- kernel/audit.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/kernel/audit.c b/kernel/audit.c index 9bc0b0301198..45b2fb1e45af 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -53,9 +53,7 @@ #include #include #include -#ifdef CONFIG_SECURITY #include -#endif #include #include #include -- cgit From bf98354280bff22bc9e57c698d485c9e1c0b04f3 Mon Sep 17 00:00:00 2001 From: Xiu Jianfeng Date: Fri, 21 Jul 2023 11:21:01 +0000 Subject: audit: correct audit_filter_inodes() definition After changes in commit 0590b9335a1c ("fixing audit rule ordering mess, part 1"), audit_filter_inodes() returns void, so if CONFIG_AUDITSYSCALL not defined, it should be do {} while(0). Signed-off-by: Xiu Jianfeng Signed-off-by: Paul Moore --- kernel/audit.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/audit.h b/kernel/audit.h index 94738bce40b2..a60d2840559e 100644 --- a/kernel/audit.h +++ b/kernel/audit.h @@ -334,7 +334,7 @@ static inline int audit_signal_info_syscall(struct task_struct *t) return 0; } -#define audit_filter_inodes(t, c) AUDIT_STATE_DISABLED +#define audit_filter_inodes(t, c) do { } while (0) #endif /* CONFIG_AUDITSYSCALL */ extern char *audit_unpack_string(void **bufp, size_t *remain, size_t len); -- cgit From b59bc6e37237e37eadf50cd5de369e913f524463 Mon Sep 17 00:00:00 2001 From: Gaosheng Cui Date: Tue, 8 Aug 2023 20:14:35 +0800 Subject: audit: fix possible soft lockup in __audit_inode_child() Tracefs or debugfs maybe cause hundreds to thousands of PATH records, too many PATH records maybe cause soft lockup. For example: 1. CONFIG_KASAN=y && CONFIG_PREEMPTION=n 2. auditctl -a exit,always -S open -k key 3. sysctl -w kernel.watchdog_thresh=5 4. mkdir /sys/kernel/debug/tracing/instances/test There may be a soft lockup as follows: watchdog: BUG: soft lockup - CPU#45 stuck for 7s! [mkdir:15498] Kernel panic - not syncing: softlockup: hung tasks Call trace: dump_backtrace+0x0/0x30c show_stack+0x20/0x30 dump_stack+0x11c/0x174 panic+0x27c/0x494 watchdog_timer_fn+0x2bc/0x390 __run_hrtimer+0x148/0x4fc __hrtimer_run_queues+0x154/0x210 hrtimer_interrupt+0x2c4/0x760 arch_timer_handler_phys+0x48/0x60 handle_percpu_devid_irq+0xe0/0x340 __handle_domain_irq+0xbc/0x130 gic_handle_irq+0x78/0x460 el1_irq+0xb8/0x140 __audit_inode_child+0x240/0x7bc tracefs_create_file+0x1b8/0x2a0 trace_create_file+0x18/0x50 event_create_dir+0x204/0x30c __trace_add_new_event+0xac/0x100 event_trace_add_tracer+0xa0/0x130 trace_array_create_dir+0x60/0x140 trace_array_create+0x1e0/0x370 instance_mkdir+0x90/0xd0 tracefs_syscall_mkdir+0x68/0xa0 vfs_mkdir+0x21c/0x34c do_mkdirat+0x1b4/0x1d4 __arm64_sys_mkdirat+0x4c/0x60 el0_svc_common.constprop.0+0xa8/0x240 do_el0_svc+0x8c/0xc0 el0_svc+0x20/0x30 el0_sync_handler+0xb0/0xb4 el0_sync+0x160/0x180 Therefore, we add cond_resched() to __audit_inode_child() to fix it. Fixes: 5195d8e217a7 ("audit: dynamically allocate audit_names when not enough space is in the names array") Signed-off-by: Gaosheng Cui Signed-off-by: Paul Moore --- kernel/auditsc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index addeed3df15d..8dfd581cd554 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2456,6 +2456,8 @@ void __audit_inode_child(struct inode *parent, } } + cond_resched(); + /* is there a matching child entry? */ list_for_each_entry(n, &context->names_list, list) { /* can only match entries that have a name */ -- cgit From 62acadda115a94bffd1f6b36acbb67e3f04811be Mon Sep 17 00:00:00 2001 From: Atul Kumar Pant Date: Wed, 16 Aug 2023 02:15:53 +0530 Subject: audit: add space before parenthesis and around '=', "==", and '<' Fixes following checkpatch.pl issue: ERROR: space required before the open parenthesis '(' ERROR: spaces required around that '=' ERROR: spaces required around that '<' ERROR: spaces required around that '==' Signed-off-by: Atul Kumar Pant [PM: subject line tweaks] Signed-off-by: Paul Moore --- kernel/acct.c | 2 +- kernel/auditfilter.c | 16 ++++++++-------- kernel/auditsc.c | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/kernel/acct.c b/kernel/acct.c index 010667ce6080..c95a9359f209 100644 --- a/kernel/acct.c +++ b/kernel/acct.c @@ -470,7 +470,7 @@ static void fill_ac(acct_t *ac) do_div(elapsed, AHZ); btime = ktime_get_real_seconds() - elapsed; ac->ac_btime = clamp_t(time64_t, btime, 0, U32_MAX); -#if ACCT_VERSION==2 +#if ACCT_VERSION == 2 ac->ac_ahz = AHZ; #endif diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c index 42d99896e7a6..12320120bb00 100644 --- a/kernel/auditfilter.c +++ b/kernel/auditfilter.c @@ -221,7 +221,7 @@ static int audit_match_signal(struct audit_entry *entry) entry->rule.mask)); } - switch(audit_classify_arch(arch->val)) { + switch (audit_classify_arch(arch->val)) { case 0: /* native */ return (audit_match_class_bits(AUDIT_CLASS_SIGNAL, entry->rule.mask)); @@ -243,7 +243,7 @@ static inline struct audit_entry *audit_to_entry_common(struct audit_rule_data * err = -EINVAL; listnr = rule->flags & ~AUDIT_FILTER_PREPEND; - switch(listnr) { + switch (listnr) { default: goto exit_err; #ifdef CONFIG_AUDITSYSCALL @@ -344,7 +344,7 @@ static int audit_field_valid(struct audit_entry *entry, struct audit_field *f) switch (entry->rule.listnr) { case AUDIT_FILTER_FS: - switch(f->type) { + switch (f->type) { case AUDIT_FSTYPE: case AUDIT_FILTERKEY: break; @@ -651,7 +651,7 @@ static struct audit_rule_data *audit_krule_to_data(struct audit_krule *krule) data->fields[i] = f->type; data->fieldflags[i] = audit_ops[f->op]; - switch(f->type) { + switch (f->type) { case AUDIT_SUBJ_USER: case AUDIT_SUBJ_ROLE: case AUDIT_SUBJ_TYPE: @@ -717,7 +717,7 @@ static int audit_compare_rule(struct audit_krule *a, struct audit_krule *b) a->fields[i].op != b->fields[i].op) return 1; - switch(a->fields[i].type) { + switch (a->fields[i].type) { case AUDIT_SUBJ_USER: case AUDIT_SUBJ_ROLE: case AUDIT_SUBJ_TYPE: @@ -946,7 +946,7 @@ static inline int audit_add_rule(struct audit_entry *entry) int dont_count = 0; /* If any of these, don't count towards total */ - switch(entry->rule.listnr) { + switch (entry->rule.listnr) { case AUDIT_FILTER_USER: case AUDIT_FILTER_EXCLUDE: case AUDIT_FILTER_FS: @@ -1029,7 +1029,7 @@ int audit_del_rule(struct audit_entry *entry) int dont_count = 0; /* If any of these, don't count towards total */ - switch(entry->rule.listnr) { + switch (entry->rule.listnr) { case AUDIT_FILTER_USER: case AUDIT_FILTER_EXCLUDE: case AUDIT_FILTER_FS: @@ -1083,7 +1083,7 @@ static void audit_list_rules(int seq, struct sk_buff_head *q) /* This is a blocking read, so use audit_filter_mutex instead of rcu * iterator to sync with list writers. */ - for (i=0; ii_fsnotify_marks)) { -- cgit From 22cde1012f6a6509656f976cbe3aa5f4c5d0f1a3 Mon Sep 17 00:00:00 2001 From: Atul Kumar Pant Date: Wed, 16 Aug 2023 02:16:44 +0530 Subject: audit: cleanup function braces and assignment-in-if-condition The patch fixes following checkpatch.pl issue: ERROR: open brace '{' following function definitions go on the next line ERROR: do not use assignment in if condition Signed-off-by: Atul Kumar Pant [PM: subject line tweaks] Signed-off-by: Paul Moore --- kernel/auditsc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index e89d397f2148..b0cb7631e48b 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -880,7 +880,8 @@ static void audit_filter_syscall(struct task_struct *tsk, */ static int audit_filter_inode_name(struct task_struct *tsk, struct audit_names *n, - struct audit_context *ctx) { + struct audit_context *ctx) +{ int h = audit_hash_ino((u32)n->ino); struct list_head *list = &audit_inode_hash[h]; @@ -1064,7 +1065,8 @@ int audit_alloc(struct task_struct *tsk) return 0; } - if (!(context = audit_alloc_context(state))) { + context = audit_alloc_context(state); + if (!context) { kfree(key); audit_log_lost("out of memory in audit_alloc"); return -ENOMEM; -- cgit From b1a0f64cc65ea2ebfaae9e0ce623e993a7d24257 Mon Sep 17 00:00:00 2001 From: Atul Kumar Pant Date: Wed, 16 Aug 2023 02:17:51 +0530 Subject: audit: move trailing statements to next line Fixes following checkpatch.pl issue: ERROR: trailing statements should be on next line Signed-off-by: Atul Kumar Pant [PM: subject line tweak] Signed-off-by: Paul Moore --- kernel/audit.c | 3 ++- kernel/auditfilter.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/audit.c b/kernel/audit.c index 45b2fb1e45af..16205dd29843 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -321,7 +321,8 @@ static inline int audit_rate_check(void) unsigned long now; int retval = 0; - if (!audit_rate_limit) return 1; + if (!audit_rate_limit) + return 1; spin_lock_irqsave(&lock, flags); if (++messages < audit_rate_limit) { diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c index 12320120bb00..8317a37dea0b 100644 --- a/kernel/auditfilter.c +++ b/kernel/auditfilter.c @@ -694,7 +694,8 @@ static struct audit_rule_data *audit_krule_to_data(struct audit_krule *krule) data->values[i] = f->val; } } - for (i = 0; i < AUDIT_BITMASK_SIZE; i++) data->mask[i] = krule->mask[i]; + for (i = 0; i < AUDIT_BITMASK_SIZE; i++) + data->mask[i] = krule->mask[i]; return data; } -- cgit