net/bnxt: fix firmware version query
authorStephen Hemminger <stephen@networkplumber.org>
Tue, 2 Nov 2021 21:27:44 +0000 (14:27 -0700)
committerAjit Khaparde <ajit.khaparde@broadcom.com>
Wed, 3 Nov 2021 04:12:29 +0000 (05:12 +0100)
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")
Cc: stable@dpdk.org
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Somnath Kotur <somnath.kotur@broadcom.com>
Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
drivers/net/bnxt/bnxt_hwrm.c

index 55dcb1d..3fefd55 100644 (file)
@@ -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);