Skip to content

Commit

Permalink
Merge branch 'dst_cache-fix-possible-races'
Browse files Browse the repository at this point in the history
Eric Dumazet says:

====================
dst_cache: fix possible races

This series is inspired by various undisclosed syzbot
reports hinting at corruptions in dst_cache structures.

It seems at least four users of dst_cache are racy against
BH reentrancy.

Last patch is adding a DEBUG_NET check to catch future misuses.
====================

Link: https://lore.kernel.org/r/20240531132636.2637995-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Jun 4, 2024
2 parents ffbe335 + 2fe6fb3 commit d730a42
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
2 changes: 2 additions & 0 deletions net/core/dst_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct dst_cache_pcpu {
static void dst_cache_per_cpu_dst_set(struct dst_cache_pcpu *dst_cache,
struct dst_entry *dst, u32 cookie)
{
DEBUG_NET_WARN_ON_ONCE(!in_softirq());
dst_release(dst_cache->dst);
if (dst)
dst_hold(dst);
Expand All @@ -40,6 +41,7 @@ static struct dst_entry *dst_cache_per_cpu_get(struct dst_cache *dst_cache,
{
struct dst_entry *dst;

DEBUG_NET_WARN_ON_ONCE(!in_softirq());
dst = idst->dst;
if (!dst)
goto fail;
Expand Down
7 changes: 6 additions & 1 deletion net/ipv6/ila/ila_lwt.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ static int ila_output(struct net *net, struct sock *sk, struct sk_buff *skb)
return orig_dst->lwtstate->orig_output(net, sk, skb);
}

local_bh_disable();
dst = dst_cache_get(&ilwt->dst_cache);
local_bh_enable();
if (unlikely(!dst)) {
struct ipv6hdr *ip6h = ipv6_hdr(skb);
struct flowi6 fl6;
Expand Down Expand Up @@ -86,8 +88,11 @@ static int ila_output(struct net *net, struct sock *sk, struct sk_buff *skb)
goto drop;
}

if (ilwt->connected)
if (ilwt->connected) {
local_bh_disable();
dst_cache_set_ip6(&ilwt->dst_cache, dst, &fl6.saddr);
local_bh_enable();
}
}

skb_dst_set(skb, dst);
Expand Down
8 changes: 4 additions & 4 deletions net/ipv6/ioam6_iptunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,9 @@ static int ioam6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
goto drop;

if (!ipv6_addr_equal(&orig_daddr, &ipv6_hdr(skb)->daddr)) {
preempt_disable();
local_bh_disable();
dst = dst_cache_get(&ilwt->cache);
preempt_enable();
local_bh_enable();

if (unlikely(!dst)) {
struct ipv6hdr *hdr = ipv6_hdr(skb);
Expand All @@ -373,9 +373,9 @@ static int ioam6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
goto drop;
}

preempt_disable();
local_bh_disable();
dst_cache_set_ip6(&ilwt->cache, dst, &fl6.saddr);
preempt_enable();
local_bh_enable();
}

skb_dst_drop(skb);
Expand Down
14 changes: 6 additions & 8 deletions net/ipv6/rpl_iptunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ static int rpl_output(struct net *net, struct sock *sk, struct sk_buff *skb)
if (unlikely(err))
goto drop;

preempt_disable();
local_bh_disable();
dst = dst_cache_get(&rlwt->cache);
preempt_enable();
local_bh_enable();

if (unlikely(!dst)) {
struct ipv6hdr *hdr = ipv6_hdr(skb);
Expand All @@ -234,9 +234,9 @@ static int rpl_output(struct net *net, struct sock *sk, struct sk_buff *skb)
goto drop;
}

preempt_disable();
local_bh_disable();
dst_cache_set_ip6(&rlwt->cache, dst, &fl6.saddr);
preempt_enable();
local_bh_enable();
}

skb_dst_drop(skb);
Expand Down Expand Up @@ -268,23 +268,21 @@ static int rpl_input(struct sk_buff *skb)
return err;
}

preempt_disable();
local_bh_disable();
dst = dst_cache_get(&rlwt->cache);
preempt_enable();

if (!dst) {
ip6_route_input(skb);
dst = skb_dst(skb);
if (!dst->error) {
preempt_disable();
dst_cache_set_ip6(&rlwt->cache, dst,
&ipv6_hdr(skb)->saddr);
preempt_enable();
}
} else {
skb_dst_drop(skb);
skb_dst_set(skb, dst);
}
local_bh_enable();

err = skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev));
if (unlikely(err))
Expand Down
14 changes: 6 additions & 8 deletions net/ipv6/seg6_iptunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,23 +464,21 @@ static int seg6_input_core(struct net *net, struct sock *sk,

slwt = seg6_lwt_lwtunnel(orig_dst->lwtstate);

preempt_disable();
local_bh_disable();
dst = dst_cache_get(&slwt->cache);
preempt_enable();

if (!dst) {
ip6_route_input(skb);
dst = skb_dst(skb);
if (!dst->error) {
preempt_disable();
dst_cache_set_ip6(&slwt->cache, dst,
&ipv6_hdr(skb)->saddr);
preempt_enable();
}
} else {
skb_dst_drop(skb);
skb_dst_set(skb, dst);
}
local_bh_enable();

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

slwt = seg6_lwt_lwtunnel(orig_dst->lwtstate);

preempt_disable();
local_bh_disable();
dst = dst_cache_get(&slwt->cache);
preempt_enable();
local_bh_enable();

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

preempt_disable();
local_bh_disable();
dst_cache_set_ip6(&slwt->cache, dst, &fl6.saddr);
preempt_enable();
local_bh_enable();
}

skb_dst_drop(skb);
Expand Down

0 comments on commit d730a42

Please sign in to comment.