iavf: fully support off-by-one driver behavior 90/41490/14
authorVratko Polak <[email protected]>
Tue, 3 Sep 2024 14:37:49 +0000 (16:37 +0200)
committerVratko Polak <[email protected]>
Tue, 3 Sep 2024 14:37:49 +0000 (16:37 +0200)
Previously, iavf_port_add_del_eth_addr was not using large enough buffer
and address sanitizer does not allow that.

Type: fix

Change-Id: Icd1491fb5651aed20685d15224e9c725347ef369
Signed-off-by: Vratko Polak <[email protected]>
src/plugins/dev_iavf/port.c
src/plugins/dev_iavf/virtchnl_funcs.h

index 7e4200a..f1578fc 100644 (file)
@@ -91,7 +91,7 @@ iavf_port_init_rss (vlib_main_t *vm, vnet_dev_port_t *port)
     .key_len = keylen,
   };
 
-  clib_memcpy (key->key, default_rss_key, sizeof (default_rss_key));
+  clib_memcpy (key->key, default_rss_key, keylen);
 
   return iavf_vc_op_config_rss_key (vm, dev, key);
 }
@@ -425,17 +425,20 @@ iavf_port_add_del_eth_addr (vlib_main_t *vm, vnet_dev_port_t *port,
                            int is_primary)
 {
   iavf_port_t *ap = vnet_dev_get_port_data (port);
-  virtchnl_ether_addr_list_t al = {
+  u8 buffer[VIRTCHNL_MSG_SZ (virtchnl_ether_addr_list_t, list, 1)];
+  virtchnl_ether_addr_list_t *al = (virtchnl_ether_addr_list_t *) buffer;
+
+  *al = (virtchnl_ether_addr_list_t){
     .vsi_id = ap->vsi_id,
     .num_elements = 1,
     .list[0].primary = is_primary ? 1 : 0,
     .list[0].extra = is_primary ? 0 : 1,
   };
 
-  clib_memcpy (al.list[0].addr, addr, sizeof (al.list[0].addr));
+  clib_memcpy (al->list[0].addr, addr, sizeof (al->list[0].addr));
 
-  return is_add ? iavf_vc_op_add_eth_addr (vm, port->dev, &al) :
-                       iavf_vc_op_del_eth_addr (vm, port->dev, &al);
+  return is_add ? iavf_vc_op_add_eth_addr (vm, port->dev, al) :
+                 iavf_vc_op_del_eth_addr (vm, port->dev, al);
 }
 
 static vnet_dev_rv_t
index e7f3901..0d4ab28 100644 (file)
@@ -9,6 +9,10 @@
 #include <vnet/dev/dev.h>
 #include <dev_iavf/iavf.h>
 
+/* The "+ 1" fakes a trailing element, but the driver requires that.
+ * Using this "wrong" macro is the easiest solution, as long as
+ * port.c uses buffer sized by the same macro as the functions here.
+ */
 #define VIRTCHNL_MSG_SZ(s, e, n) STRUCT_OFFSET_OF (s, e[(n) + 1])
 
 typedef struct