Skip to content

Commit 3e3b830

Browse files
committed
Merge: audit: backport kernel audit enhancements and fixes up to upstream v6.6
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/3216 JIRA: https://issues.redhat.com/browse/RHEL-9127 Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=57449883 Backport selected trivial fixes, cleanups, and enhancements from upstream up to version 6.6. This will help make Audit functionality more stable, bring useful enhancements/fixes downstream, and ease future backports. Ricardo Robaina (15): audit: include security.h unconditionally audit: correct audit_filter_inodes() definition audit: fix possible soft lockup in __audit_inode_child() audit: add space before parenthesis and around '=', "==", and '<' audit: cleanup function braces and assignment-in-if-condition audit: move trailing statements to next line netfilter: nf_tables: Audit log setelem reset netfilter: nf_tables: Audit log rule reset netfilter: nf_tables: Unbreak audit log reset netfilter: nf_tables: Fix entries val in rule reset audit log selftests: netfilter: Test nf_tables audit logging selftests: netfilter: Extend nft_audit.sh netfilter: nf_tables: Deduplicate nft_register_obj audit logs netfilter: nf_tables: audit log object reset once per table selftests: netfilter: Run nft_audit.sh in its own netns include/linux/audit.h | 2 + kernel/acct.c | 2 +- kernel/audit.c | 5 +- kernel/audit.h | 2 +- kernel/auditfilter.c | 19 +- kernel/auditsc.c | 12 +- net/netfilter/nf_tables_api.c | 160 ++++++++---- tools/testing/selftests/netfilter/.gitignore | 1 + tools/testing/selftests/netfilter/Makefile | 4 +- .../selftests/netfilter/audit_logread.c | 165 ++++++++++++ tools/testing/selftests/netfilter/config | 1 + .../testing/selftests/netfilter/nft_audit.sh | 245 ++++++++++++++++++ 12 files changed, 552 insertions(+), 66 deletions(-) create mode 100644 tools/testing/selftests/netfilter/audit_logread.c create mode 100644 tools/testing/selftests/netfilter/nft_audit.sh Signed-off-by: Ricardo Robaina <[email protected]> Approved-by: Florian Westphal <[email protected]> Approved-by: John B. Wyatt IV <[email protected]> Signed-off-by: Scott Weaver <[email protected]>
2 parents dc61077 + 466399f commit 3e3b830

File tree

12 files changed

+552
-66
lines changed

12 files changed

+552
-66
lines changed

include/linux/audit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ enum audit_nfcfgop {
117117
AUDIT_NFT_OP_OBJ_RESET,
118118
AUDIT_NFT_OP_FLOWTABLE_REGISTER,
119119
AUDIT_NFT_OP_FLOWTABLE_UNREGISTER,
120+
AUDIT_NFT_OP_SETELEM_RESET,
121+
AUDIT_NFT_OP_RULE_RESET,
120122
AUDIT_NFT_OP_INVALID,
121123
};
122124

kernel/acct.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ static void fill_ac(acct_t *ac)
448448
do_div(elapsed, AHZ);
449449
btime = ktime_get_real_seconds() - elapsed;
450450
ac->ac_btime = clamp_t(time64_t, btime, 0, U32_MAX);
451-
#if ACCT_VERSION==2
451+
#if ACCT_VERSION == 2
452452
ac->ac_ahz = AHZ;
453453
#endif
454454

kernel/audit.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@
5353
#include <net/sock.h>
5454
#include <net/netlink.h>
5555
#include <linux/skbuff.h>
56-
#ifdef CONFIG_SECURITY
5756
#include <linux/security.h>
58-
#endif
5957
#include <linux/freezer.h>
6058
#include <linux/pid_namespace.h>
6159
#include <net/netns/generic.h>
@@ -323,7 +321,8 @@ static inline int audit_rate_check(void)
323321
unsigned long now;
324322
int retval = 0;
325323

326-
if (!audit_rate_limit) return 1;
324+
if (!audit_rate_limit)
325+
return 1;
327326

328327
spin_lock_irqsave(&lock, flags);
329328
if (++messages < audit_rate_limit) {

kernel/audit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ static inline int audit_signal_info_syscall(struct task_struct *t)
334334
return 0;
335335
}
336336

337-
#define audit_filter_inodes(t, c) AUDIT_STATE_DISABLED
337+
#define audit_filter_inodes(t, c) do { } while (0)
338338
#endif /* CONFIG_AUDITSYSCALL */
339339

340340
extern char *audit_unpack_string(void **bufp, size_t *remain, size_t len);

kernel/auditfilter.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static int audit_match_signal(struct audit_entry *entry)
221221
entry->rule.mask));
222222
}
223223

224-
switch(audit_classify_arch(arch->val)) {
224+
switch (audit_classify_arch(arch->val)) {
225225
case 0: /* native */
226226
return (audit_match_class_bits(AUDIT_CLASS_SIGNAL,
227227
entry->rule.mask));
@@ -243,7 +243,7 @@ static inline struct audit_entry *audit_to_entry_common(struct audit_rule_data *
243243

244244
err = -EINVAL;
245245
listnr = rule->flags & ~AUDIT_FILTER_PREPEND;
246-
switch(listnr) {
246+
switch (listnr) {
247247
default:
248248
goto exit_err;
249249
#ifdef CONFIG_AUDITSYSCALL
@@ -344,7 +344,7 @@ static int audit_field_valid(struct audit_entry *entry, struct audit_field *f)
344344

345345
switch (entry->rule.listnr) {
346346
case AUDIT_FILTER_FS:
347-
switch(f->type) {
347+
switch (f->type) {
348348
case AUDIT_FSTYPE:
349349
case AUDIT_FILTERKEY:
350350
break;
@@ -651,7 +651,7 @@ static struct audit_rule_data *audit_krule_to_data(struct audit_krule *krule)
651651

652652
data->fields[i] = f->type;
653653
data->fieldflags[i] = audit_ops[f->op];
654-
switch(f->type) {
654+
switch (f->type) {
655655
case AUDIT_SUBJ_USER:
656656
case AUDIT_SUBJ_ROLE:
657657
case AUDIT_SUBJ_TYPE:
@@ -694,7 +694,8 @@ static struct audit_rule_data *audit_krule_to_data(struct audit_krule *krule)
694694
data->values[i] = f->val;
695695
}
696696
}
697-
for (i = 0; i < AUDIT_BITMASK_SIZE; i++) data->mask[i] = krule->mask[i];
697+
for (i = 0; i < AUDIT_BITMASK_SIZE; i++)
698+
data->mask[i] = krule->mask[i];
698699

699700
return data;
700701
}
@@ -717,7 +718,7 @@ static int audit_compare_rule(struct audit_krule *a, struct audit_krule *b)
717718
a->fields[i].op != b->fields[i].op)
718719
return 1;
719720

720-
switch(a->fields[i].type) {
721+
switch (a->fields[i].type) {
721722
case AUDIT_SUBJ_USER:
722723
case AUDIT_SUBJ_ROLE:
723724
case AUDIT_SUBJ_TYPE:
@@ -946,7 +947,7 @@ static inline int audit_add_rule(struct audit_entry *entry)
946947
int dont_count = 0;
947948

948949
/* If any of these, don't count towards total */
949-
switch(entry->rule.listnr) {
950+
switch (entry->rule.listnr) {
950951
case AUDIT_FILTER_USER:
951952
case AUDIT_FILTER_EXCLUDE:
952953
case AUDIT_FILTER_FS:
@@ -1029,7 +1030,7 @@ int audit_del_rule(struct audit_entry *entry)
10291030
int dont_count = 0;
10301031

10311032
/* If any of these, don't count towards total */
1032-
switch(entry->rule.listnr) {
1033+
switch (entry->rule.listnr) {
10331034
case AUDIT_FILTER_USER:
10341035
case AUDIT_FILTER_EXCLUDE:
10351036
case AUDIT_FILTER_FS:
@@ -1083,7 +1084,7 @@ static void audit_list_rules(int seq, struct sk_buff_head *q)
10831084

10841085
/* This is a blocking read, so use audit_filter_mutex instead of rcu
10851086
* iterator to sync with list writers. */
1086-
for (i=0; i<AUDIT_NR_FILTERS; i++) {
1087+
for (i = 0; i < AUDIT_NR_FILTERS; i++) {
10871088
list_for_each_entry(r, &audit_rules_list[i], list) {
10881089
struct audit_rule_data *data;
10891090

kernel/auditsc.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ static const struct audit_nfcfgop_tab audit_nfcfgs[] = {
143143
{ AUDIT_NFT_OP_OBJ_RESET, "nft_reset_obj" },
144144
{ AUDIT_NFT_OP_FLOWTABLE_REGISTER, "nft_register_flowtable" },
145145
{ AUDIT_NFT_OP_FLOWTABLE_UNREGISTER, "nft_unregister_flowtable" },
146+
{ AUDIT_NFT_OP_SETELEM_RESET, "nft_reset_setelem" },
147+
{ AUDIT_NFT_OP_RULE_RESET, "nft_reset_rule" },
146148
{ AUDIT_NFT_OP_INVALID, "nft_invalid" },
147149
};
148150

@@ -880,7 +882,8 @@ static void audit_filter_syscall(struct task_struct *tsk,
880882
*/
881883
static int audit_filter_inode_name(struct task_struct *tsk,
882884
struct audit_names *n,
883-
struct audit_context *ctx) {
885+
struct audit_context *ctx)
886+
{
884887
int h = audit_hash_ino((u32)n->ino);
885888
struct list_head *list = &audit_inode_hash[h];
886889

@@ -1064,7 +1067,8 @@ int audit_alloc(struct task_struct *tsk)
10641067
return 0;
10651068
}
10661069

1067-
if (!(context = audit_alloc_context(state))) {
1070+
context = audit_alloc_context(state);
1071+
if (!context) {
10681072
kfree(key);
10691073
audit_log_lost("out of memory in audit_alloc");
10701074
return -ENOMEM;
@@ -2128,7 +2132,7 @@ static void handle_path(const struct dentry *dentry)
21282132
d = dentry;
21292133
rcu_read_lock();
21302134
seq = read_seqbegin(&rename_lock);
2131-
for(;;) {
2135+
for (;;) {
21322136
struct inode *inode = d_backing_inode(d);
21332137

21342138
if (inode && unlikely(inode->i_fsnotify_marks)) {
@@ -2460,6 +2464,8 @@ void __audit_inode_child(struct inode *parent,
24602464
}
24612465
}
24622466

2467+
cond_resched();
2468+
24632469
/* is there a matching child entry? */
24642470
list_for_each_entry(n, &context->names_list, list) {
24652471
/* can only match entries that have a name */

0 commit comments

Comments
 (0)