Skip to content

Commit d730a42

Browse files
committed
Merge branch 'dst_cache-fix-possible-races'
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>
2 parents ffbe335 + 2fe6fb3 commit d730a42

5 files changed

Lines changed: 24 additions & 21 deletions

File tree

net/core/dst_cache.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct dst_cache_pcpu {
2727
static void dst_cache_per_cpu_dst_set(struct dst_cache_pcpu *dst_cache,
2828
struct dst_entry *dst, u32 cookie)
2929
{
30+
DEBUG_NET_WARN_ON_ONCE(!in_softirq());
3031
dst_release(dst_cache->dst);
3132
if (dst)
3233
dst_hold(dst);
@@ -40,6 +41,7 @@ static struct dst_entry *dst_cache_per_cpu_get(struct dst_cache *dst_cache,
4041
{
4142
struct dst_entry *dst;
4243

44+
DEBUG_NET_WARN_ON_ONCE(!in_softirq());
4345
dst = idst->dst;
4446
if (!dst)
4547
goto fail;

net/ipv6/ila/ila_lwt.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ static int ila_output(struct net *net, struct sock *sk, struct sk_buff *skb)
5858
return orig_dst->lwtstate->orig_output(net, sk, skb);
5959
}
6060

61+
local_bh_disable();
6162
dst = dst_cache_get(&ilwt->dst_cache);
63+
local_bh_enable();
6264
if (unlikely(!dst)) {
6365
struct ipv6hdr *ip6h = ipv6_hdr(skb);
6466
struct flowi6 fl6;
@@ -86,8 +88,11 @@ static int ila_output(struct net *net, struct sock *sk, struct sk_buff *skb)
8688
goto drop;
8789
}
8890

89-
if (ilwt->connected)
91+
if (ilwt->connected) {
92+
local_bh_disable();
9093
dst_cache_set_ip6(&ilwt->dst_cache, dst, &fl6.saddr);
94+
local_bh_enable();
95+
}
9196
}
9297

9398
skb_dst_set(skb, dst);

net/ipv6/ioam6_iptunnel.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,9 @@ static int ioam6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
351351
goto drop;
352352

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

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

376-
preempt_disable();
376+
local_bh_disable();
377377
dst_cache_set_ip6(&ilwt->cache, dst, &fl6.saddr);
378-
preempt_enable();
378+
local_bh_enable();
379379
}
380380

381381
skb_dst_drop(skb);

net/ipv6/rpl_iptunnel.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ static int rpl_output(struct net *net, struct sock *sk, struct sk_buff *skb)
212212
if (unlikely(err))
213213
goto drop;
214214

215-
preempt_disable();
215+
local_bh_disable();
216216
dst = dst_cache_get(&rlwt->cache);
217-
preempt_enable();
217+
local_bh_enable();
218218

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

237-
preempt_disable();
237+
local_bh_disable();
238238
dst_cache_set_ip6(&rlwt->cache, dst, &fl6.saddr);
239-
preempt_enable();
239+
local_bh_enable();
240240
}
241241

242242
skb_dst_drop(skb);
@@ -268,23 +268,21 @@ static int rpl_input(struct sk_buff *skb)
268268
return err;
269269
}
270270

271-
preempt_disable();
271+
local_bh_disable();
272272
dst = dst_cache_get(&rlwt->cache);
273-
preempt_enable();
274273

275274
if (!dst) {
276275
ip6_route_input(skb);
277276
dst = skb_dst(skb);
278277
if (!dst->error) {
279-
preempt_disable();
280278
dst_cache_set_ip6(&rlwt->cache, dst,
281279
&ipv6_hdr(skb)->saddr);
282-
preempt_enable();
283280
}
284281
} else {
285282
skb_dst_drop(skb);
286283
skb_dst_set(skb, dst);
287284
}
285+
local_bh_enable();
288286

289287
err = skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev));
290288
if (unlikely(err))

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)