[PATCH] net: bnxt: validate HWRM response length
From: Noah Weinberger
Date: Sun Nov 08 2026 - 18:54:07 EST
Hello,
Both HWRM completion paths compute the address of the valid bit
from the firmware-provided response length without bounding it to the
response area:
len = le16_to_cpu(READ_ONCE(ctx->resp->resp_len));
valid = ((u8 *)ctx->resp) + len - 1;
...
if (*valid) /* poll */
...
*valid = 0; /* zero for compatibility */
The response area is the last PAGE_SIZE of the 2*PAGE_SIZE DMA
allocation (BNXT_HWRM_RESP_RESERVED). Firmware that reports a
resp_len above PAGE_SIZE (the field is u16, so up to 65535) makes the
poll read and the *valid = 0 write land up to ~61 KB past the
allocation, on every command. Lengths below the response header size
are also accepted today.
The patch rejects both cases before the pointer arithmetic, on the
interrupt path and the polling path.
Affected version/commit: mainline 8a65162514fbad21a2c58ffed65f42b27e92b163 (v7.4-rc2 window, 2026-11-08), drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c:589-590 and :609 and :648-649 (len = le16_to_cpu(ctx->resp->resp_len); valid = ((u8 *)ctx->resp) + len - 1), :650-662 (poll loop reads *valid), :672-676 (*valid = 0), bnxt_hwrm.h:68-73 (response area = last PAGE_SIZE of a 2*PAGE_SIZE DMA allocation, BNXT_HWRM_RESP_RESERVED = PAGE_SIZE)
Longstanding pattern; the context-based HWRM rework kept it.
This was found during an assisted (AI-supported) static source review of
mainline 8a65162514fbad21a2c58ffed65f42b27e92b163 (v7.4-rc2 window, 2026-11-08). The patch below has NOT been compiled and has
NOT been runtime tested, and no reproducer was produced - the triggering
conditions are described above instead. Please treat this as a report for
verification rather than a battle-tested fix.
---
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c
index 5bfabdca7d..3425c180d1 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c
@@ -587,6 +587,10 @@ static int __hwrm_send(struct bnxt *bp, struct bnxt_hwrm_ctx *ctx)
goto exit;
}
len = le16_to_cpu(READ_ONCE(ctx->resp->resp_len));
+ if (len < sizeof(*ctx->resp) || len > BNXT_HWRM_RESP_RESERVED) {
+ hwrm_err(bp, ctx, "Invalid resp len: %u\n", len);
+ goto exit;
+ }
valid = ((u8 *)ctx->resp) + len - 1;
} else {
__le16 seen_out_of_seq = ctx->req->seq_id; /* will never see */
@@ -646,6 +650,10 @@ static int __hwrm_send(struct bnxt *bp, struct bnxt_hwrm_ctx *ctx)
}
/* Last byte of resp contains valid bit */
+ if (len < sizeof(*ctx->resp) || len > BNXT_HWRM_RESP_RESERVED) {
+ hwrm_err(bp, ctx, "Invalid resp len: %u\n", len);
+ goto exit;
+ }
valid = ((u8 *)ctx->resp) + len - 1;
for (j = 0; j < HWRM_VALID_BIT_DELAY_USEC; ) {
/* make sure we read from updated DMA memory */