Blob Blame History Raw
From: Pablo Neira Ayuso <pablo@netfilter.org>
Date: Sun, 27 May 2018 21:08:13 +0200
Subject: netfilter: nf_tables: disable preemption in nft_update_chain_stats()
Git-commit: ad9d9e85072b668731f356be0a3750a3ba22a607
Patch-mainline: v4.17
References: netfilter-stable-18_06_27

This patch fixes the following splat.

[118709.054937] BUG: using smp_processor_id() in preemptible [00000000] code: test/1571
[118709.054970] caller is nft_update_chain_stats.isra.4+0x53/0x97 [nf_tables]
[118709.054980] CPU: 2 PID: 1571 Comm: test Not tainted 4.17.0-rc6+ #335
[...]
[118709.054992] Call Trace:
[118709.055011]  dump_stack+0x5f/0x86
[118709.055026]  check_preemption_disabled+0xd4/0xe4

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 net/netfilter/nf_tables_core.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/net/netfilter/nf_tables_core.c
+++ b/net/netfilter/nf_tables_core.c
@@ -225,15 +225,15 @@ next_rule:
 	if (!base_chain->stats)
 		goto end;
 
+	rcu_read_lock_bh();
 	stats = this_cpu_ptr(rcu_dereference(base_chain->stats));
 	if (stats) {
-		rcu_read_lock_bh();
 		u64_stats_update_begin(&stats->syncp);
 		stats->pkts++;
 		stats->bytes += pkt->skb->len;
 		u64_stats_update_end(&stats->syncp);
-		rcu_read_unlock_bh();
 	}
+	rcu_read_unlock_bh();
 end:
 	return nft_base_chain(basechain)->policy;
 }