Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 9b5ba5c9c5109 ("netfilter: nf_tables: Unbreak audit log reset")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Reviewed-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

authored by

Phil Sutter and committed by
Pablo Neira Ayuso
7fb818f2 4908d5af

+10 -6
+10 -6
net/netfilter/nf_tables_api.c
··· 3451 3451 struct net *net = sock_net(skb->sk); 3452 3452 const struct nft_rule *rule, *prule; 3453 3453 unsigned int s_idx = cb->args[0]; 3454 + unsigned int entries = 0; 3455 + int ret = 0; 3454 3456 u64 handle; 3455 3457 3456 3458 prule = NULL; ··· 3475 3473 NFT_MSG_NEWRULE, 3476 3474 NLM_F_MULTI | NLM_F_APPEND, 3477 3475 table->family, 3478 - table, chain, rule, handle, reset) < 0) 3479 - return 1; 3480 - 3476 + table, chain, rule, handle, reset) < 0) { 3477 + ret = 1; 3478 + break; 3479 + } 3480 + entries++; 3481 3481 nl_dump_check_consistent(cb, nlmsg_hdr(skb)); 3482 3482 cont: 3483 3483 prule = rule; ··· 3487 3483 (*idx)++; 3488 3484 } 3489 3485 3490 - if (reset && *idx) 3491 - audit_log_rule_reset(table, cb->seq, *idx); 3486 + if (reset && entries) 3487 + audit_log_rule_reset(table, cb->seq, entries); 3492 3488 3493 - return 0; 3489 + return ret; 3494 3490 } 3495 3491 3496 3492 static int nf_tables_dump_rules(struct sk_buff *skb,