Skip to content

Commit c0b98ac

Browse files
edumazetkuba-moo
authored andcommitted
ipv6: sr: block BH in seg6_output_core() and seg6_input_core()
As explained in commit 1378817 ("tipc: block BH before using dst_cache"), net/core/dst_cache.c helpers need to be called with BH disabled. Disabling preemption in seg6_output_core() is not good enough, because seg6_output_core() is called from process context, lwtunnel_output() only uses rcu_read_lock(). We might be interrupted by a softirq, re-enter seg6_output_core() and corrupt dst_cache data structures. Fix the race by using local_bh_disable() instead of preempt_disable(). Apply a similar change in seg6_input_core(). Fixes: fa79581 ("ipv6: sr: fix several BUGs when preemption is enabled") Fixes: 6c8702c ("ipv6: sr: add support for SRH encapsulation and injection with lwtunnels") Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: David Lebrun <dlebrun@google.com> Acked-by: Paolo Abeni <pabeni@redhat.com> Link: https://lore.kernel.org/r/20240531132636.2637995-4-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent db0090c commit c0b98ac

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

net/ipv6/seg6_iptunnel.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -464,23 +464,21 @@ static int seg6_input_core(struct net *net, struct sock *sk,
464464

465465
slwt = seg6_lwt_lwtunnel(orig_dst->lwtstate);
466466

467-
preempt_disable();
467+
local_bh_disable();
468468
dst = dst_cache_get(&slwt->cache);
469-
preempt_enable();
470469

471470
if (!dst) {
472471
ip6_route_input(skb);
473472
dst = skb_dst(skb);
474473
if (!dst->error) {
475-
preempt_disable();
476474
dst_cache_set_ip6(&slwt->cache, dst,
477475
&ipv6_hdr(skb)->saddr);
478-
preempt_enable();
479476
}
480477
} else {
481478
skb_dst_drop(skb);
482479
skb_dst_set(skb, dst);
483480
}
481+
local_bh_enable();
484482

485483
err = skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev));
486484
if (unlikely(err))
@@ -536,9 +534,9 @@ static int seg6_output_core(struct net *net, struct sock *sk,
536534

537535
slwt = seg6_lwt_lwtunnel(orig_dst->lwtstate);
538536

539-
preempt_disable();
537+
local_bh_disable();
540538
dst = dst_cache_get(&slwt->cache);
541-
preempt_enable();
539+
local_bh_enable();
542540

543541
if (unlikely(!dst)) {
544542
struct ipv6hdr *hdr = ipv6_hdr(skb);
@@ -558,9 +556,9 @@ static int seg6_output_core(struct net *net, struct sock *sk,
558556
goto drop;
559557
}
560558

561-
preempt_disable();
559+
local_bh_disable();
562560
dst_cache_set_ip6(&slwt->cache, dst, &fl6.saddr);
563-
preempt_enable();
561+
local_bh_enable();
564562
}
565563

566564
skb_dst_drop(skb);

0 commit comments

Comments
 (0)