Skip to content

Commit a9f5e78

Browse files
lrq-maxummakynes
authored andcommitted
netfilter: nf_tables: check the result of dereferencing base_chain->stats
Check the result of dereferencing base_chain->stats, instead of result of this_cpu_ptr with NULL. base_chain->stats maybe be changed to NULL when a chain is updated and a new NULL counter can be attached. And we do not need to check returning of this_cpu_ptr since base_chain->stats is from percpu allocator if it is non-NULL, this_cpu_ptr returns a valid value. And fix two sparse error by replacing rcu_access_pointer and rcu_dereference with READ_ONCE under rcu_read_lock. Thanks for Eric's help to finish this patch. Fixes: 0092409 ("netfilter: nf_tables: don't assume chain stats are set when jumplabel is set") Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: Zhang Yu <[email protected]> Signed-off-by: Li RongQing <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent cd64289 commit a9f5e78

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

net/netfilter/nf_tables_core.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,23 @@ static noinline void nft_update_chain_stats(const struct nft_chain *chain,
9898
const struct nft_pktinfo *pkt)
9999
{
100100
struct nft_base_chain *base_chain;
101+
struct nft_stats __percpu *pstats;
101102
struct nft_stats *stats;
102103

103104
base_chain = nft_base_chain(chain);
104-
if (!rcu_access_pointer(base_chain->stats))
105-
return;
106105

107-
local_bh_disable();
108-
stats = this_cpu_ptr(rcu_dereference(base_chain->stats));
109-
if (stats) {
106+
rcu_read_lock();
107+
pstats = READ_ONCE(base_chain->stats);
108+
if (pstats) {
109+
local_bh_disable();
110+
stats = this_cpu_ptr(pstats);
110111
u64_stats_update_begin(&stats->syncp);
111112
stats->pkts++;
112113
stats->bytes += pkt->skb->len;
113114
u64_stats_update_end(&stats->syncp);
115+
local_bh_enable();
114116
}
115-
local_bh_enable();
117+
rcu_read_unlock();
116118
}
117119

118120
struct nft_jumpstack {

0 commit comments

Comments
 (0)