Skip to content

Commit 29e0922

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: use skb_to_full_sk in ip_route_me_harder
inet_sk(skb->sk) is illegal in case skb is attached to request socket. Fixes: ca6fb06 ("tcp: attach SYNACK messages to request sockets instead of listener") Reported by: Daniel J Blueman <[email protected]> Signed-off-by: Florian Westphal <[email protected]> Tested-by: Daniel J Blueman <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 2f44f75 commit 29e0922

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

net/ipv4/netfilter.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ int ip_route_me_harder(struct net *net, struct sk_buff *skb, unsigned int addr_t
2323
struct rtable *rt;
2424
struct flowi4 fl4 = {};
2525
__be32 saddr = iph->saddr;
26-
__u8 flags = skb->sk ? inet_sk_flowi_flags(skb->sk) : 0;
26+
const struct sock *sk = skb_to_full_sk(skb);
27+
__u8 flags = sk ? inet_sk_flowi_flags(sk) : 0;
2728
struct net_device *dev = skb_dst(skb)->dev;
2829
unsigned int hh_len;
2930

@@ -40,7 +41,7 @@ int ip_route_me_harder(struct net *net, struct sk_buff *skb, unsigned int addr_t
4041
fl4.daddr = iph->daddr;
4142
fl4.saddr = saddr;
4243
fl4.flowi4_tos = RT_TOS(iph->tos);
43-
fl4.flowi4_oif = skb->sk ? skb->sk->sk_bound_dev_if : 0;
44+
fl4.flowi4_oif = sk ? sk->sk_bound_dev_if : 0;
4445
if (!fl4.flowi4_oif)
4546
fl4.flowi4_oif = l3mdev_master_ifindex(dev);
4647
fl4.flowi4_mark = skb->mark;
@@ -61,7 +62,7 @@ int ip_route_me_harder(struct net *net, struct sk_buff *skb, unsigned int addr_t
6162
xfrm_decode_session(skb, flowi4_to_flowi(&fl4), AF_INET) == 0) {
6263
struct dst_entry *dst = skb_dst(skb);
6364
skb_dst_set(skb, NULL);
64-
dst = xfrm_lookup(net, dst, flowi4_to_flowi(&fl4), skb->sk, 0);
65+
dst = xfrm_lookup(net, dst, flowi4_to_flowi(&fl4), sk, 0);
6566
if (IS_ERR(dst))
6667
return PTR_ERR(dst);
6768
skb_dst_set(skb, dst);

0 commit comments

Comments
 (0)