Skip to content

Commit 0d880dc

Browse files
Phil SutterFlorian Westphal
authored andcommitted
netfilter: nf_tables: Deduplicate nft_register_obj audit logs
When adding/updating an object, the transaction handler emits suitable audit log entries already, the one in nft_obj_notify() is redundant. To fix that (and retain the audit logging from objects' 'update' callback), Introduce an "audit log free" variant for internal use. Fixes: c520292 ("audit: log nftables configuration change events once per table") Signed-off-by: Phil Sutter <[email protected]> Reviewed-by: Richard Guy Briggs <[email protected]> Acked-by: Paul Moore <[email protected]> (Audit) Signed-off-by: Florian Westphal <[email protected]>
1 parent 203bb9d commit 0d880dc

File tree

2 files changed

+48
-16
lines changed

2 files changed

+48
-16
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7871,24 +7871,14 @@ static int nf_tables_delobj(struct sk_buff *skb, const struct nfnl_info *info,
78717871
return nft_delobj(&ctx, obj);
78727872
}
78737873

7874-
void nft_obj_notify(struct net *net, const struct nft_table *table,
7875-
struct nft_object *obj, u32 portid, u32 seq, int event,
7876-
u16 flags, int family, int report, gfp_t gfp)
7874+
static void
7875+
__nft_obj_notify(struct net *net, const struct nft_table *table,
7876+
struct nft_object *obj, u32 portid, u32 seq, int event,
7877+
u16 flags, int family, int report, gfp_t gfp)
78777878
{
78787879
struct nftables_pernet *nft_net = nft_pernet(net);
78797880
struct sk_buff *skb;
78807881
int err;
7881-
char *buf = kasprintf(gfp, "%s:%u",
7882-
table->name, nft_net->base_seq);
7883-
7884-
audit_log_nfcfg(buf,
7885-
family,
7886-
obj->handle,
7887-
event == NFT_MSG_NEWOBJ ?
7888-
AUDIT_NFT_OP_OBJ_REGISTER :
7889-
AUDIT_NFT_OP_OBJ_UNREGISTER,
7890-
gfp);
7891-
kfree(buf);
78927882

78937883
if (!report &&
78947884
!nfnetlink_has_listeners(net, NFNLGRP_NFTABLES))
@@ -7911,13 +7901,35 @@ void nft_obj_notify(struct net *net, const struct nft_table *table,
79117901
err:
79127902
nfnetlink_set_err(net, portid, NFNLGRP_NFTABLES, -ENOBUFS);
79137903
}
7904+
7905+
void nft_obj_notify(struct net *net, const struct nft_table *table,
7906+
struct nft_object *obj, u32 portid, u32 seq, int event,
7907+
u16 flags, int family, int report, gfp_t gfp)
7908+
{
7909+
struct nftables_pernet *nft_net = nft_pernet(net);
7910+
char *buf = kasprintf(gfp, "%s:%u",
7911+
table->name, nft_net->base_seq);
7912+
7913+
audit_log_nfcfg(buf,
7914+
family,
7915+
obj->handle,
7916+
event == NFT_MSG_NEWOBJ ?
7917+
AUDIT_NFT_OP_OBJ_REGISTER :
7918+
AUDIT_NFT_OP_OBJ_UNREGISTER,
7919+
gfp);
7920+
kfree(buf);
7921+
7922+
__nft_obj_notify(net, table, obj, portid, seq, event,
7923+
flags, family, report, gfp);
7924+
}
79147925
EXPORT_SYMBOL_GPL(nft_obj_notify);
79157926

79167927
static void nf_tables_obj_notify(const struct nft_ctx *ctx,
79177928
struct nft_object *obj, int event)
79187929
{
7919-
nft_obj_notify(ctx->net, ctx->table, obj, ctx->portid, ctx->seq, event,
7920-
ctx->flags, ctx->family, ctx->report, GFP_KERNEL);
7930+
__nft_obj_notify(ctx->net, ctx->table, obj, ctx->portid,
7931+
ctx->seq, event, ctx->flags, ctx->family,
7932+
ctx->report, GFP_KERNEL);
79217933
}
79227934

79237935
/*

tools/testing/selftests/netfilter/nft_audit.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,26 @@ do_test "nft add set t1 s2 $setblock; add set t1 s3 { $settype; }" \
8585
do_test "nft add element t1 s3 $setelem" \
8686
"table=t1 family=2 entries=3 op=nft_register_setelem"
8787

88+
# adding counters
89+
90+
do_test 'nft add counter t1 c1' \
91+
'table=t1 family=2 entries=1 op=nft_register_obj'
92+
93+
do_test 'nft add counter t2 c1; add counter t2 c2' \
94+
'table=t2 family=2 entries=2 op=nft_register_obj'
95+
96+
# adding/updating quotas
97+
98+
do_test 'nft add quota t1 q1 { 10 bytes }' \
99+
'table=t1 family=2 entries=1 op=nft_register_obj'
100+
101+
do_test 'nft add quota t2 q1 { 10 bytes }; add quota t2 q2 { 10 bytes }' \
102+
'table=t2 family=2 entries=2 op=nft_register_obj'
103+
104+
# changing the quota value triggers obj update path
105+
do_test 'nft add quota t1 q1 { 20 bytes }' \
106+
'table=t1 family=2 entries=1 op=nft_register_obj'
107+
88108
# resetting rules
89109

90110
do_test 'nft reset rules t1 c2' \

0 commit comments

Comments
 (0)