|WARNING| net/bnxt: fix out-of-bounds read in TCAM get
dpdklab at iol.unh.edu
dpdklab at iol.unh.edu
Mon Oct 5 18:47:19 CEST 2026
Test-Label: ai-code-review
Test-Status: WARNING
https://dpdk.org/patch/170566
_AI Code Review_
=== Patch Review: series.patch (via Claude) ===
Review date: 2026-10-05
# DPDK Patch Review: net/bnxt: fix out-of-bounds read in TCAM get
## Summary
This patch fixes a critical security vulnerability in the bnxt driver's TCAM get function. The fix addresses an out-of-bounds read caused by missing validation and a fall-through execution path after error detection.
---
## Errors
### 1. Missing byte-order conversion in initial assignments (lines 1174-1175 in original code)
**Original code:**
```c
*key_size = resp.key_size;
*remap_size = resp.result_size;
```
These lines read firmware response fields without converting from little-endian to host byte order. The patch correctly fixes this by using `rte_le_to_cpu_16()`, but the reviewers should verify that these values are used consistently throughout the caller's code path.
**Status:** Fixed in patch (lines 1174-1175 in patched version use `rte_le_to_cpu_16()`).
---
## Warnings
### 1. Error code handling inconsistency
The patch changes the error path pattern. Original code set `rc = -EINVAL` and fell through (which was the bug). The fix correctly returns immediately, but the final `return rc;` at line 1180 will now return `rc` from the `bnxt_hwrm_tf_message_direct()` call, which is zero (success path only reaches here).
The final `return rc;` should be `return 0;` for clarity, since `rc` is guaranteed to be zero at that point. However, this is functionally correct as-is.
**Recommendation:** Consider changing `return rc;` to `return 0;` at line 1180 for code clarity.
---
### 2. Log message format string argument type
At line 1163, the error log uses `%d` format specifier for `rc`:
```c
PMD_DRV_LOG_LINE(ERR, "%s: FW sizes exceed TCAM bounds, rc:%d",
__func__, rc);
```
This is acceptable since `rc` is `int`, but the format is slightly inconsistent with typical DPDK error logging which often uses `%s` with `strerror(-rc)`. The current format is still correct.
---
### 3. Integer overflow in bounds check (line 1160)
The bounds check:
```c
if ((size_t)rte_le_to_cpu_16(resp.key_size) * 2 +
(size_t)rte_le_to_cpu_16(resp.result_size) > sizeof(resp.dev_data))
```
While the cast to `size_t` is correct for the comparison, the multiplication `* 2` happens after the cast. If `resp.key_size` were maliciously set to a very large value (near UINT16_MAX), `(size_t)value * 2` could theoretically overflow on a 16-bit size_t platform (though DPDK doesn't support such platforms).
**More defensive approach:**
```c
if (rte_le_to_cpu_16(resp.key_size) > sizeof(resp.dev_data) / 2 ||
rte_le_to_cpu_16(resp.result_size) > sizeof(resp.dev_data) ||
(size_t)rte_le_to_cpu_16(resp.key_size) * 2 +
(size_t)rte_le_to_cpu_16(resp.result_size) > sizeof(resp.dev_data))
```
However, given that `resp.key_size` is `uint16_t` and `sizeof(resp.dev_data)` is likely much larger, this is more theoretical than practical. The current code is acceptable but could be more defensive.
---
### 4. Missing validation of negative sizes
`resp.key_size` and `resp.result_size` are `uint16_t`, so they cannot be negative. However, after conversion with `rte_le_to_cpu_16()`, they remain unsigned. The code should verify they are non-zero if zero-length keys/results are invalid for this hardware.
**Recommendation:** If zero-length keys or results are invalid, add:
```c
if (rte_le_to_cpu_16(resp.key_size) == 0 ||
rte_le_to_cpu_16(resp.result_size) == 0) {
rc = -EINVAL;
PMD_DRV_LOG_LINE(ERR, "%s: Invalid zero-length response", __func__);
return rc;
}
```
This depends on hardware requirements and may not be necessary.
---
## Info
### 1. Redundant `rc` variable assignment
At line 1161, the patch assigns `rc = -EINVAL;` before the log and return. While this makes the error code explicit, it's immediately returned and never read elsewhere in this error path. This is fine for consistency and clarity.
---
### 2. Code duplication in error messages
The two new error messages (lines 1162-1163 and 1168-1169) have similar format. Consider whether they should be consolidated or made more distinct to aid debugging.
---
### 3. Validation order
The patch validates firmware buffer bounds before caller buffer size. This is the correct order - checking firmware consistency first prevents relying on potentially corrupted size values in the second check.
---
## Correctness Verification
**Use-after-free:** None introduced
**Resource leaks:** None (no allocations in this function)
**Buffer overflow:** Fixed (was the primary bug)
**Error propagation:** Correct - all error paths return immediately
**Byte order conversion:** Fixed - all `resp.*` fields now converted
**Integer overflow:** Low risk given data types, acceptable as-is
---
## Style Compliance
**Coding style:** Patch follows DPDK style
**Line length:** All lines within acceptable limits
**Function format:** Proper indentation and spacing
**Error handling:** Explicit checks with immediate returns
---
## Documentation and Process
**Fixes tag:** Present and correct
**Cc: stable:** Present (appropriate for security fix)
**Release notes:** Not included in patch - should be added for this security fix
**Security advisory:** This is a potential security vulnerability (out-of-bounds read). Consider coordinating with security team for CVE assignment if not already done.
---
## Final Assessment
**Patch correctness:** The patch successfully fixes the reported vulnerability by:
1. Adding early return on `bnxt_hwrm_tf_message_direct()` failure
2. Validating firmware buffer bounds before copying
3. Validating caller buffer sizes before copying
4. Converting all firmware sizes to host byte order
5. Using validated sizes in memcpy operations
The patch is **functionally correct** and significantly improves security. The warnings above are minor suggestions for potential further hardening, not blockers.
**Recommendation: ACCEPT** with consideration for the minor improvements suggested in the Warnings section for future refinement.
More information about the test-report
mailing list