Skip to content

Commit

Permalink
virtio_net: fix use after free
Browse files Browse the repository at this point in the history
commit 0b725a2
    net: Remove ndo_xmit_flush netdev operation, use signalling instead.

added code that looks at skb->xmit_more after the skb has
been put in TX VQ. Since some paths process the ring and free the skb
immediately, this can cause use after free.

Fix by storing xmit_more in a local variable.

Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Michael S. Tsirkin authored and David S. Miller committed Oct 15, 2014
1 parent 28b5f05 commit 4b7fd2e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/net/virtio_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,8 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
int qnum = skb_get_queue_mapping(skb);
struct send_queue *sq = &vi->sq[qnum];
int err;
struct netdev_queue *txq = netdev_get_tx_queue(dev, qnum);
bool kick = !skb->xmit_more;

/* Free up any pending old buffers before queueing new ones. */
free_old_xmit_skbs(sq);
Expand Down Expand Up @@ -956,7 +958,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
}
}

if (__netif_subqueue_stopped(dev, qnum) || !skb->xmit_more)
if (kick || netif_xmit_stopped(txq))
virtqueue_kick(sq->vq);

return NETDEV_TX_OK;
Expand Down

0 comments on commit 4b7fd2e

Please sign in to comment.