diff mbox series

[net-next] bnx2x: Set ivi->vlan field as an integer

Message ID 20240815-bnx2x-int-vlan-v1-1-5940b76e37ad@kernel.org (mailing list archive)
State Accepted
Commit a99ef548bba01435f19137cf1670861be1c1ee4b
Delegated to: Netdev Maintainers
Headers show
Series [net-next] bnx2x: Set ivi->vlan field as an integer | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 30 this patch: 29
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 31 this patch: 29
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 30 this patch: 29
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 12 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-08-16--21-00 (tests: 710)

Commit Message

Simon Horman Aug. 15, 2024, 3:27 p.m. UTC
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>
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Brett Creeley Aug. 15, 2024, 5:55 p.m. UTC | #1
On 8/15/2024 8:27 AM, Simon Horman wrote:
> Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
> 
> 
> 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>
> ---
>   drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c
> index 77d4cb4ad782..12198fc3ab22 100644
> --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c
> +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c
> @@ -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;

Makes sense to me.

Reviewed-by: Brett Creeley <brett.creeley@amd.com>

> 
>                  mutex_unlock(&bp->vfdb->bulletin_mutex);
>          }
> 
>
patchwork-bot+netdevbpf@kernel.org Aug. 17, 2024, 2:50 a.m. UTC | #2
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 15 Aug 2024 16:27:46 +0100 you wrote:
> 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.
> 
> [...]

Here is the summary with links:
  - [net-next] bnx2x: Set ivi->vlan field as an integer
    https://git.kernel.org/netdev/net-next/c/a99ef548bba0

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c
index 77d4cb4ad782..12198fc3ab22 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c
@@ -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);
 	}