OSDN Git Service

xen-netfront: re-order error checks in xennet_get_responses()
authorJan Beulich <jbeulich@suse.com>
Wed, 13 Jul 2022 09:19:55 +0000 (11:19 +0200)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 14 Jul 2022 10:20:18 +0000 (12:20 +0200)
Check the retrieved grant reference first; there's no point trying to
have xennet_move_rx_slot() move invalid data (and further defer
recognition of the issue, likely making diagnosis yet more difficult).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/xen-netfront.c

index 8bae9b8..27a11cc 100644 (file)
@@ -1043,16 +1043,6 @@ static int xennet_get_responses(struct netfront_queue *queue,
        }
 
        for (;;) {
-               if (unlikely(rx->status < 0 ||
-                            rx->offset + rx->status > XEN_PAGE_SIZE)) {
-                       if (net_ratelimit())
-                               dev_warn(dev, "rx->offset: %u, size: %d\n",
-                                        rx->offset, rx->status);
-                       xennet_move_rx_slot(queue, skb, ref);
-                       err = -EINVAL;
-                       goto next;
-               }
-
                /*
                 * This definitely indicates a bug, either in this driver or in
                 * the backend driver. In future this should flag the bad
@@ -1066,6 +1056,16 @@ static int xennet_get_responses(struct netfront_queue *queue,
                        goto next;
                }
 
+               if (unlikely(rx->status < 0 ||
+                            rx->offset + rx->status > XEN_PAGE_SIZE)) {
+                       if (net_ratelimit())
+                               dev_warn(dev, "rx->offset: %u, size: %d\n",
+                                        rx->offset, rx->status);
+                       xennet_move_rx_slot(queue, skb, ref);
+                       err = -EINVAL;
+                       goto next;
+               }
+
                if (!gnttab_end_foreign_access_ref(ref)) {
                        dev_alert(dev,
                                  "Grant still in use by backend domain\n");