Skip to content

Commit 1eacdd7

Browse files
Sebastian Andrzej Siewiorummakynes
authored andcommitted
netfilter: nft_counter: Disable BH in nft_counter_offload_stats().
The sequence counter nft_counter_seq is a per-CPU counter. There is no lock associated with it. nft_counter_do_eval() is using the same counter and disables BH which suggest that it can be invoked from a softirq. This in turn means that nft_counter_offload_stats(), which disables only preemption, can be interrupted by nft_counter_do_eval() leading to two writer for one seqcount_t. This can lead to loosing stats or reading statistics while they are updated. Disable BH during stats update in nft_counter_offload_stats() to ensure one writer at a time. Fixes: b72920f ("netfilter: nftables: counter hardware offload support") Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Reviewed-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 807067b commit 1eacdd7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

net/netfilter/nft_counter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,15 @@ static void nft_counter_offload_stats(struct nft_expr *expr,
265265
struct nft_counter *this_cpu;
266266
seqcount_t *myseq;
267267

268-
preempt_disable();
268+
local_bh_disable();
269269
this_cpu = this_cpu_ptr(priv->counter);
270270
myseq = this_cpu_ptr(&nft_counter_seq);
271271

272272
write_seqcount_begin(myseq);
273273
this_cpu->packets += stats->pkts;
274274
this_cpu->bytes += stats->bytes;
275275
write_seqcount_end(myseq);
276-
preempt_enable();
276+
local_bh_enable();
277277
}
278278

279279
void nft_counter_init_seqcount(void)

0 commit comments

Comments
 (0)