[5/6] net/bnxt: add integer underflow check

Message ID 20200303175938.14292-6-stephen@networkplumber.org (mailing list archive)
State Changes Requested, archived
Delegated to: Ajit Khaparde
Headers
Series net/bnxt: bounds checking patches |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Stephen Hemminger March 3, 2020, 5:59 p.m. UTC
  If a request to read a small value is passed to nvram reader
it would underflow.

Reported-by: Christopher Ertl <Christopher.Ertl@microsoft.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/bnxt/bnxt_hwrm.c | 3 +++
 1 file changed, 3 insertions(+)
  

Patch

diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
index 6beb215d604f..d878320aa110 100644
--- a/drivers/net/bnxt/bnxt_hwrm.c
+++ b/drivers/net/bnxt/bnxt_hwrm.c
@@ -3859,6 +3859,9 @@  int bnxt_get_nvram_directory(struct bnxt *bp, uint32_t len, uint8_t *data)
 
 	*data++ = dir_entries;
 	*data++ = entry_length;
+	if (len <= 2)
+		return -EINVAL;
+
 	len -= 2;
 	memset(data, 0xff, len);