OSDN Git Service

i40e: force VMDQ device name truncation
authorJacob Keller <jacob.e.keller@intel.com>
Wed, 12 Jul 2017 09:46:12 +0000 (05:46 -0400)
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>
Sun, 27 Aug 2017 22:44:04 +0000 (15:44 -0700)
In new versions of GCC since 7.x a new warning exists which warns when
a string is truncated before all of the format can be completed.

When we setup VMDQ netdev names we are copying a pre-existing interface
name which could be up to 15 characters in length. Since we also add
4 bytes, v, the literal %, the d and a \0 null, we would overrun the
available size unless snprintf truncated for us.

The snprintf call will of course truncate on the end, so lets instead
modify the code to force truncation of the copied netdev name by
4 characters, to create enough space for the 4 bytes we're adding.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
drivers/net/ethernet/intel/i40e/i40e_main.c

index b0ccd3c..3a6a752 100644 (file)
@@ -9690,8 +9690,13 @@ static int i40e_config_netdev(struct i40e_vsi *vsi)
                i40e_add_mac_filter(vsi, mac_addr);
                spin_unlock_bh(&vsi->mac_filter_hash_lock);
        } else {
-               /* relate the VSI_VMDQ name to the VSI_MAIN name */
-               snprintf(netdev->name, IFNAMSIZ, "%sv%%d",
+               /* Relate the VSI_VMDQ name to the VSI_MAIN name. Note that we
+                * are still limited by IFNAMSIZ, but we're adding 'v%d\0' to
+                * the end, which is 4 bytes long, so force truncation of the
+                * original name by IFNAMSIZ - 4
+                */
+               snprintf(netdev->name, IFNAMSIZ, "%.*sv%%d",
+                        IFNAMSIZ - 4,
                         pf->vsi[pf->lan_vsi]->netdev->name);
                random_ether_addr(mac_addr);