Skip to content

Commit 0092409

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: nf_tables: don't assume chain stats are set when jumplabel is set
nft_chain_stats_replace() and all other spots assume ->stats can be NULL, but nft_update_chain_stats does not. It must do this check, just because the jump label is set doesn't mean all basechains have stats assigned. Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent a44f6d8 commit 0092409

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

net/netfilter/nf_tables_core.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,22 @@ DEFINE_STATIC_KEY_FALSE(nft_counters_enabled);
119119
static noinline void nft_update_chain_stats(const struct nft_chain *chain,
120120
const struct nft_pktinfo *pkt)
121121
{
122+
struct nft_base_chain *base_chain;
122123
struct nft_stats *stats;
123124

124-
local_bh_disable();
125-
stats = this_cpu_ptr(rcu_dereference(nft_base_chain(chain)->stats));
126-
u64_stats_update_begin(&stats->syncp);
127-
stats->pkts++;
128-
stats->bytes += pkt->skb->len;
129-
u64_stats_update_end(&stats->syncp);
130-
local_bh_enable();
125+
base_chain = nft_base_chain(chain);
126+
if (!base_chain->stats)
127+
return;
128+
129+
stats = this_cpu_ptr(rcu_dereference(base_chain->stats));
130+
if (stats) {
131+
local_bh_disable();
132+
u64_stats_update_begin(&stats->syncp);
133+
stats->pkts++;
134+
stats->bytes += pkt->skb->len;
135+
u64_stats_update_end(&stats->syncp);
136+
local_bh_enable();
137+
}
131138
}
132139

133140
struct nft_jumpstack {

0 commit comments

Comments
 (0)