Skip to content

Commit 1620c88

Browse files
committed
xfrm: Fix the usage of skb->sk
xfrm assumed to always have a full socket at skb->sk. This is not always true, so fix it by converting to a full socket before it is used. Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> Reviewed-by: Eric Dumazet <edumazet@google.com>
1 parent 600258d commit 1620c88

File tree

6 files changed

+10
-9
lines changed

6 files changed

+10
-9
lines changed

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(void *data, 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->sk, skb, err);
282+
xfrm_output_resume(skb_to_full_sk(skb), skb, err);
283283
}
284284
}
285285

net/ipv6/esp6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ static void esp_output_done(void *data, int err)
315315
x->encap && x->encap->encap_type == TCP_ENCAP_ESPINTCP)
316316
esp_output_tail_tcp(x, skb);
317317
else
318-
xfrm_output_resume(skb->sk, skb, err);
318+
xfrm_output_resume(skb_to_full_sk(skb), skb, err);
319319
}
320320
}
321321

net/ipv6/xfrm6_output.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ static int __xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
8282

8383
toobig = skb->len > mtu && !skb_is_gso(skb);
8484

85-
if (toobig && xfrm6_local_dontfrag(skb->sk)) {
85+
if (toobig && xfrm6_local_dontfrag(sk)) {
8686
xfrm6_local_rxpmtu(skb, mtu);
8787
kfree_skb(skb);
8888
return -EMSGSIZE;
8989
} else if (toobig && xfrm6_noneed_fragment(skb)) {
9090
skb->ignore_df = 1;
9191
goto skip_frag;
92-
} else if (!skb->ignore_df && toobig && skb->sk) {
92+
} else if (!skb->ignore_df && toobig && sk) {
9393
xfrm_local_error(skb, mtu);
9494
kfree_skb(skb);
9595
return -EMSGSIZE;

net/xfrm/xfrm_interface_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)
506506
skb_dst_set(skb, dst);
507507
skb->dev = tdev;
508508

509-
err = dst_output(xi->net, skb->sk, skb);
509+
err = dst_output(xi->net, skb_to_full_sk(skb), skb);
510510
if (net_xmit_eval(err) == 0) {
511511
dev_sw_netstats_tx_add(dev, 1, length);
512512
} else {

net/xfrm/xfrm_output.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ static int xfrm4_tunnel_check_size(struct sk_buff *skb)
796796
!skb_gso_validate_network_len(skb, ip_skb_dst_mtu(skb->sk, skb)))) {
797797
skb->protocol = htons(ETH_P_IP);
798798

799-
if (skb->sk)
799+
if (skb->sk && sk_fullsock(skb->sk))
800800
xfrm_local_error(skb, mtu);
801801
else
802802
icmp_send(skb, ICMP_DEST_UNREACH,
@@ -832,6 +832,7 @@ static int xfrm6_tunnel_check_size(struct sk_buff *skb)
832832
{
833833
int mtu, ret = 0;
834834
struct dst_entry *dst = skb_dst(skb);
835+
struct sock *sk = skb_to_full_sk(skb);
835836

836837
if (skb->ignore_df)
837838
goto out;
@@ -846,9 +847,9 @@ static int xfrm6_tunnel_check_size(struct sk_buff *skb)
846847
skb->dev = dst->dev;
847848
skb->protocol = htons(ETH_P_IPV6);
848849

849-
if (xfrm6_local_dontfrag(skb->sk))
850+
if (xfrm6_local_dontfrag(sk))
850851
ipv6_stub->xfrm6_local_rxpmtu(skb, mtu);
851-
else if (skb->sk)
852+
else if (sk)
852853
xfrm_local_error(skb, mtu);
853854
else
854855
icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);

net/xfrm/xfrm_policy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2959,7 +2959,7 @@ static void xfrm_policy_queue_process(struct timer_list *t)
29592959
skb_dst_drop(skb);
29602960
skb_dst_set(skb, dst);
29612961

2962-
dst_output(net, skb->sk, skb);
2962+
dst_output(net, skb_to_full_sk(skb), skb);
29632963
}
29642964

29652965
out:

0 commit comments

Comments
 (0)