]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
gve: fix the wrong AdminQ buffer overflow check
authorHaiyue Wang <haiyue.wang@intel.com>
Wed, 14 Jul 2021 07:34:59 +0000 (15:34 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 15 Sep 2021 08:00:37 +0000 (10:00 +0200)
[ Upstream commit 63a9192b8fa1ea55efeba1f18fad52bb24d9bf12 ]

The 'tail' pointer is also free-running count, so it needs to be masked
as 'adminq_prod_cnt' does, to become an index value of AdminQ buffer.

Fixes: 5cdad90de62c ("gve: Batch AQ commands for creating and destroying queues.")
Signed-off-by: Haiyue Wang <haiyue.wang@intel.com>
Reviewed-by: Catherine Sullivan <csully@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/google/gve/gve_adminq.c

index 53864f2005994f79b13cc3e1a4a0ffd2331ec72f..b175f2b2f5bcff8d79917c4fe6277b56bc4ae28a 100644 (file)
@@ -233,7 +233,8 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
        tail = ioread32be(&priv->reg_bar0->adminq_event_counter);
 
        // Check if next command will overflow the buffer.
-       if (((priv->adminq_prod_cnt + 1) & priv->adminq_mask) == tail) {
+       if (((priv->adminq_prod_cnt + 1) & priv->adminq_mask) ==
+           (tail & priv->adminq_mask)) {
                int err;
 
                // Flush existing commands to make room.
@@ -243,7 +244,8 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
 
                // Retry.
                tail = ioread32be(&priv->reg_bar0->adminq_event_counter);
-               if (((priv->adminq_prod_cnt + 1) & priv->adminq_mask) == tail) {
+               if (((priv->adminq_prod_cnt + 1) & priv->adminq_mask) ==
+                   (tail & priv->adminq_mask)) {
                        // This should never happen. We just flushed the
                        // command queue so there should be enough space.
                        return -ENOMEM;