[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH net-next] xen-netback: size the queue name for multi-digit ids



xenvif_connect() names each queue with

        snprintf(queue->name, sizeof(queue->name), "%s-q%u",
                 be->vif->dev->name, queue->id);

QUEUE_NAME_SIZE is IFNAMSIZ + 5, which has room for a three digit queue
id.  The interface name can be 15 characters and %u can print ten
digits, so the format can produce 28 bytes including the terminator into
a 21 byte buffer.  gcc notices this in a W=1 build, and CONFIG_WERROR
turns it into a build failure:

  drivers/net/xen-netback/xenbus.c:783:65: error: '%u' directive output
    may be truncated writing between 1 and 10 bytes into a region of
    size between 4 and 19 [-Werror=format-truncation=]

The id is bounded by the multi-queue-num-queues value that the guest
requests, which xen-netback validates against the max_queues module
parameter, but gcc analyses the full range of %u.

Size the buffer for what the format allows: IFNAMSIZ + 12 covers the 15
character interface name, "-q", ten digits and the terminator, and
IRQ_NAME_SIZE, which derives from it, still fits the "-tx" and "-rx"
suffixes.

No functional change for the default configuration.

Reported-by: kernel test robot <lkp@xxxxxxxxx>
Closes: https://lore.kernel.org/r/202606111107.k8nf2OCl-lkp@xxxxxxxxx/
Signed-off-by: Aibing Chen <chenaibing@xxxxxxxxxxxxxxxxxxxx>
---
 drivers/net/xen-netback/common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/xen-netback/common.h b/drivers/net/xen-netback/common.h
index 17421da13..b12fbb19a 100644
--- a/drivers/net/xen-netback/common.h
+++ b/drivers/net/xen-netback/common.h
@@ -98,7 +98,7 @@ struct xenvif_rx_meta {
 #define XEN_NETBK_LEGACY_SLOTS_MAX XEN_NETIF_NR_SLOTS_MIN
 
 /* Queue name is interface name with "-qNNN" appended */
-#define QUEUE_NAME_SIZE (IFNAMSIZ + 5)
+#define QUEUE_NAME_SIZE (IFNAMSIZ + 12)
 
 /* IRQ name is queue name with "-tx" or "-rx" appended */
 #define IRQ_NAME_SIZE (QUEUE_NAME_SIZE + 3)





 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.