Skip to content

Commit c7a175a

Browse files
Evann-atlgregkh
authored andcommitted
xfrm: Use actual socket sk instead of skb socket for xfrm_output_resume
[ Upstream commit 9ab1265 ] A situation can occur where the interface bound to the sk is different to the interface bound to the sk attached to the skb. The interface bound to the sk is the correct one however this information is lost inside xfrm_output2 and instead the sk on the skb is used in xfrm_output_resume instead. This assumes that the sk bound interface and the bound interface attached to the sk within the skb are the same which can lead to lookup failures inside ip_route_me_harder resulting in the packet being dropped. We have an l2tp v3 tunnel with ipsec protection. The tunnel is in the global VRF however we have an encapsulated dot1q tunnel interface that is within a different VRF. We also have a mangle rule that marks the packets causing them to be processed inside ip_route_me_harder. Prior to commit 31c70d5 ("l2tp: keep original skb ownership") this worked fine as the sk attached to the skb was changed from the dot1q encapsulated interface to the sk for the tunnel which meant the interface bound to the sk and the interface bound to the skb were identical. Commit 46d6c5a ("netfilter: use actual socket sk rather than skb sk when routing harder") fixed some of these issues however a similar problem existed in the xfrm code. Fixes: 31c70d5 ("l2tp: keep original skb ownership") Signed-off-by: Evan Nimmo <evan.nimmo@alliedtelesis.co.nz> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 3b74ce5 commit c7a175a

6 files changed

Lines changed: 10 additions & 10 deletions

File tree

‎include/net/xfrm.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ int xfrm_trans_queue_net(struct net *net, struct sk_buff *skb,
15571557
int xfrm_trans_queue(struct sk_buff *skb,
15581558
int (*finish)(struct net *, struct sock *,
15591559
struct sk_buff *));
1560-
int xfrm_output_resume(struct sk_buff *skb, int err);
1560+
int xfrm_output_resume(struct sock *sk, struct sk_buff *skb, int err);
15611561
int xfrm_output(struct sock *sk, struct sk_buff *skb);
15621562

15631563
#if IS_ENABLED(CONFIG_NET_PKTGEN)

‎net/ipv4/ah4.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static void ah_output_done(struct crypto_async_request *base, int err)
141141
}
142142

143143
kfree(AH_SKB_CB(skb)->tmp);
144-
xfrm_output_resume(skb, err);
144+
xfrm_output_resume(skb->sk, skb, err);
145145
}
146146

147147
static int ah_output(struct xfrm_state *x, struct sk_buff *skb)

‎net/ipv4/esp4.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static void esp_output_done(struct crypto_async_request *base, int err)
279279
x->encap && x->encap->encap_type == TCP_ENCAP_ESPINTCP)
280280
esp_output_tail_tcp(x, skb);
281281
else
282-
xfrm_output_resume(skb, err);
282+
xfrm_output_resume(skb->sk, skb, err);
283283
}
284284
}
285285

‎net/ipv6/ah6.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ static void ah6_output_done(struct crypto_async_request *base, int err)
316316
}
317317

318318
kfree(AH_SKB_CB(skb)->tmp);
319-
xfrm_output_resume(skb, err);
319+
xfrm_output_resume(skb->sk, skb, err);
320320
}
321321

322322
static int ah6_output(struct xfrm_state *x, struct sk_buff *skb)

‎net/ipv6/esp6.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ static void esp_output_done(struct crypto_async_request *base, int err)
314314
x->encap && x->encap->encap_type == TCP_ENCAP_ESPINTCP)
315315
esp_output_tail_tcp(x, skb);
316316
else
317-
xfrm_output_resume(skb, err);
317+
xfrm_output_resume(skb->sk, skb, err);
318318
}
319319
}
320320

‎net/xfrm/xfrm_output.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -503,22 +503,22 @@ static int xfrm_output_one(struct sk_buff *skb, int err)
503503
return err;
504504
}
505505

506-
int xfrm_output_resume(struct sk_buff *skb, int err)
506+
int xfrm_output_resume(struct sock *sk, struct sk_buff *skb, int err)
507507
{
508508
struct net *net = xs_net(skb_dst(skb)->xfrm);
509509

510510
while (likely((err = xfrm_output_one(skb, err)) == 0)) {
511511
nf_reset_ct(skb);
512512

513-
err = skb_dst(skb)->ops->local_out(net, skb->sk, skb);
513+
err = skb_dst(skb)->ops->local_out(net, sk, skb);
514514
if (unlikely(err != 1))
515515
goto out;
516516

517517
if (!skb_dst(skb)->xfrm)
518-
return dst_output(net, skb->sk, skb);
518+
return dst_output(net, sk, skb);
519519

520520
err = nf_hook(skb_dst(skb)->ops->family,
521-
NF_INET_POST_ROUTING, net, skb->sk, skb,
521+
NF_INET_POST_ROUTING, net, sk, skb,
522522
NULL, skb_dst(skb)->dev, xfrm_output2);
523523
if (unlikely(err != 1))
524524
goto out;
@@ -534,7 +534,7 @@ EXPORT_SYMBOL_GPL(xfrm_output_resume);
534534

535535
static int xfrm_output2(struct net *net, struct sock *sk, struct sk_buff *skb)
536536
{
537-
return xfrm_output_resume(skb, 1);
537+
return xfrm_output_resume(sk, skb, 1);
538538
}
539539

540540
static int xfrm_output_gso(struct net *net, struct sock *sk, struct sk_buff *skb)

0 commit comments

Comments
 (0)