Skip to content

Commit d3e599c

Browse files
keesdavem330
authored andcommitted
bnxt: Do not read past the end of test names
Test names were being concatenated based on a offset beyond the end of the first name, which tripped the buffer overflow detection logic: detected buffer overflow in strnlen [...] Call Trace: bnxt_ethtool_init.cold+0x18/0x18 Refactor struct hwrm_selftest_qlist_output to use an actual array, and adjust the concatenation to use snprintf() rather than a series of strncat() calls. Reported-by: Niklas Cassel <[email protected]> Link: https://lore.kernel.org/lkml/Y8F%2F1w1AZTvLglFX@x1-carbon/ Tested-by: Niklas Cassel <[email protected]> Fixes: eb51365 ("bnxt_en: Add basic ethtool -t selftest support.") Cc: Michael Chan <[email protected]> Cc: "David S. Miller" <[email protected]> Cc: Eric Dumazet <[email protected]> Cc: Jakub Kicinski <[email protected]> Cc: Paolo Abeni <[email protected]> Cc: [email protected] Signed-off-by: Kees Cook <[email protected]> Reviewed-by: Michael Chan <[email protected]> Reviewed-by: Niklas Cassel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent fdfc76a commit d3e599c

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3969,7 +3969,7 @@ void bnxt_ethtool_init(struct bnxt *bp)
39693969
test_info->timeout = HWRM_CMD_TIMEOUT;
39703970
for (i = 0; i < bp->num_tests; i++) {
39713971
char *str = test_info->string[i];
3972-
char *fw_str = resp->test0_name + i * 32;
3972+
char *fw_str = resp->test_name[i];
39733973

39743974
if (i == BNXT_MACLPBK_TEST_IDX) {
39753975
strcpy(str, "Mac loopback test (offline)");
@@ -3980,14 +3980,9 @@ void bnxt_ethtool_init(struct bnxt *bp)
39803980
} else if (i == BNXT_IRQ_TEST_IDX) {
39813981
strcpy(str, "Interrupt_test (offline)");
39823982
} else {
3983-
strscpy(str, fw_str, ETH_GSTRING_LEN);
3984-
strncat(str, " test", ETH_GSTRING_LEN - strlen(str));
3985-
if (test_info->offline_mask & (1 << i))
3986-
strncat(str, " (offline)",
3987-
ETH_GSTRING_LEN - strlen(str));
3988-
else
3989-
strncat(str, " (online)",
3990-
ETH_GSTRING_LEN - strlen(str));
3983+
snprintf(str, ETH_GSTRING_LEN, "%s test (%s)",
3984+
fw_str, test_info->offline_mask & (1 << i) ?
3985+
"offline" : "online");
39913986
}
39923987
}
39933988

drivers/net/ethernet/broadcom/bnxt/bnxt_hsi.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10249,14 +10249,7 @@ struct hwrm_selftest_qlist_output {
1024910249
u8 unused_0;
1025010250
__le16 test_timeout;
1025110251
u8 unused_1[2];
10252-
char test0_name[32];
10253-
char test1_name[32];
10254-
char test2_name[32];
10255-
char test3_name[32];
10256-
char test4_name[32];
10257-
char test5_name[32];
10258-
char test6_name[32];
10259-
char test7_name[32];
10252+
char test_name[8][32];
1026010253
u8 eyescope_target_BER_support;
1026110254
#define SELFTEST_QLIST_RESP_EYESCOPE_TARGET_BER_SUPPORT_BER_1E8_SUPPORTED 0x0UL
1026210255
#define SELFTEST_QLIST_RESP_EYESCOPE_TARGET_BER_SUPPORT_BER_1E9_SUPPORTED 0x1UL

0 commit comments

Comments
 (0)