Skip to content

Commit 3ddbf7b

Browse files
committed
Merge tag 'nf-24-08-22' of git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf
Pablo Neira Ayuso says: ==================== Netfilter fixes for net 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. * tag 'nf-24-08-22' of git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf: netfilter: flowtable: validate vlan header netfilter: nft_counter: Synchronize nft_counter_reset() against reader. netfilter: nft_counter: Disable BH in nft_counter_offload_stats(). ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 2696c15 + 6ea14cc commit 3ddbf7b

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

net/netfilter/nf_flow_table_inet.c

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ nf_flow_offload_inet_hook(void *priv, struct sk_buff *skb,
1717

1818
switch (skb->protocol) {
1919
case htons(ETH_P_8021Q):
20+
if (!pskb_may_pull(skb, skb_mac_offset(skb) + sizeof(*veth)))
21+
return NF_ACCEPT;
22+
2023
veth = (struct vlan_ethhdr *)skb_mac_header(skb);
2124
proto = veth->h_vlan_encapsulated_proto;
2225
break;

net/netfilter/nf_flow_table_ip.c

+3
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ static bool nf_flow_skb_encap_protocol(struct sk_buff *skb, __be16 proto,
281281

282282
switch (skb->protocol) {
283283
case htons(ETH_P_8021Q):
284+
if (!pskb_may_pull(skb, skb_mac_offset(skb) + sizeof(*veth)))
285+
return false;
286+
284287
veth = (struct vlan_ethhdr *)skb_mac_header(skb);
285288
if (veth->h_vlan_encapsulated_proto == proto) {
286289
*offset += VLAN_HLEN;

net/netfilter/nft_counter.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,16 @@ static void nft_counter_reset(struct nft_counter_percpu_priv *priv,
107107
struct nft_counter *total)
108108
{
109109
struct nft_counter *this_cpu;
110+
seqcount_t *myseq;
110111

111112
local_bh_disable();
112113
this_cpu = this_cpu_ptr(priv->counter);
114+
myseq = this_cpu_ptr(&nft_counter_seq);
115+
116+
write_seqcount_begin(myseq);
113117
this_cpu->packets -= total->packets;
114118
this_cpu->bytes -= total->bytes;
119+
write_seqcount_end(myseq);
115120
local_bh_enable();
116121
}
117122

@@ -265,15 +270,15 @@ static void nft_counter_offload_stats(struct nft_expr *expr,
265270
struct nft_counter *this_cpu;
266271
seqcount_t *myseq;
267272

268-
preempt_disable();
273+
local_bh_disable();
269274
this_cpu = this_cpu_ptr(priv->counter);
270275
myseq = this_cpu_ptr(&nft_counter_seq);
271276

272277
write_seqcount_begin(myseq);
273278
this_cpu->packets += stats->pkts;
274279
this_cpu->bytes += stats->bytes;
275280
write_seqcount_end(myseq);
276-
preempt_enable();
281+
local_bh_enable();
277282
}
278283

279284
void nft_counter_init_seqcount(void)

0 commit comments

Comments
 (0)