Skip to content

Commit 0113d9c

Browse files
Kyle-Kyledavem330
authored andcommitted
ipv4: fix null-deref in ipv4_link_failure
Currently, we assume the skb is associated with a device before calling __ip_options_compile, which is not always the case if it is re-routed by ipvs. When skb->dev is NULL, dev_net(skb->dev) will become null-dereference. This patch adds a check for the edge case and switch to use the net_device from the rtable when skb->dev is NULL. Fixes: ed0de45 ("ipv4: recompile ip options in ipv4_link_failure") Suggested-by: David Ahern <[email protected]> Signed-off-by: Kyle Zeng <[email protected]> Cc: Stephen Suryaputra <[email protected]> Cc: Vadim Fedorenko <[email protected]> Reviewed-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent cb47b1f commit 0113d9c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

net/ipv4/route.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,7 @@ EXPORT_INDIRECT_CALLABLE(ipv4_dst_check);
12131213

12141214
static void ipv4_send_dest_unreach(struct sk_buff *skb)
12151215
{
1216+
struct net_device *dev;
12161217
struct ip_options opt;
12171218
int res;
12181219

@@ -1230,7 +1231,8 @@ static void ipv4_send_dest_unreach(struct sk_buff *skb)
12301231
opt.optlen = ip_hdr(skb)->ihl * 4 - sizeof(struct iphdr);
12311232

12321233
rcu_read_lock();
1233-
res = __ip_options_compile(dev_net(skb->dev), &opt, skb, NULL);
1234+
dev = skb->dev ? skb->dev : skb_rtable(skb)->dst.dev;
1235+
res = __ip_options_compile(dev_net(dev), &opt, skb, NULL);
12341236
rcu_read_unlock();
12351237

12361238
if (res)

0 commit comments

Comments
 (0)