Skip to contentSkip to conversation

net/bnxt: fix undefined shift in vers_get

PATCH In review Stephen Hemminger 3 participants 4 messages Nov 2, 2021 – Nov 3, 2021 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/bnxt: fix undefined shift in vers_get

UBSan testing revealed undefined shift here.

The firmware returns the version in bytes; and shifting a 8 bit quantity here can lead to undefined behaviour or truncation. The fix is to promote the bytes to 32 bit before shifting.

Bugzilla ID: 838

Fixes 9a891c1764ea ("net/bnxt: update HWRM to version 1.9.2")
---
 drivers/net/bnxt/bnxt_hwrm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/bnxt/bnxt_hwrm.c +3 -3
index 82e89b7c8af7..f3d46bafd265 100644
@@ -1260,9 +1260,9 @@ int bnxt_hwrm_ver_get(struct bnxt *bp, uint32_t timeout)
 		resp->hwrm_intf_upd_8b, resp->hwrm_fw_maj_8b,
 		resp->hwrm_fw_min_8b, resp->hwrm_fw_bld_8b,
 		resp->hwrm_fw_rsvd_8b);
-	bp->fw_ver = (resp->hwrm_fw_maj_8b << 24) |
-		     (resp->hwrm_fw_min_8b << 16) |
-		     (resp->hwrm_fw_bld_8b << 8) |
+	bp->fw_ver = ((uint32_t)resp->hwrm_fw_maj_8b << 24) |
+		     ((uint32_t)resp->hwrm_fw_min_8b << 16) |
+		     ((uint32_t)resp->hwrm_fw_bld_8b << 8) |
 		     resp->hwrm_fw_rsvd_8b;
 	PMD_DRV_LOG(INFO, "Driver HWRM version: %d.%d.%d\n",
 		HWRM_VERSION_MAJOR, HWRM_VERSION_MINOR, HWRM_VERSION_UPDATE);
Signature · 1 line
2.30.2
Acked-by on v1 1/1
#1 lore raw
Quoted 30 lines · On Wed, 3 Nov 2021, 02:57 Stephen Hemminger, <[email protected]> wrote:

UBSan testing revealed undefined shift here.

The firmware returns the version in bytes; and shifting a 8 bit quantity here can lead to undefined behaviour or truncation. The fix is to promote the bytes to 32 bit before shifting.

Bugzilla ID: 838

Fixes 9a891c1764ea ("net/bnxt: update HWRM to version 1.9.2")
---
 drivers/net/bnxt/bnxt_hwrm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/bnxt/bnxt_hwrm.c +3 -3
index 82e89b7c8af7..f3d46bafd265 100644
@@ -1260,9 +1260,9 @@ int bnxt_hwrm_ver_get(struct bnxt *bp, uint32_t
 timeout)
                resp->hwrm_intf_upd_8b, resp->hwrm_fw_maj_8b,
                resp->hwrm_fw_min_8b, resp->hwrm_fw_bld_8b,
                resp->hwrm_fw_rsvd_8b);
-       bp->fw_ver = (resp->hwrm_fw_maj_8b << 24) |
-                    (resp->hwrm_fw_min_8b << 16) |
-                    (resp->hwrm_fw_bld_8b << 8) |
+       bp->fw_ver = ((uint32_t)resp->hwrm_fw_maj_8b << 24) |
+                    ((uint32_t)resp->hwrm_fw_min_8b << 16) |
+                    ((uint32_t)resp->hwrm_fw_bld_8b << 8) |
                     resp->hwrm_fw_rsvd_8b;
        PMD_DRV_LOG(INFO, "Driver HWRM version: %d.%d.%d\n",
Quoted 5 lines

HWRM_VERSION_MAJOR, HWRM_VERSION_MINOR,
HWRM_VERSION_UPDATE);
--
2.30.2

Quoted 2 lines
Acked-by
#2 lore raw
Quoted 31 lines · Somnath Kotur
Quoted 27 lines · On Wed, 3 Nov 2021, 02:57 Stephen Hemminger, <[email protected]> wrote:

UBSan testing revealed undefined shift here.

The firmware returns the version in bytes; and shifting a 8 bit quantity here can lead to undefined behaviour or truncation. The fix is to promote the bytes to 32 bit before shifting.

Bugzilla ID: 838

Fixes 9a891c1764ea ("net/bnxt: update HWRM to version 1.9.2")
---
 drivers/net/bnxt/bnxt_hwrm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/bnxt/bnxt_hwrm.c +2 -3
index 82e89b7c8af7..f3d46bafd265 100644
@@ -1260,9 +1260,9 @@ int bnxt_hwrm_ver_get(struct bnxt *bp, uint32_t timeout)
                resp->hwrm_intf_upd_8b, resp->hwrm_fw_maj_8b,
                resp->hwrm_fw_min_8b, resp->hwrm_fw_bld_8b,
                resp->hwrm_fw_rsvd_8b);
-       bp->fw_ver = (resp->hwrm_fw_maj_8b << 24) |
-                    (resp->hwrm_fw_min_8b << 16) |
-                    (resp->hwrm_fw_bld_8b << 8) |
+       bp->fw_ver = ((uint32_t)resp->hwrm_fw_maj_8b << 24) |
+                    ((uint32_t)resp->hwrm_fw_min_8b << 16) |
Quoted 8 lines
Quoted 6 lines
drivers/net/bnxt/bnxt_hwrm.c +1 -1
+                    ((uint32_t)resp->hwrm_fw_bld_8b << 8) |
                     resp->hwrm_fw_rsvd_8b;
        PMD_DRV_LOG(INFO, "Driver HWRM version: %d.%d.%d\n",
                HWRM_VERSION_MAJOR, HWRM_VERSION_MINOR, HWRM_VERSION_UPDATE);
--

2.30.2

Patch applied to dpdk-next-net-brcm. Thanks

Quoted 2 lines
Quoted 2 lines
#3 lore raw
Quoted 41 lines · Ajit Khaparde
Quoted 31 lines · Somnath Kotur
Quoted 27 lines · On Wed, 3 Nov 2021, 02:57 Stephen Hemminger, <[email protected]> wrote:

UBSan testing revealed undefined shift here.

The firmware returns the version in bytes; and shifting a 8 bit quantity here can lead to undefined behaviour or truncation. The fix is to promote the bytes to 32 bit before shifting.

Bugzilla ID: 838

Fixes 9a891c1764ea ("net/bnxt: update HWRM to version 1.9.2")
---
 drivers/net/bnxt/bnxt_hwrm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/bnxt/bnxt_hwrm.c +2 -3
index 82e89b7c8af7..f3d46bafd265 100644
@@ -1260,9 +1260,9 @@ int bnxt_hwrm_ver_get(struct bnxt *bp, uint32_t timeout)
                resp->hwrm_intf_upd_8b, resp->hwrm_fw_maj_8b,
                resp->hwrm_fw_min_8b, resp->hwrm_fw_bld_8b,
                resp->hwrm_fw_rsvd_8b);
-       bp->fw_ver = (resp->hwrm_fw_maj_8b << 24) |
-                    (resp->hwrm_fw_min_8b << 16) |
-                    (resp->hwrm_fw_bld_8b << 8) |
+       bp->fw_ver = ((uint32_t)resp->hwrm_fw_maj_8b << 24) |
+                    ((uint32_t)resp->hwrm_fw_min_8b << 16) |
Quoted 8 lines
Quoted 6 lines
drivers/net/bnxt/bnxt_hwrm.c +1 -1
+                    ((uint32_t)resp->hwrm_fw_bld_8b << 8) |
                     resp->hwrm_fw_rsvd_8b;
        PMD_DRV_LOG(INFO, "Driver HWRM version: %d.%d.%d\n",
                HWRM_VERSION_MAJOR, HWRM_VERSION_MINOR, HWRM_VERSION_UPDATE);
--

2.30.2

Quoted 3 lines

Patch applied to dpdk-next-net-brcm. Thanks

FYI -
During commit, I updated the commit headline a bit - net/bnxt: fix undefined shift in ver get

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines