]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bnx2x: Set ivi->vlan field as an integer
authorSimon Horman <horms@kernel.org>
Thu, 15 Aug 2024 15:27:46 +0000 (16:27 +0100)
committerJakub Kicinski <kuba@kernel.org>
Sat, 17 Aug 2024 01:02:28 +0000 (18:02 -0700)
In bnx2x_get_vf_config():
* The vlan field of ivi is a 32-bit integer, it is used to store a vlan ID.
* The vlan field of bulletin is a 16-bit integer, it is also used to store
  a vlan ID.

In the current code, ivi->vlan is set using memset. But in the case of
setting it to the value of bulletin->vlan, this involves reading
32 bits from a 16bit source. This is likely safe, as the following
6 bytes are padding in the same structure, but none the less, it seems
undesirable.

However, it is entirely unclear to me how this scheme works on
big-endian systems.

Resolve this by simply assigning integer values to ivi->vlan.

Flagged by W=1 builds.
f.e. gcc-14 reports:

In function 'fortify_memcpy_chk',
    inlined from 'bnx2x_get_vf_config' at .../bnx2x_sriov.c:2655:4:
.../fortify-string.h:580:25: warning: call to '__read_overflow2_field' declared with attribute warning: detected read beyond size of field (2nd parameter); maybe use struct_group()? [-Wattribute-warning]
  580 |                         __read_overflow2_field(q_size_field, size);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Compile tested only.

Signed-off-by: Simon Horman <horms@kernel.org>
Reviewed-by: Brett Creeley <brett.creeley@amd.com>
Link: https://patch.msgid.link/20240815-bnx2x-int-vlan-v1-1-5940b76e37ad@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c

index 77d4cb4ad78236c2c447888cf9cbb7612fbcf208..12198fc3ab22be16907f858e9411eb567e10f8fd 100644 (file)
@@ -2652,10 +2652,10 @@ int bnx2x_get_vf_config(struct net_device *dev, int vfidx,
                /* vlan */
                if (bulletin->valid_bitmap & (1 << VLAN_VALID))
                        /* vlan configured by ndo so its in bulletin board */
-                       memcpy(&ivi->vlan, &bulletin->vlan, VLAN_HLEN);
+                       ivi->vlan = bulletin->vlan;
                else
                        /* function has not been loaded yet. Show vlans as 0s */
-                       memset(&ivi->vlan, 0, VLAN_HLEN);
+                       ivi->vlan = 0;
 
                mutex_unlock(&bp->vfdb->bulletin_mutex);
        }