Skip to contentSkip to conversation

net/bnxt: fix -Warray-bounds in blob bit-stream pull helpers

PATCH New Manish Kurup 1 participant 1 message Oct 5 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/bnxt: fix -Warray-bounds in blob bit-stream pull helpers

From: Joey Zhong <[email protected]>

GCC inlines ulp_bs_pull_lsb() and flags the remainder branch:
if (len)

      ulp_bs_get_lsb(src, offset, len, &dst[size - 1 - idx]);

After the full-byte loop exits, idx == cnt. When cnt == size with a non-zero bit remainder (e.g., len = 33 with size = 4), the subscript size - 1 - idx underflows to UINT32_MAX, producing a -Warray-bounds false positive (and a genuine out-of-bounds write if len/size are ever miscalculated upstream of the check that normally prevents this). ulp_blob_pull() rejects this state via its ULP_BYTE_2_BITS(data_size) < len check, but GCC cannot carry that constraint through the inlined call chain.

Changes:
- ulp_bs_pull_lsb / ulp_bs_pull_msb: add unlikely(cnt > size) entry guard and an explicit likely(idx < size) check on the remainder branch so GCC can prove all subscripts are in range.
- ulp_bs_pull_msb: add the missing uint32_t size parameter (matching ulp_bs_pull_lsb) and update its three call sites to pass the destination buffer size.
- ulp_bs_get_lsb / ulp_bs_get_msb: add unlikely(!bitlen) early exit to make the zero-length contract explicit.

Fixes f634204b7ad8 ("net/bnxt: support generic table processing")
---
 drivers/net/bnxt/tf_ulp/ulp_gen_tbl.c |  2 +-
 drivers/net/bnxt/tf_ulp/ulp_mapper.c  |  1 +
 drivers/net/bnxt/tf_ulp/ulp_utils.h   | 44 +++++++++++++++++++++++----
 3 files changed, 40 insertions(+), 7 deletions(-)
drivers/net/bnxt/tf_ulp/ulp_gen_tbl.c +1 -1
index ac0a7e6db1..535849b1f9 100644
@@ -309,7 +309,7 @@ ulp_mapper_gen_tbl_entry_data_get(struct ulp_mapper_gen_tbl_entry *entry,
 	if (entry->byte_order == BNXT_ULP_BYTE_ORDER_LE)
 		ulp_bs_pull_lsb(entry->byte_data, data, data_size, offset, len);
 	else
-		ulp_bs_pull_msb(entry->byte_data, data, offset, len);
+		ulp_bs_pull_msb(entry->byte_data, data, data_size, offset, len);
 
 	return 0;
 }
drivers/net/bnxt/tf_ulp/ulp_mapper.c +1 -0
index 960cdda311..168f05a5a4 100644
@@ -701,6 +701,7 @@ ulp_mapper_tbl_ident_scan_ext(struct bnxt_ulp_mapper_parms *parms,
 					idents[i].ident_bit_size);
 		else
 			ulp_bs_pull_msb(byte_data, (uint8_t *)&val64,
+					sizeof(val64),
 					idents[i].ident_bit_pos,
 					idents[i].ident_bit_size);
 
drivers/net/bnxt/tf_ulp/ulp_utils.h +38 -6

97 lines not on this page · raw message

Signature · 1 line
2.31.1