Skip to content

Commit

Permalink
vxlan: Fix double free of skb.
Browse files Browse the repository at this point in the history
In case of error vxlan_xmit_one() can free already freed skb.
Also fixes memory leak of dst-entry.

Fixes: acbf74a ("vxlan: Refactor vxlan driver to make use
of the common UDP tunnel functions").

Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Pravin B Shelar authored and David S. Miller committed Dec 24, 2014
1 parent 997e068 commit 74f4727
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions drivers/net/vxlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1579,8 +1579,10 @@ static int vxlan6_xmit_skb(struct vxlan_sock *vs,
bool udp_sum = !udp_get_no_check6_tx(vs->sock->sk);

skb = udp_tunnel_handle_offloads(skb, udp_sum);
if (IS_ERR(skb))
return -EINVAL;
if (IS_ERR(skb)) {
err = -EINVAL;
goto err;
}

skb_scrub_packet(skb, xnet);

Expand All @@ -1590,12 +1592,16 @@ static int vxlan6_xmit_skb(struct vxlan_sock *vs,

/* Need space for new headers (invalidates iph ptr) */
err = skb_cow_head(skb, min_headroom);
if (unlikely(err))
return err;
if (unlikely(err)) {
kfree_skb(skb);
goto err;
}

skb = vlan_hwaccel_push_inside(skb);
if (WARN_ON(!skb))
return -ENOMEM;
if (WARN_ON(!skb)) {
err = -ENOMEM;
goto err;
}

vxh = (struct vxlanhdr *) __skb_push(skb, sizeof(*vxh));
vxh->vx_flags = htonl(VXLAN_FLAGS);
Expand All @@ -1606,6 +1612,9 @@ static int vxlan6_xmit_skb(struct vxlan_sock *vs,
udp_tunnel6_xmit_skb(vs->sock, dst, skb, dev, saddr, daddr, prio,
ttl, src_port, dst_port);
return 0;
err:
dst_release(dst);
return err;
}
#endif

Expand All @@ -1621,16 +1630,18 @@ int vxlan_xmit_skb(struct vxlan_sock *vs,

skb = udp_tunnel_handle_offloads(skb, udp_sum);
if (IS_ERR(skb))
return -EINVAL;
return PTR_ERR(skb);

min_headroom = LL_RESERVED_SPACE(rt->dst.dev) + rt->dst.header_len
+ VXLAN_HLEN + sizeof(struct iphdr)
+ (vlan_tx_tag_present(skb) ? VLAN_HLEN : 0);

/* Need space for new headers (invalidates iph ptr) */
err = skb_cow_head(skb, min_headroom);
if (unlikely(err))
if (unlikely(err)) {
kfree_skb(skb);
return err;
}

skb = vlan_hwaccel_push_inside(skb);
if (WARN_ON(!skb))
Expand Down Expand Up @@ -1776,9 +1787,12 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
tos, ttl, df, src_port, dst_port,
htonl(vni << 8),
!net_eq(vxlan->net, dev_net(vxlan->dev)));

if (err < 0)
if (err < 0) {
/* skb is already freed. */
skb = NULL;
goto rt_tx_error;
}

iptunnel_xmit_stats(err, &dev->stats, dev->tstats);
#if IS_ENABLED(CONFIG_IPV6)
} else {
Expand Down

0 comments on commit 74f4727

Please sign in to comment.