Skip to content

Commit 310529e

Browse files
Phil Sutterummakynes
authored andcommitted
netfilter: nf_tables: Fix for endless loop when dumping ruleset
__nf_tables_dump_rules() stores the current idx value into cb->args[0] before returning to caller. With multiple chains present, cb->args[0] is therefore updated after each chain's rules have been traversed. This though causes the final nf_tables_dump_rules() run (which should return an skb->len of zero since no rules are left to dump) to continue dumping rules for each but the first chain. Fix this by moving the cb->args[0] update to nf_tables_dump_rules(). With no final action to be performed anymore in __nf_tables_dump_rules(), drop 'out_unfinished' jump label and 'rc' variable - instead return the appropriate value directly. Fixes: 241faec ("netfilter: nf_tables: Speed up selective rule dumps") Signed-off-by: Phil Sutter <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent a007184 commit 310529e

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,7 +2304,6 @@ static int __nf_tables_dump_rules(struct sk_buff *skb,
23042304
struct net *net = sock_net(skb->sk);
23052305
unsigned int s_idx = cb->args[0];
23062306
const struct nft_rule *rule;
2307-
int rc = 1;
23082307

23092308
list_for_each_entry_rcu(rule, &chain->rules, list) {
23102309
if (!nft_is_active(net, rule))
@@ -2321,16 +2320,13 @@ static int __nf_tables_dump_rules(struct sk_buff *skb,
23212320
NLM_F_MULTI | NLM_F_APPEND,
23222321
table->family,
23232322
table, chain, rule) < 0)
2324-
goto out_unfinished;
2323+
return 1;
23252324

23262325
nl_dump_check_consistent(cb, nlmsg_hdr(skb));
23272326
cont:
23282327
(*idx)++;
23292328
}
2330-
rc = 0;
2331-
out_unfinished:
2332-
cb->args[0] = *idx;
2333-
return rc;
2329+
return 0;
23342330
}
23352331

23362332
static int nf_tables_dump_rules(struct sk_buff *skb,
@@ -2382,6 +2378,8 @@ static int nf_tables_dump_rules(struct sk_buff *skb,
23822378
}
23832379
done:
23842380
rcu_read_unlock();
2381+
2382+
cb->args[0] = idx;
23852383
return skb->len;
23862384
}
23872385

0 commit comments

Comments
 (0)