Netfilter fixes for net
Subsystems (3)
Pablo Neira Ayuso
maintainercover Netfilter fixes for net
Hi,
The following patchset contains Netfilter fixes for net:
Patch #1 disable BH when collecting stats via hardware offload to ensure
concurrent updates from packet path do not result in losing stats. From Sebastian Andrzej Siewior.
Patch #2 uses write seqcount to reset counters serialize against reader.
Also from Sebastian Andrzej Siewior.
Patch #3 ensures vlan header is in place before accessing its fields,
according to KMSAN splat triggered by syzbot.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git nf-24-08-22
Thanks.
----------------------------------------------------------------
The following changes since commit 807067bf014d4a3ae2cc55bd3de16f22a01eb580:
kcm: Serialise kcm_sendmsg() for the same socket. (2024-08-19 18:36:12 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git tags/nf-24-08-22
for you to fetch changes up to 0509ac6c6a9a282ade4ad79b04665395691f73b1:
netfilter: flowtable: validate vlan header (2024-08-21 23:42:49 +0200)
----------------------------------------------------------------
netfilter pull request 24-08-22
----------------------------------------------------------------
Pablo Neira Ayuso (1):
netfilter: flowtable: validate vlan header
Sebastian Andrzej Siewior (2):
netfilter: nft_counter: Disable BH in nft_counter_offload_stats().
netfilter: nft_counter: Synchronize nft_counter_reset() against reader.
net/netfilter/nf_flow_table_inet.c | 3 +++ net/netfilter/nf_flow_table_ip.c | 3 +++ net/netfilter/nft_counter.c | 9 +++++++-- 3 files changed, 13 insertions(+), 2 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/3 netfilter: nft_counter: Disable BH in nft_counter_offload_stats().
From: Sebastian Andrzej Siewior <[email protected]>
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.
--- net/netfilter/nft_counter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nft_counter.c +2 -2
@@ -265,7 +265,7 @@ static void nft_counter_offload_stats(struct nft_expr *expr,struct nft_counter *this_cpu;seqcount_t *myseq; -preempt_disable (); +local_bh_disable (); this_cpu =this_cpu_ptr (priv->counter); myseq =this_cpu_ptr (&nft_counter_seq);
@@ -273,7 +273,7 @@ static void nft_counter_offload_stats(struct nft_expr *expr, this_cpu->packets += stats->pkts; this_cpu->bytes += stats->bytes;write_seqcount_end (myseq); -preempt_enable (); +local_bh_enable (); }void nft_counter_init_seqcount (void )
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 2/3 netfilter: nft_counter: Synchronize nft_counter_reset() against reader.
In reply to Pablo Neira AyusoFrom: Sebastian Andrzej Siewior <[email protected]>
nft_counter_reset() resets the counter by subtracting the previously retrieved value from the counter. This is a write operation on the counter and as such it requires to be performed with a write sequence of nft_counter_seq to serialize against its possible reader.
Update the packets/ bytes within write-sequence of nft_counter_seq.
--- net/netfilter/nft_counter.c | 5 +++++ 1 file changed, 5 insertions(+)
net/netfilter/nft_counter.c +5 -0
@@ -107,11 +107,16 @@ static void nft_counter_reset(struct nft_counter_percpu_priv *priv, struct nft_counter *total) {struct nft_counter *this_cpu; +seqcount_t *myseq;local_bh_disable (); this_cpu =this_cpu_ptr (priv->counter); + myseq =this_cpu_ptr (&nft_counter_seq); + +write_seqcount_begin (myseq); this_cpu->packets -= total->packets; this_cpu->bytes -= total->bytes; +write_seqcount_end (myseq);local_bh_enable (); }
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 3/3 netfilter: flowtable: validate vlan header
In reply to Pablo Neira AyusoEnsure there is sufficient room to access the protocol field of the VLAN header, validate it once before the flowtable lookup.
=====================================================
BUG: KMSAN: uninit-value in nf_flow_offload_inet_hook+0x45a/0x5f0 net/netfilter/nf_flow_table_inet.c:32 nf_flow_offload_inet_hook+0x45a/0x5f0 net/netfilter/nf_flow_table_inet.c:32 nf_hook_entry_hookfn include/linux/netfilter.h:154 [inline] nf_hook_slow+0xf4/0x400 net/netfilter/core.c:626 nf_hook_ingress include/linux/netfilter_netdev.h:34 [inline] nf_ingress net/core/dev.c:5440 [inline]
--- net/netfilter/nf_flow_table_inet.c | 3 +++ net/netfilter/nf_flow_table_ip.c | 3 +++ 2 files changed, 6 insertions(+)
net/netfilter/nf_flow_table_inet.c +3 -0
@@ -17,6 +17,9 @@ nf_flow_offload_inet_hook(void *priv, struct sk_buff *skb,switch (skb->protocol) {case htons (ETH_P_8021Q ): +if (!pskb_may_pull (skb,VLAN_HLEN )) +return NF_ACCEPT ; + veth = (struct vlan_ethhdr *)skb_mac_header (skb); proto = veth->h_vlan_encapsulated_proto;break ;
net/netfilter/nf_flow_table_ip.c +3 -0
@@ -281,6 +281,9 @@ static bool nf_flow_skb_encap_protocol(struct sk_buff *skb, __be16 proto,switch (skb->protocol) {case htons (ETH_P_8021Q ): +if (!pskb_may_pull (skb,VLAN_HLEN )) +return false; + veth = (struct vlan_ethhdr *)skb_mac_header (skb);if (veth->h_vlan_encapsulated_proto == proto) { *offset +=VLAN_HLEN ;
Signature · 1 line
2.30.2
Re: [PATCH net 3/3] netfilter: flowtable: validate vlan header
Quoted 25 lines · Pablo Neira Ayuso
Ensure there is sufficient room to access the protocol field of the VLAN header, validate it once before the flowtable lookup.
=====================================================
BUG: KMSAN: uninit-value in nf_flow_offload_inet_hook+0x45a/0x5f0 net/netfilter/nf_flow_table_inet.c:32 nf_flow_offload_inet_hook+0x45a/0x5f0 net/netfilter/nf_flow_table_inet.c:32 nf_hook_entry_hookfn include/linux/netfilter.h:154 [inline] nf_hook_slow+0xf4/0x400 net/netfilter/core.c:626 nf_hook_ingress include/linux/netfilter_netdev.h:34 [inline] nf_ingress net/core/dev.c:5440 [inline]Fixes 4cd91f7c290f ("netfilter: flowtable: add vlan support")Reported-by [email protected]Signed-off-by Pablo Neira Ayuso <[email protected]>--- net/netfilter/nf_flow_table_inet.c | 3 +++ net/netfilter/nf_flow_table_ip.c | 3 +++ 2 files changed, 6 insertions(+)net/netfilter/nf_flow_table_inet.c +0
-0
net/netfilter/nf_flow_table_inet.c nf_flow_offload_inet_hook(void *priv, struct sk_buff *skb, · line 23
Quoted 7 lines
net/netfilter/nf_flow_table_inet.c +3
-0@@ -17,6 +17,9 @@ nf_flow_offload_inet_hook(void *priv, struct sk_buff *skb,switch (skb->protocol) {case htons (ETH_P_8021Q ): +if (!pskb_may_pull (skb,VLAN_HLEN )) +return NF_ACCEPT ; + veth = (struct vlan_ethhdr *)skb_mac_header (skb);
Is skb_mac_header(skb) always pointing at skb->data - 14 at this stage ?
Otherwise, using
if (!pskb_may_pull(skb, skb_mac_offset(skb) + sizeof(*veth)) would be safer.
Pablo Neira Ayuso
maintainerRe: [PATCH net 3/3] netfilter: flowtable: validate vlan header
Quoted 36 lines · Eric Dumazet
Quoted 25 lines · Pablo Neira Ayuso
Ensure there is sufficient room to access the protocol field of the VLAN header, validate it once before the flowtable lookup.
=====================================================
BUG: KMSAN: uninit-value in nf_flow_offload_inet_hook+0x45a/0x5f0 net/netfilter/nf_flow_table_inet.c:32 nf_flow_offload_inet_hook+0x45a/0x5f0 net/netfilter/nf_flow_table_inet.c:32 nf_hook_entry_hookfn include/linux/netfilter.h:154 [inline] nf_hook_slow+0xf4/0x400 net/netfilter/core.c:626 nf_hook_ingress include/linux/netfilter_netdev.h:34 [inline] nf_ingress net/core/dev.c:5440 [inline]Fixes 4cd91f7c290f ("netfilter: flowtable: add vlan support")Reported-by [email protected]Signed-off-by Pablo Neira Ayuso <[email protected]>--- net/netfilter/nf_flow_table_inet.c | 3 +++ net/netfilter/nf_flow_table_ip.c | 3 +++ 2 files changed, 6 insertions(+)net/netfilter/nf_flow_table_inet.c +0
-0net/netfilter/nf_flow_table_inet.c nf_flow_offload_inet_hook(void *priv, struct sk_buff *skb, · line 23
Quoted 7 lines
net/netfilter/nf_flow_table_inet.c +3
-0@@ -17,6 +17,9 @@ nf_flow_offload_inet_hook(void *priv, struct sk_buff *skb,switch (skb->protocol) {case htons (ETH_P_8021Q ): +if (!pskb_may_pull (skb,VLAN_HLEN )) +return NF_ACCEPT ; + veth = (struct vlan_ethhdr *)skb_mac_header (skb);Is
skb_mac_header(skb)always pointing atskb->data- 14 at this stage ?
Quoted 3 lines
Otherwise, using
if (!pskb_may_pull(skb,
skb_mac_offset(skb)+sizeof(*veth)) would be safer.
That looks consistent. Done and I just sent a new PR. Thanks.