Skip to content

Commit 7fb818f

Browse files
Phil Sutterummakynes
authored andcommitted
netfilter: nf_tables: Fix entries val in rule reset audit log
The value in idx and the number of rules handled in that particular __nf_tables_dump_rules() call is not identical. The former is a cursor to pick up from if multiple netlink messages are needed, so its value is ever increasing. Fixing this is not just a matter of subtracting s_idx from it, though: When resetting rules in multiple chains, __nf_tables_dump_rules() is called for each and cb->args[0] is not adjusted in between. Introduce a dedicated counter to record the number of rules reset in this call in a less confusing way. While being at it, prevent the direct return upon buffer exhaustion: Any rules previously dumped into that skb would evade audit logging otherwise. Fixes: 9b5ba5c ("netfilter: nf_tables: Unbreak audit log reset") Signed-off-by: Phil Sutter <[email protected]> Reviewed-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 4908d5a commit 7fb818f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3451,6 +3451,8 @@ static int __nf_tables_dump_rules(struct sk_buff *skb,
34513451
struct net *net = sock_net(skb->sk);
34523452
const struct nft_rule *rule, *prule;
34533453
unsigned int s_idx = cb->args[0];
3454+
unsigned int entries = 0;
3455+
int ret = 0;
34543456
u64 handle;
34553457

34563458
prule = NULL;
@@ -3473,20 +3475,22 @@ static int __nf_tables_dump_rules(struct sk_buff *skb,
34733475
NFT_MSG_NEWRULE,
34743476
NLM_F_MULTI | NLM_F_APPEND,
34753477
table->family,
3476-
table, chain, rule, handle, reset) < 0)
3477-
return 1;
3478-
3478+
table, chain, rule, handle, reset) < 0) {
3479+
ret = 1;
3480+
break;
3481+
}
3482+
entries++;
34793483
nl_dump_check_consistent(cb, nlmsg_hdr(skb));
34803484
cont:
34813485
prule = rule;
34823486
cont_skip:
34833487
(*idx)++;
34843488
}
34853489

3486-
if (reset && *idx)
3487-
audit_log_rule_reset(table, cb->seq, *idx);
3490+
if (reset && entries)
3491+
audit_log_rule_reset(table, cb->seq, entries);
34883492

3489-
return 0;
3493+
return ret;
34903494
}
34913495

34923496
static int nf_tables_dump_rules(struct sk_buff *skb,

0 commit comments

Comments
 (0)