Skip to content

Commit c4dad0a

Browse files
rgbriggspcmoore
authored andcommitted
audit: tidy and extend netfilter_cfg x_tables
NETFILTER_CFG record generation was inconsistent for x_tables and ebtables configuration changes. The call was needlessly messy and there were supporting records missing at times while they were produced when not requested. Simplify the logging call into a new audit_log_nfcfg call. Honour the audit_enabled setting while more consistently recording information including supporting records by tidying up dummy checks. Add an op= field that indicates the operation being performed (register or replace). Here is the enhanced sample record: type=NETFILTER_CFG msg=audit(1580905834.919:82970): table=filter family=2 entries=83 op=replace Generate audit NETFILTER_CFG records on ebtables table registration. Previously this was being done for x_tables registration and replacement operations and ebtables table replacement only. See: linux-audit/audit-kernel#25 See: linux-audit/audit-kernel#35 See: linux-audit/audit-kernel#43 Signed-off-by: Richard Guy Briggs <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 9d2161b commit c4dad0a

File tree

4 files changed

+52
-17
lines changed

4 files changed

+52
-17
lines changed

include/linux/audit.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ struct audit_ntp_data {
9494
struct audit_ntp_data {};
9595
#endif
9696

97+
enum audit_nfcfgop {
98+
AUDIT_XT_OP_REGISTER,
99+
AUDIT_XT_OP_REPLACE,
100+
};
101+
97102
extern int is_audit_feature_set(int which);
98103

99104
extern int __init audit_register_class(int class, unsigned *list);
@@ -379,6 +384,8 @@ extern void __audit_log_kern_module(char *name);
379384
extern void __audit_fanotify(unsigned int response);
380385
extern void __audit_tk_injoffset(struct timespec64 offset);
381386
extern void __audit_ntp_log(const struct audit_ntp_data *ad);
387+
extern void __audit_log_nfcfg(const char *name, u8 af, unsigned int nentries,
388+
enum audit_nfcfgop op);
382389

383390
static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
384391
{
@@ -514,6 +521,14 @@ static inline void audit_ntp_log(const struct audit_ntp_data *ad)
514521
__audit_ntp_log(ad);
515522
}
516523

524+
static inline void audit_log_nfcfg(const char *name, u8 af,
525+
unsigned int nentries,
526+
enum audit_nfcfgop op)
527+
{
528+
if (audit_enabled)
529+
__audit_log_nfcfg(name, af, nentries, op);
530+
}
531+
517532
extern int audit_n_rules;
518533
extern int audit_signals;
519534
#else /* CONFIG_AUDITSYSCALL */
@@ -646,6 +661,12 @@ static inline void audit_ntp_log(const struct audit_ntp_data *ad)
646661

647662
static inline void audit_ptrace(struct task_struct *t)
648663
{ }
664+
665+
static inline void audit_log_nfcfg(const char *name, u8 af,
666+
unsigned int nentries,
667+
enum audit_nfcfgop op)
668+
{ }
669+
649670
#define audit_n_rules 0
650671
#define audit_signals 0
651672
#endif /* CONFIG_AUDITSYSCALL */

kernel/auditsc.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ struct audit_tree_refs {
130130
struct audit_chunk *c[31];
131131
};
132132

133+
struct audit_nfcfgop_tab {
134+
enum audit_nfcfgop op;
135+
const char *s;
136+
};
137+
138+
const struct audit_nfcfgop_tab audit_nfcfgs[] = {
139+
{ AUDIT_XT_OP_REGISTER, "register" },
140+
{ AUDIT_XT_OP_REPLACE, "replace" },
141+
};
142+
133143
static int audit_match_perm(struct audit_context *ctx, int mask)
134144
{
135145
unsigned n;
@@ -2542,6 +2552,20 @@ void __audit_ntp_log(const struct audit_ntp_data *ad)
25422552
audit_log_ntp_val(ad, "adjust", AUDIT_NTP_ADJUST);
25432553
}
25442554

2555+
void __audit_log_nfcfg(const char *name, u8 af, unsigned int nentries,
2556+
enum audit_nfcfgop op)
2557+
{
2558+
struct audit_buffer *ab;
2559+
2560+
ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_NETFILTER_CFG);
2561+
if (!ab)
2562+
return;
2563+
audit_log_format(ab, "table=%s family=%u entries=%u op=%s",
2564+
name, af, nentries, audit_nfcfgs[op].s);
2565+
audit_log_end(ab);
2566+
}
2567+
EXPORT_SYMBOL_GPL(__audit_log_nfcfg);
2568+
25452569
static void audit_log_task(struct audit_buffer *ab)
25462570
{
25472571
kuid_t auid, uid;

net/bridge/netfilter/ebtables.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,14 +1046,8 @@ static int do_replace_finish(struct net *net, struct ebt_replace *repl,
10461046
vfree(table);
10471047
vfree(counterstmp);
10481048

1049-
#ifdef CONFIG_AUDIT
1050-
if (audit_enabled) {
1051-
audit_log(audit_context(), GFP_KERNEL,
1052-
AUDIT_NETFILTER_CFG,
1053-
"table=%s family=%u entries=%u",
1054-
repl->name, AF_BRIDGE, repl->nentries);
1055-
}
1056-
#endif
1049+
audit_log_nfcfg(repl->name, AF_BRIDGE, repl->nentries,
1050+
AUDIT_XT_OP_REPLACE);
10571051
return ret;
10581052

10591053
free_unlock:
@@ -1223,6 +1217,8 @@ int ebt_register_table(struct net *net, const struct ebt_table *input_table,
12231217
*res = NULL;
12241218
}
12251219

1220+
audit_log_nfcfg(repl->name, AF_BRIDGE, repl->nentries,
1221+
AUDIT_XT_OP_REGISTER);
12261222
return ret;
12271223
free_unlock:
12281224
mutex_unlock(&ebt_mutex);

net/netfilter/x_tables.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,15 +1408,9 @@ xt_replace_table(struct xt_table *table,
14081408
}
14091409
}
14101410

1411-
#ifdef CONFIG_AUDIT
1412-
if (audit_enabled) {
1413-
audit_log(audit_context(), GFP_KERNEL,
1414-
AUDIT_NETFILTER_CFG,
1415-
"table=%s family=%u entries=%u",
1416-
table->name, table->af, private->number);
1417-
}
1418-
#endif
1419-
1411+
audit_log_nfcfg(table->name, table->af, private->number,
1412+
!private->number ? AUDIT_XT_OP_REGISTER :
1413+
AUDIT_XT_OP_REPLACE);
14201414
return private;
14211415
}
14221416
EXPORT_SYMBOL_GPL(xt_replace_table);

0 commit comments

Comments
 (0)