Article View: linux.kernel.netdev
Article #12963[PATCH net-next 10/14] netfilter: bridge: annotate data-races around br_netfilter and nf_log sysctls
From: Jiayuan Chen
Date: Mon, 09 Nov 2026 02:52
Date: Mon, 09 Nov 2026 02:52
163 lines
15756 bytes
15756 bytes
bridge-nf-call-arptables, bridge-nf-call-iptables,
bridge-nf-call-ip6tables, bridge-nf-filter-vlan-tagged,
bridge-nf-filter-pppoe-tagged, bridge-nf-pass-vlan-input-dev and
nf_log_all_netns are read in the packet path without any lock while their
sysctl handlers update them, and brnf_sysctl_call_tables() normalizes the
value with a plain write. Add READ_ONCE() to the readers and WRITE_ONCE()
to that handler.
KCSAN reports it when bridge-nf-call-iptables is changed while packets
are bridged:
BUG: KCSAN: data-race in br_nf_pre_routing / do_proc_int_conv
write (marked) to 0xffff8d7242d8ec50 of 4 bytes by task 824 on cpu 0:
do_proc_int_conv+0xa9/0xd0
proc_vec_conv+0x21/0x40
proc_vec+0x21e/0x6f0
proc_dointvec+0x16/0x30
brnf_sysctl_call_tables+0x19/0x70
proc_sys_call_handler+0x282/0x3a0
proc_sys_write+0x13/0x20
...
read to 0xffff8d7242d8ec50 of 4 bytes by interrupt on cpu 1:
br_nf_pre_routing+0x1a9/0x9d0
br_handle_frame+0x523/0x990
__netif_receive_skb_core.constprop.0+0x3b2/0x1cf0
__netif_receive_skb_one_core+0x51/0xe0
__netif_receive_skb+0x23/0xb0
process_backlog+0x27a/0x950
...
value changed: 0x00000001 -> 0x00000000
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
---
net/bridge/br_netfilter_hooks.c | 20 ++++++++++----------
net/bridge/netfilter/ebt_log.c | 2 +-
net/netfilter/nf_log_syslog.c | 2 +-
3 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/net/bridge/br_netfilter_hooks.c b/net/bridge/br_netfilter_hooks.c
index e15355ff215a7..8a47fe4e8eb61 100644
--- a/net/bridge/br_netfilter_hooks.c
+++ b/net/bridge/br_netfilter_hooks.c
@@ -94,7 +94,7 @@ static inline bool is_vlan_ip(const struct sk_buff *skb, const struct net *net)
{
struct brnf_net *brnet = net_generic(net, brnf_net_id);
- return vlan_proto(skb) == htons(ETH_P_IP) && brnet->filter_vlan_tagged;
+ return vlan_proto(skb) == htons(ETH_P_IP) && READ_ONCE(brnet->filter_vlan_tagged);
}
static inline bool is_vlan_ipv6(const struct sk_buff *skb,
@@ -103,14 +103,14 @@ static inline bool is_vlan_ipv6(const struct sk_buff *skb,
struct brnf_net *brnet = net_generic(net, brnf_net_id);
return vlan_proto(skb) == htons(ETH_P_IPV6) &&
- brnet->filter_vlan_tagged;
+ READ_ONCE(brnet->filter_vlan_tagged);
}
static inline bool is_vlan_arp(const struct sk_buff *skb, const struct net *net)
{
struct brnf_net *brnet = net_generic(net, brnf_net_id);
- return vlan_proto(skb) == htons(ETH_P_ARP) && brnet->filter_vlan_tagged;
+ return vlan_proto(skb) == htons(ETH_P_ARP) && READ_ONCE(brnet->filter_vlan_tagged);
}
static inline __be16 pppoe_proto(const struct sk_buff *skb)
@@ -124,7 +124,7 @@ static inline bool is_pppoe_ip(const struct sk_buff *skb, const struct net *net)
struct brnf_net *brnet = net_generic(net, brnf_net_id);
return skb->protocol == htons(ETH_P_PPP_SES) &&
- pppoe_proto(skb) == htons(PPP_IP) && brnet->filter_pppoe_tagged;
+ pppoe_proto(skb) == htons(PPP_IP) && READ_ONCE(brnet->filter_pppoe_tagged);
}
static inline bool is_pppoe_ipv6(const struct sk_buff *skb,
@@ -134,7 +134,7 @@ static inline bool is_pppoe_ipv6(const struct sk_buff *skb,
return skb->protocol == htons(ETH_P_PPP_SES) &&
pppoe_proto(skb) == htons(PPP_IPV6) &&
- brnet->filter_pppoe_tagged;
+ READ_ONCE(brnet->filter_pppoe_tagged);
}
/* largest possible L2 header, see br_nf_dev_queue_xmit() */
@@ -442,7 +442,7 @@ static struct net_device *brnf_get_logical_dev(struct sk_buff *skb,
br = bridge_parent(dev);
- if (brnet->pass_vlan_indev == 0 || !skb_vlan_tag_present(skb))
+ if (READ_ONCE(brnet->pass_vlan_indev) == 0 || !skb_vlan_tag_present(skb))
return br;
vlan = __vlan_find_dev_deep_rcu(br, skb->vlan_proto,
@@ -502,7 +502,7 @@ static unsigned int br_nf_pre_routing(void *priv,
brnet = net_generic(state->net, brnf_net_id);
if (IS_IPV6(skb) || is_vlan_ipv6(skb, state->net) ||
is_pppoe_ipv6(skb, state->net)) {
- if (!brnet->call_ip6tables &&
+ if (!READ_ONCE(brnet->call_ip6tables) &&
!br_opt_get(br, BROPT_NF_CALL_IP6TABLES))
return NF_ACCEPT;
if (!ipv6_mod_enabled()) {
@@ -514,7 +514,7 @@ static unsigned int br_nf_pre_routing(void *priv,
return br_nf_pre_routing_ipv6(priv, skb, state);
}
- if (!brnet->call_iptables && !br_opt_get(br, BROPT_NF_CALL_IPTABLES))
+ if (!READ_ONCE(brnet->call_iptables) && !br_opt_get(br, BROPT_NF_CALL_IPTABLES))
return NF_ACCEPT;
if (!IS_IP(skb) && !is_vlan_ip(skb, state->net) &&
@@ -740,7 +740,7 @@ static unsigned int br_nf_forward_arp(struct sk_buff *skb,
br = p->br;
brnet = net_generic(state->net, brnf_net_id);
- if (!brnet->call_arptables && !br_opt_get(br, BROPT_NF_CALL_ARPTABLES))
+ if (!READ_ONCE(brnet->call_arptables) && !br_opt_get(br, BROPT_NF_CALL_ARPTABLES))
return NF_ACCEPT;
if (is_vlan_arp(skb, state->net))
@@ -1178,7 +1178,7 @@ int brnf_sysctl_call_tables(const struct ctl_table *ctl, int write,
ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
if (write && *(int *)(ctl->data))
- *(int *)(ctl->data) = 1;
+ WRITE_ONCE(*(int *)(ctl->data), 1);
return ret;
}
diff --git a/net/bridge/netfilter/ebt_log.c b/net/bridge/netfilter/ebt_log.c
index e2eea1daaf8ba..f360414a2814e 100644
--- a/net/bridge/netfilter/ebt_log.c
+++ b/net/bridge/netfilter/ebt_log.c
@@ -79,7 +79,7 @@ ebt_log_packet(struct net *net, u_int8_t pf, unsigned int hooknum,
unsigned int bitmask;
/* FIXME: Disabled from containers until syslog ns is supported */
- if (!net_eq(net, &init_net) && !sysctl_nf_log_all_netns)
+ if (!net_eq(net, &init_net) && !READ_ONCE(sysctl_nf_log_all_netns))
return;
spin_lock_bh(&ebt_log_lock);
diff --git a/net/netfilter/nf_log_syslog.c b/net/netfilter/nf_log_syslog.c
index c3fd398ffcd77..2907f47c83423 100644
--- a/net/netfilter/nf_log_syslog.c
+++ b/net/netfilter/nf_log_syslog.c
@@ -43,7 +43,7 @@ struct arppayload {
/* Guard against containers flooding syslog. */
static bool nf_log_allowed(const struct net *net)
{
- return net_eq(net, &init_net) || sysctl_nf_log_all_netns;
+ return net_eq(net, &init_net) || READ_ONCE(sysctl_nf_log_all_netns);
}
static void nf_log_dump_vlan(struct nf_log_buf *m, const struct sk_buff *skb)
--
2.43.0
Technical Details
Message-ID:
<20261109025425.328445-11-jiayuan.chen@linux.dev>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359000-linux-kernel-netdev=dewy.ruReferences:
<20261109025425.328445-1-jiayuan.chen@linux.dev>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359000-linux-kernel-netdev=dewy.ru From: jiayuan.chen@linux.dev (Jiayuan Chen) Newsgroups: linux.kernel.netdev Subject: [PATCH net-next 10/14] netfilter: bridge: annotate data-races around br_netfilter and nf_log sysctls Date: Mon, 9 Nov 2026 10:52:09 +0800 Organization: Usenet Network Message-ID: <20261109025425.328445-11-jiayuan.chen@linux.dev> References: <20261109025425.328445-1-jiayuan.chen@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="258179"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:u2z2YL4WNbYqGSz5QNG9yQHUxmo= sha256:hI3vf5kr/D0+hUUyapuCkSWHO6WK5FvBW7FTI7ZXSCc= sha1:3KtcF5JoKakDFKo6R2IfpLF+wcM= sha256:WmRLo7IEdSvKCLjB2bM3CQoJWugHf/L4hAtrvaMVRmI= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 9B5171136B8; Mon, 9 Nov 2026 06:02:10 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.051 X-Spam-Status: No, score=-2.051 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, HK_RANDOM_FROM=1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=linux.dev X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7p_Iob7vFWtL; Mon, 9 Nov 2026 06:02:06 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-359000-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 367B51136B6; Mon, 9 Nov 2026 06:01:58 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id BC80C2943A; Mon, 9 Nov 2026 02:59:43 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794193181; b=J5AFayazg3cbe2Ox3VWeltGI+W3lSz76v9llvAqTxG2SDDix4HScUB3i8TLYc6HLwVf7 CT0l2df6q9QU8az/BERnW63ygAYe9aaD5wKDH5FMmNXxZ2vGm5ELdFtEafstpk0YoFW3c FJT7/AXMu2qHt03h7rEcVUo/9KBVBfbeYi/iGbZWGBFO/WA9ugdzngvv+z65nUQqsS2mH 0EzjqaX406CV/dTq1Zc2uR+ieti09vfmA+FZsnRZx6qGnJR5I6TlNi1yTp8zI/a0IiPwY xj07rAVhddLkkcOc/osoW8N16aF3MQf1ZW+yikoacBMwYkVF9NQDPpojtyUd0mDjj6g== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794193181; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Transfer-Encoding; bh=0LOz5L54nWXPFnHL/Mb3fPQeqh/eofMGeNrfaibpa3c=; b=IDsKdVJpRiutTqUne4lR0/fJCroJuVzZLq78Vo26CruAQSs0lo1/q1/pr6WsfC+n+fke fGzBsHxeHmiKEdYWNAtXFo5AHKYS/AZuiPpUEnxp+ZrTcfC5ydATXbpGCuRqFmwi1/2E7 2aknj0D5g2Jk6Mh59+VMAkwCdiGq/kvaQhXVICpoVVEs0S/YzwKEsPfO+4fgybk4QdOhr QXcVkK3pPJWriqN/CII15mUY6h9hm0NodG19NqUUsarzUsKfI18vyNM0cZx5R9xK5L2ef qF9Vj4p6Avrd/qx1tlzhOx0/8juPxKF9GulTqu413y65d0L8svrbdC0+L3dsHxQhIUw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=ckwWJYna; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2523C606A332; Mon, 9 Nov 2026 02:59:41 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=ckwWJYna X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.202 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794193170; b=I4A4wYUJpzVhesJBQ3d6GgaDsgT1dmebcPHFwgd/TqDbGgg2Hiomk18OUUSIUGXBFhTS BHSVTfbKRiVJZjLgQy+MUHuXY12A6JLIPjzu7DQN9Ef4AmFBMmc0mxoy6+PDTRaJ8INs6 DsqMtEZzRBtXNiy8c6izfp45CVk2qMsnoVbKw5yMVmyvueUKYHzLv4RrJs0q+mTckPlfY F5FL4TTLHuaxgOrEAdTHFIwgrmoNGTFcMn8qiB8fxUgZXZgI5fQ49uzV47z1bnY8Jvk6o N2izgVJH9fcJ/U5qJ4fGp8Tw+eWYKGE8el5JKW1A++Q3l08Y+bNAsSic49osCbf2tnQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794193170; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=0LOz5L54nWXPFnHL/Mb3fPQeqh/eofMGeNrfaibpa3c=; b=ji2cQhFJLr+OhBAZHRWOqr1HoMzwZGvwk8vIvd/gnzf7Y+/Ofh6iWMwS3njr5MKRcRBZ qm060VOf0G59LFwjn/Qawa/TL8dGXDZgt23d7iyqB4qEEROc9HKw3k6x1q0eYp3qVqvpf Gw1vmFYgmit1oxAwx5KOmxGjoxZ1nvGhhKQJv5uynjo5bOjI4JBpZhncq9ZBSbLgFV6bv IUoaO05y1jbPBegdfugabRhh5sEhWOPBt5WNdNx/0IVH2C0dOuo0dYCIPLdXjRH2wibIt E3AEAjsXcBj86cyhrppJI5UjwlC+kqephTA2LTLaxxWKxdnuze/IYNZEXFYsvJGYHWQ== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=ckwWJYna; arc=none smtp.remote-ip=91.218.175.202 X-Received: from mta0.migadu.com (out-202.mta0.migadu.com [91.218.175.202]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DCA5C606A31C for <netdev@vger.kernel.org>; Mon, 9 Nov 2026 02:59:29 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DCA5C606A31C X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=v8X1DpkjtfbDlgHCJDasGfHlMnkFTI38sTWUwIHdKjY=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1794193168; v=1; x=1794797968; b=ckwWJYnaim0Q1IIfjBwnZgv/sq+mCLAlHhvNQX8O8FZXVWtRzlYGI/bGRMhzGRrPhRMbO9hl FGMN/UNeAIiB7+LxPiP2GgFgHhKUUTyojNYMY/8RTFJzwlRhQoafdpTWruk3mgzL4ZvBYbpLLlu HlGw6Dj7Xz09BFe797qFit4U= X-Envelope-To: netdev@vger.kernel.org X-Received: by smtp.migadu.com with ESMTPS id c4c637c1dc94c2eb; Mon, 09 Nov 2026 02:59:28 +0000 X-Mizu-Trace-ID: c4c637c1dc94c2eb X-Migadu-Flow: FLOW_OUT X-Cc: Jiayuan Chen <jiayuan.chen@linux.dev>, David Ahern <dsahern@kernel.org>, Ido Schimmel <idosch@nvidia.com>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@kernel.org>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>, Pablo Neira Ayuso <pablo@netfilter.org>, Florian Westphal <fw@strlen.de>, Phil Sutter <phil@nwl.cc>, Nikolay Aleksandrov <razor@blackwall.org>, Paul Moore <paul@paul-moore.com>, Matthieu Baerts <matttbe@kernel.org>, Mat Martineau <martineau@kernel.org>, Geliang Tang <geliang@kernel.org>, Julian Anastasov <ja@ssi.bg>, Allison Henderson <achender@kernel.org>, Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>, Xin Long <lucien.xin@gmail.com>, "D. Wythe" <alibuda@linux.alibaba.com>, Dust Li <dust.li@linux.alibaba.com>, Sidraya Jayagond <sidraya@linux.ibm.com>, Mahanta Jambigi <mjambigi@linux.ibm.com>, Tony Lu <tonylu@linux.alibaba.com>, Wen Gu <guwen@linux.alibaba.com>, linux-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, bridge@lists.linux.dev, linux-security-module@vger.kernel.org, mptcp@lists.linux.dev, lvs-devel@vger.kernel.org, linux-rdma@vger.kernel.org, rds-devel@oss.oracle.com, linux-sctp@vger.kernel.org, linux-s390@vger.kernel.org X-Mailer: git-send-email 2.43.0 X-In-Reply-To: <20261109025425.328445-1-jiayuan.chen@linux.dev> X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list