Skip to content

Commit db0090c

Browse files
edumazetkuba-moo
authored andcommitted
net: ipv6: rpl_iptunnel: block BH in rpl_output() and rpl_input()
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 rpl_output() is not good enough, because rpl_output() is called from process context, lwtunnel_output() only uses rcu_read_lock(). We might be interrupted by a softirq, re-enter rpl_output() and corrupt dst_cache data structures. Fix the race by using local_bh_disable() instead of preempt_disable(). Apply a similar change in rpl_input(). Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Alexander Aring <aahringo@redhat.com> Acked-by: Paolo Abeni <pabeni@redhat.com> Link: https://lore.kernel.org/r/20240531132636.2637995-3-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 2fe4048 commit db0090c

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

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))

0 commit comments

Comments
 (0)