From: Toshiaki Makita Date: Tue, 29 Jan 2019 00:45:56 +0000 (+0900) Subject: virtio_net: Fix out of bounds access of sq X-Git-Tag: v4.19.20~46 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0921dd505d30a4028425abf7e02e961a1c45cba0;p=platform%2Fkernel%2Flinux-rpi3.git virtio_net: Fix out of bounds access of sq [ Upstream commit 1667c08a9d31c7cdf09f4890816bfbf20b685495 ] When XDP is disabled, curr_queue_pairs + smp_processor_id() can be larger than max_queue_pairs. There is no guarantee that we have enough XDP send queues dedicated for each cpu when XDP is disabled, so do not count drops on sq in that case. Fixes: 5b8f3c8d30a6 ("virtio_net: Add XDP related stats") Signed-off-by: Toshiaki Makita Acked-by: Jason Wang Acked-by: Michael S. Tsirkin Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 6bea1fe..94a6f72 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -490,20 +490,17 @@ static int virtnet_xdp_xmit(struct net_device *dev, int ret, err; int i; - sq = virtnet_xdp_sq(vi); - - if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK)) { - ret = -EINVAL; - drops = n; - goto out; - } - /* Only allow ndo_xdp_xmit if XDP is loaded on dev, as this * indicate XDP resources have been successfully allocated. */ xdp_prog = rcu_dereference(rq->xdp_prog); - if (!xdp_prog) { - ret = -ENXIO; + if (!xdp_prog) + return -ENXIO; + + sq = virtnet_xdp_sq(vi); + + if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK)) { + ret = -EINVAL; drops = n; goto out; }