Skip to content

Commit 8d34a7a

Browse files
committed
netfilter: nf_tables: Audit log rule reset
JIRA: https://issues.redhat.com/browse/RHEL-9127 This patch is a backport of the following upstream commit: commit ea078ae Author: Phil Sutter <phil@nwl.cc> Date: Tue Aug 29 19:51:58 2023 +0200 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 <phil@nwl.cc> Reviewed-by: Richard Guy Briggs <rgb@redhat.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Ricardo Robaina <rrobaina@redhat.com>
1 parent 4052bb3 commit 8d34a7a

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
@@ -3089,6 +3089,18 @@ static void nf_tables_rule_notify(const struct nft_ctx *ctx,
30893089
nfnetlink_set_err(ctx->net, ctx->portid, NFNLGRP_NFTABLES, -ENOBUFS);
30903090
}
30913091

3092+
static void audit_log_rule_reset(const struct nft_table *table,
3093+
unsigned int base_seq,
3094+
unsigned int nentries)
3095+
{
3096+
char *buf = kasprintf(GFP_ATOMIC, "%s:%u",
3097+
table->name, base_seq);
3098+
3099+
audit_log_nfcfg(buf, table->family, nentries,
3100+
AUDIT_NFT_OP_RULE_RESET, GFP_ATOMIC);
3101+
kfree(buf);
3102+
}
3103+
30923104
struct nft_rule_dump_ctx {
30933105
char *table;
30943106
char *chain;
@@ -3195,6 +3207,9 @@ static int nf_tables_dump_rules(struct sk_buff *skb,
31953207
done:
31963208
rcu_read_unlock();
31973209

3210+
if (reset && idx > cb->args[0])
3211+
audit_log_rule_reset(table, cb->seq, idx - cb->args[0]);
3212+
31983213
cb->args[0] = idx;
31993214
return skb->len;
32003215
}
@@ -3302,6 +3317,9 @@ static int nf_tables_getrule(struct sk_buff *skb, const struct nfnl_info *info,
33023317
if (err < 0)
33033318
goto err_fill_rule_info;
33043319

3320+
if (reset)
3321+
audit_log_rule_reset(table, nft_pernet(net)->base_seq, 1);
3322+
33053323
return nfnetlink_unicast(skb2, net, NETLINK_CB(skb).portid);
33063324

33073325
err_fill_rule_info:

0 commit comments

Comments
 (0)