Commit 7eb2e251 authored by Rusty Russell's avatar Rusty Russell Committed by Jeff Garzik

virtio: fix virtio_net xmit of freed skb bug

If we fail to transmit a packet, we assume the queue is full and put
the skb into last_xmit_skb.  However, if more space frees up before we
xmit it, we loop, and the result can be transmitting the same skb twice.

Fix is simple: set skb to NULL if we've used it in some way, and check
before sending.
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
Signed-off-by: default avatarJeff Garzik <jgarzik@redhat.com>
parent d399cf8c
...@@ -287,22 +287,26 @@ static int start_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -287,22 +287,26 @@ static int start_xmit(struct sk_buff *skb, struct net_device *dev)
free_old_xmit_skbs(vi); free_old_xmit_skbs(vi);
/* If we has a buffer left over from last time, send it now. */ /* If we has a buffer left over from last time, send it now. */
if (vi->last_xmit_skb) { if (unlikely(vi->last_xmit_skb)) {
if (xmit_skb(vi, vi->last_xmit_skb) != 0) { if (xmit_skb(vi, vi->last_xmit_skb) != 0) {
/* Drop this skb: we only queue one. */ /* Drop this skb: we only queue one. */
vi->dev->stats.tx_dropped++; vi->dev->stats.tx_dropped++;
kfree_skb(skb); kfree_skb(skb);
skb = NULL;
goto stop_queue; goto stop_queue;
} }
vi->last_xmit_skb = NULL; vi->last_xmit_skb = NULL;
} }
/* Put new one in send queue and do transmit */ /* Put new one in send queue and do transmit */
if (likely(skb)) {
__skb_queue_head(&vi->send, skb); __skb_queue_head(&vi->send, skb);
if (xmit_skb(vi, skb) != 0) { if (xmit_skb(vi, skb) != 0) {
vi->last_xmit_skb = skb; vi->last_xmit_skb = skb;
skb = NULL;
goto stop_queue; goto stop_queue;
} }
}
done: done:
vi->svq->vq_ops->kick(vi->svq); vi->svq->vq_ops->kick(vi->svq);
return NETDEV_TX_OK; return NETDEV_TX_OK;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment