Skip to contentSkip to conversation

gve: fix the wrong AdminQ buffer overflow check

PATCH Applied Haiyue Wang 3 participants 3 messages Jul 14, 2021 – Jul 16, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gve: fix the wrong AdminQ buffer overflow check

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.")
---
 drivers/net/ethernet/google/gve/gve_adminq.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/google/gve/gve_adminq.c +4 -2
index 5bb56b454541..f089d33dd48e 100644
@@ -322,7 +322,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.
@@ -332,7 +333,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;
Signature · 1 line
2.32.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Haiyue Wang

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.")
Quoted 29 lines
---
 drivers/net/ethernet/google/gve/gve_adminq.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/google/gve/gve_adminq.c +4 -3
index 5bb56b454541..f089d33dd48e 100644
@@ -322,7 +322,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.
@@ -332,7 +333,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;
--
Quoted 2 lines

2.32.0

Thanks!

#2 lore raw
In reply to Haiyue Wang
This patch was applied to netdev/net-next.git (refs/heads/master):

Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

Quoted 8 lines · On Wed, 14 Jul 2021 15:34:59 +0800 you wrote:

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.")
---
 drivers/net/ethernet/google/gve/gve_adminq.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Here is the summary with links:
- [v1] gve: fix the wrong AdminQ buffer overflow check

    https://git.kernel.org/netdev/net-next/c/63a9192b8fa1

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html