net/bnxt: fix undefined shift in vers_get

Message ID 20211102212744.295345-1-stephen@networkplumber.org (mailing list archive)
State Accepted, archived
Delegated to: Ajit Khaparde
Headers
Series net/bnxt: fix undefined shift in vers_get |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/github-robot: build success github build: passed
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing fail Testing issues

Commit Message

Stephen Hemminger Nov. 2, 2021, 9:27 p.m. UTC
  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")
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/bnxt/bnxt_hwrm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

Somnath Kotur Nov. 3, 2021, 2:18 a.m. UTC | #1
On Wed, 3 Nov 2021, 02:57 Stephen Hemminger, <stephen@networkplumber.org>
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")
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  drivers/net/bnxt/bnxt_hwrm.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
> index 82e89b7c8af7..f3d46bafd265 100644
> --- a/drivers/net/bnxt/bnxt_hwrm.c
> +++ b/drivers/net/bnxt/bnxt_hwrm.c
> @@ -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);
> --
> 2.30.2
>
Acked-by: Somnath Kotur <somnath.kotur@broadcom.com>

>
>
  
Ajit Khaparde Nov. 3, 2021, 4:13 a.m. UTC | #2
On Tue, Nov 2, 2021 at 7:18 PM Somnath Kotur <somnath.kotur@broadcom.com> wrote:
>
>
>
> On Wed, 3 Nov 2021, 02:57 Stephen Hemminger, <stephen@networkplumber.org> 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")
>> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
>> ---
>>  drivers/net/bnxt/bnxt_hwrm.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
>> index 82e89b7c8af7..f3d46bafd265 100644
>> --- a/drivers/net/bnxt/bnxt_hwrm.c
>> +++ b/drivers/net/bnxt/bnxt_hwrm.c
>> @@ -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);
>> --
>> 2.30.2
>
> Acked-by: Somnath Kotur <somnath.kotur@broadcom.com>
Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com>

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

>>
>>
  
Ajit Khaparde Nov. 3, 2021, 4:14 a.m. UTC | #3
On Tue, Nov 2, 2021 at 9:13 PM Ajit Khaparde <ajit.khaparde@broadcom.com> wrote:
>
> On Tue, Nov 2, 2021 at 7:18 PM Somnath Kotur <somnath.kotur@broadcom.com> wrote:
> >
> >
> >
> > On Wed, 3 Nov 2021, 02:57 Stephen Hemminger, <stephen@networkplumber.org> 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")
> >> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> >> ---
> >>  drivers/net/bnxt/bnxt_hwrm.c | 6 +++---
> >>  1 file changed, 3 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
> >> index 82e89b7c8af7..f3d46bafd265 100644
> >> --- a/drivers/net/bnxt/bnxt_hwrm.c
> >> +++ b/drivers/net/bnxt/bnxt_hwrm.c
> >> @@ -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);
> >> --
> >> 2.30.2
> >
> > Acked-by: Somnath Kotur <somnath.kotur@broadcom.com>
> Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
>
> 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

>
> >>
> >>
  

Patch

diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
index 82e89b7c8af7..f3d46bafd265 100644
--- a/drivers/net/bnxt/bnxt_hwrm.c
+++ b/drivers/net/bnxt/bnxt_hwrm.c
@@ -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);