Skip to content

Commit 34b2cef

Browse files
Eric Dumazetdavem330
authored andcommitted
ipv4: keep skb->dst around in presence of IP options
Andrey Konovalov got crashes in __ip_options_echo() when a NULL skb->dst is accessed. ipv4_pktinfo_prepare() should not drop the dst if (evil) IP options are present. We could refine the test to the presence of ts_needtime or srr, but IP options are not often used, so let's be conservative. Thanks to syzkaller team for finding this bug. Fixes: d826eb1 ("ipv4: PKTINFO doesnt need dst reference") Signed-off-by: Eric Dumazet <edumazet@google.com> Reported-by: Andrey Konovalov <andreyknvl@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5fa8bbd commit 34b2cef

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

net/ipv4/ip_sockglue.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,14 @@ void ipv4_pktinfo_prepare(const struct sock *sk, struct sk_buff *skb)
12381238
pktinfo->ipi_ifindex = 0;
12391239
pktinfo->ipi_spec_dst.s_addr = 0;
12401240
}
1241-
skb_dst_drop(skb);
1241+
/* We need to keep the dst for __ip_options_echo()
1242+
* We could restrict the test to opt.ts_needtime || opt.srr,
1243+
* but the following is good enough as IP options are not often used.
1244+
*/
1245+
if (unlikely(IPCB(skb)->opt.optlen))
1246+
skb_dst_force(skb);
1247+
else
1248+
skb_dst_drop(skb);
12421249
}
12431250

12441251
int ip_setsockopt(struct sock *sk, int level,

0 commit comments

Comments
 (0)