Skip to content

Commit ea078ae

Browse files
Phil Sutterummakynes
Phil Sutter
authored andcommitted
netfilter: nf_tables: Audit log rule reset
Resetting rules' stateful data happens outside of the transaction logic, so 'get' and 'dump' handlers have to emit audit log entries themselves. Fixes: 8daa8fd ("netfilter: nf_tables: Introduce NFT_MSG_GETRULE_RESET") Signed-off-by: Phil Sutter <[email protected]> Reviewed-by: Richard Guy Briggs <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 7e9be11 commit ea078ae

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

include/linux/audit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ enum audit_nfcfgop {
118118
AUDIT_NFT_OP_FLOWTABLE_REGISTER,
119119
AUDIT_NFT_OP_FLOWTABLE_UNREGISTER,
120120
AUDIT_NFT_OP_SETELEM_RESET,
121+
AUDIT_NFT_OP_RULE_RESET,
121122
AUDIT_NFT_OP_INVALID,
122123
};
123124

kernel/auditsc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ static const struct audit_nfcfgop_tab audit_nfcfgs[] = {
144144
{ AUDIT_NFT_OP_FLOWTABLE_REGISTER, "nft_register_flowtable" },
145145
{ AUDIT_NFT_OP_FLOWTABLE_UNREGISTER, "nft_unregister_flowtable" },
146146
{ AUDIT_NFT_OP_SETELEM_RESET, "nft_reset_setelem" },
147+
{ AUDIT_NFT_OP_RULE_RESET, "nft_reset_rule" },
147148
{ AUDIT_NFT_OP_INVALID, "nft_invalid" },
148149
};
149150

net/netfilter/nf_tables_api.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3422,6 +3422,18 @@ static void nf_tables_rule_notify(const struct nft_ctx *ctx,
34223422
nfnetlink_set_err(ctx->net, ctx->portid, NFNLGRP_NFTABLES, -ENOBUFS);
34233423
}
34243424

3425+
static void audit_log_rule_reset(const struct nft_table *table,
3426+
unsigned int base_seq,
3427+
unsigned int nentries)
3428+
{
3429+
char *buf = kasprintf(GFP_ATOMIC, "%s:%u",
3430+
table->name, base_seq);
3431+
3432+
audit_log_nfcfg(buf, table->family, nentries,
3433+
AUDIT_NFT_OP_RULE_RESET, GFP_ATOMIC);
3434+
kfree(buf);
3435+
}
3436+
34253437
struct nft_rule_dump_ctx {
34263438
char *table;
34273439
char *chain;
@@ -3528,6 +3540,9 @@ static int nf_tables_dump_rules(struct sk_buff *skb,
35283540
done:
35293541
rcu_read_unlock();
35303542

3543+
if (reset && idx > cb->args[0])
3544+
audit_log_rule_reset(table, cb->seq, idx - cb->args[0]);
3545+
35313546
cb->args[0] = idx;
35323547
return skb->len;
35333548
}
@@ -3635,6 +3650,9 @@ static int nf_tables_getrule(struct sk_buff *skb, const struct nfnl_info *info,
36353650
if (err < 0)
36363651
goto err_fill_rule_info;
36373652

3653+
if (reset)
3654+
audit_log_rule_reset(table, nft_pernet(net)->base_seq, 1);
3655+
36383656
return nfnetlink_unicast(skb2, net, NETLINK_CB(skb).portid);
36393657

36403658
err_fill_rule_info:

0 commit comments

Comments
 (0)