All of lore.kernel.org
 help / color / mirror / Atom feed
From: Toshiaki Makita <makita.toshiaki@lab.ntt.co.jp>
To: "David S. Miller" <davem@davemloft.net>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>
Cc: netdev@vger.kernel.org, virtualization@lists.linux-foundation.org
Subject: [PATCH v2 net 4/7] virtio_net: Fix out of bounds access of sq
Date: Tue, 29 Jan 2019 09:45:56 +0900	[thread overview]
Message-ID: <1548722759-2470-5-git-send-email-makita.toshiaki__39460.6924893864$1548742691$gmane$org@lab.ntt.co.jp> (raw)
In-Reply-To: <1548722759-2470-1-git-send-email-makita.toshiaki@lab.ntt.co.jp>

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 <makita.toshiaki@lab.ntt.co.jp>
Acked-by: Jason Wang <jasowang@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/net/virtio_net.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 0e1a369..669b65c 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -491,20 +491,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;
 	}
-- 
1.8.3.1

  parent reply	other threads:[~2019-01-29  0:45 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-29  0:45 [PATCH v2 net 0/7] virtio_net: Fix problems around XDP tx and napi_tx Toshiaki Makita
2019-01-29  0:45 ` [PATCH v2 net 1/7] virtio_net: Don't enable NAPI when interface is down Toshiaki Makita
2019-01-29  0:45 ` Toshiaki Makita
2019-01-29  0:45 ` [PATCH v2 net 2/7] virtio_net: Don't call free_old_xmit_skbs for xdp_frames Toshiaki Makita
2019-01-29  0:45 ` Toshiaki Makita
2019-01-29  0:45 ` [PATCH v2 net 3/7] virtio_net: Fix not restoring real_num_rx_queues Toshiaki Makita
2019-01-29  0:45 ` Toshiaki Makita
2019-01-29  0:45 ` [PATCH v2 net 4/7] virtio_net: Fix out of bounds access of sq Toshiaki Makita
2019-01-29  0:45 ` Toshiaki Makita [this message]
2019-01-29  0:45 ` [PATCH v2 net 5/7] virtio_net: Don't process redirected XDP frames when XDP is disabled Toshiaki Makita
2019-01-29  2:20   ` Jason Wang
2019-01-29  2:20   ` Jason Wang
2019-01-29 22:50   ` Michael S. Tsirkin
2019-01-29 22:50   ` Michael S. Tsirkin
2019-01-29  0:45 ` Toshiaki Makita
2019-01-29  0:45 ` [PATCH v2 net 6/7] virtio_net: Use xdp_return_frame to free xdp_frames on destroying vqs Toshiaki Makita
2019-01-29  0:45 ` Toshiaki Makita
2019-01-29  0:45 ` [PATCH v2 net 7/7] virtio_net: Differentiate sk_buff and xdp_frame on freeing Toshiaki Makita
2019-01-29  2:23   ` Jason Wang
2019-01-29  2:23   ` Jason Wang
2019-01-29  2:35     ` Toshiaki Makita
2019-01-29  2:35     ` Toshiaki Makita
2019-01-29  2:49       ` Jason Wang
2019-01-29  2:49       ` Jason Wang
2019-01-29 22:51   ` Michael S. Tsirkin
2019-01-29 22:51   ` Michael S. Tsirkin
2019-01-29  0:45 ` Toshiaki Makita
2019-01-30 22:03 ` [PATCH v2 net 0/7] virtio_net: Fix problems around XDP tx and napi_tx David Miller
2019-01-30 22:03 ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='1548722759-2470-5-git-send-email-makita.toshiaki__39460.6924893864$1548742691$gmane$org@lab.ntt.co.jp' \
    --to=makita.toshiaki@lab.ntt.co.jp \
    --cc=davem@davemloft.net \
    --cc=jasowang@redhat.com \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.