Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netfilter: br_netfilter: Use nested-BH locking for brnf_frag_data_storage.

brnf_frag_data_storage is a per-CPU variable and relies on disabled BH
for its locking. Without per-CPU locking in local_bh_disable() on
PREEMPT_RT this data structure requires explicit locking.

Add a local_lock_t to the data structure and use local_lock_nested_bh()
for locking. This change adds only lockdep coverage and does not alter
the functional behaviour for !PREEMPT_RT.

Cc: Florian Westphal <fw@strlen.de>
Cc: Jozsef Kadlecsik <kadlec@netfilter.org>
Cc: Nikolay Aleksandrov <razor@blackwall.org>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Roopa Prabhu <roopa@nvidia.com>
Cc: bridge@lists.linux.dev
Cc: coreteam@netfilter.org
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: https://patch.msgid.link/20240620132727.660738-8-bigeasy@linutronix.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Sebastian Andrzej Siewior and committed by
Jakub Kicinski
c67ef53a ebad6d03

+16 -4
+16 -4
net/bridge/br_netfilter_hooks.c
··· 137 137 #define NF_BRIDGE_MAX_MAC_HEADER_LENGTH (PPPOE_SES_HLEN + ETH_HLEN) 138 138 139 139 struct brnf_frag_data { 140 + local_lock_t bh_lock; 140 141 char mac[NF_BRIDGE_MAX_MAC_HEADER_LENGTH]; 141 142 u8 encap_size; 142 143 u8 size; ··· 145 144 __be16 vlan_proto; 146 145 }; 147 146 148 - static DEFINE_PER_CPU(struct brnf_frag_data, brnf_frag_data_storage); 147 + static DEFINE_PER_CPU(struct brnf_frag_data, brnf_frag_data_storage) = { 148 + .bh_lock = INIT_LOCAL_LOCK(bh_lock), 149 + }; 149 150 150 151 static void nf_bridge_info_free(struct sk_buff *skb) 151 152 { ··· 853 850 { 854 851 struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb); 855 852 unsigned int mtu, mtu_reserved; 853 + int ret; 856 854 857 855 mtu_reserved = nf_bridge_mtu_reduction(skb); 858 856 mtu = skb->dev->mtu; ··· 886 882 887 883 IPCB(skb)->frag_max_size = nf_bridge->frag_max_size; 888 884 885 + local_lock_nested_bh(&brnf_frag_data_storage.bh_lock); 889 886 data = this_cpu_ptr(&brnf_frag_data_storage); 890 887 891 888 if (skb_vlan_tag_present(skb)) { ··· 902 897 skb_copy_from_linear_data_offset(skb, -data->size, data->mac, 903 898 data->size); 904 899 905 - return br_nf_ip_fragment(net, sk, skb, br_nf_push_frag_xmit); 900 + ret = br_nf_ip_fragment(net, sk, skb, br_nf_push_frag_xmit); 901 + local_unlock_nested_bh(&brnf_frag_data_storage.bh_lock); 902 + return ret; 906 903 } 907 904 if (IS_ENABLED(CONFIG_NF_DEFRAG_IPV6) && 908 905 skb->protocol == htons(ETH_P_IPV6)) { ··· 916 909 917 910 IP6CB(skb)->frag_max_size = nf_bridge->frag_max_size; 918 911 912 + local_lock_nested_bh(&brnf_frag_data_storage.bh_lock); 919 913 data = this_cpu_ptr(&brnf_frag_data_storage); 920 914 data->encap_size = nf_bridge_encap_header_len(skb); 921 915 data->size = ETH_HLEN + data->encap_size; ··· 924 916 skb_copy_from_linear_data_offset(skb, -data->size, data->mac, 925 917 data->size); 926 918 927 - if (v6ops) 928 - return v6ops->fragment(net, sk, skb, br_nf_push_frag_xmit); 919 + if (v6ops) { 920 + ret = v6ops->fragment(net, sk, skb, br_nf_push_frag_xmit); 921 + local_unlock_nested_bh(&brnf_frag_data_storage.bh_lock); 922 + return ret; 923 + } 924 + local_unlock_nested_bh(&brnf_frag_data_storage.bh_lock); 929 925 930 926 kfree_skb(skb); 931 927 return -EMSGSIZE;