net/bnxt: fix potential OOB string writes in debug helpers
Subsystems (2)
PATCH 1/1 net/bnxt: fix potential OOB string writes in debug helpers
From: Keegan Freyhof <[email protected]>
The debug-dump helpers in tfc_mpc_debug.c (em_show, mod_decode, enc_decode, stat_decode) and tfc_tcam_debug.c (prof_tcam_show, wc_tcam_show) build up formatted strings by appending into a fixed 256-byte buffer without checking remaining space, allowing an out-of-bounds write once the accumulated output exceeds the destination buffer.
Add tfc_str_append(), a bounds-checked snprintf() wrapper that clamps its return value to the space actually available so a chain of appended writes can never run past the end of the buffer, and use it in place of the unchecked buffer writes in both files. The two prof_tcam_show()/wc_tcam_show() dump routines had been converted from strcat() to snprintf() with raw return-value accumulation, which reintroduces the same out-of-bounds write on any segment that gets truncated; both now use tfc_str_append() as well, matching the already-correct pattern in the equivalent em_show() dump routine.
--- drivers/net/bnxt/tf_core/v3/tfc_debug.h | 1 + drivers/net/bnxt/tf_core/v3/tfc_mpc_debug.c | 167 ++++++++---- drivers/net/bnxt/tf_core/v3/tfc_tcam_debug.c | 258 ++++++++++--------- 3 files changed, 245 insertions(+), 181 deletions(-)
drivers/net/bnxt/tf_core/v3/tfc_debug.h +1 -0
@@ -18,6 +18,7 @@ int tfc_mpc_table_write_zero(struct tfc *tfcp,uint8_t words, uint8_t *data);const char *get_lrec_opcode_str (uint8_t opcode); +size_t tfc_str_append (char *buf,size_t size,const char *fmt, ...);void act_show (FILE *fd,struct act_info_t *act_info,uint32_t offset);int tfc_em_show (FILE *fd,struct tfc *tfcp,uint8_t tsid,enum cfa_dir dir);int tfc_wc_show (FILE *fd,struct tfc *tfcp,uint8_t tsid,enum cfa_dir dir);
drivers/net/bnxt/tf_core/v3/tfc_mpc_debug.c +114 -53
339 lines not on this page · raw message
drivers/net/bnxt/tf_core/v3/tfc_tcam_debug.c +130 -128
381 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v2 1/1 net/bnxt: remove unused TruFlow debug dump helpers
tfc_mpc_debug.c, tfc_tcam_debug.c and tfc_debug.h contain debug dump routines (tfc_em_show(), tfc_wc_show(), tfc_backing_store_dump(), the TCAM show/read helpers, and so on) that are built unconditionally but are not called from anywhere in the driver.
Remove them. The one function in these files that does have a caller, tfc_mpc_table_read(), is used by tfc_em_delete_entries_by_pool_id(), so move it to tfc_em.c unchanged, next to its user.
This also removes the unbounded strcat() use and the format-string handling in those helpers, which showed up as clang -Werror build failures.
---
v2: Replace the v1 "fix potential OOB string writes in debug helpers"
with removal of the unused debug dump helpers, per review feedback. No functional change: the only function with a caller, tfc_mpc_table_read(), is moved to tfc_em.c unchanged.
drivers/net/bnxt/tf_core/v3/meson.build | 2 - drivers/net/bnxt/tf_core/v3/tfc_debug.h | 34 - drivers/net/bnxt/tf_core/v3/tfc_em.c | 171 +- drivers/net/bnxt/tf_core/v3/tfc_mpc_debug.c | 1411 ------------- drivers/net/bnxt/tf_core/v3/tfc_tcam_debug.c | 1875 ------------------ 5 files changed, 169 insertions(+), 3324 deletions(-) delete mode 100644 drivers/net/bnxt/tf_core/v3/tfc_debug.h delete mode 100644 drivers/net/bnxt/tf_core/v3/tfc_mpc_debug.c delete mode 100644 drivers/net/bnxt/tf_core/v3/tfc_tcam_debug.c
drivers/net/bnxt/tf_core/v3/meson.build +0 -2
@@ -21,8 +21,6 @@ sources += files( 'tfc_idx_tbl.c', 'tfc_if_tbl.c', 'tfc_init.c', - 'tfc_mpc_debug.c', - 'tfc_tcam_debug.c', 'tfc_msg.c', 'tfc_priv.c', 'tfc_resources.c',
drivers/net/bnxt/tf_core/v3/tfc_debug.h deleted +0 -34
@@ -1,34 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright(c) 2019-2021 Broadcom -* All rights reserved. -*/ - -#ifndef _TFC_DEBUG_H_ -#define _TFC_DEBUG_H_ - -/* #define EM_DEBUG */ -/* #define WC_DEBUG */ -/* #define ACT_DEBUG */ - -int tfc_mpc_table_write_zero (struct tfc *tfcp, -uint8_t tsid, -enum cfa_dir dir, -uint32_t type, -uint32_t offset, -uint8_t words, -uint8_t *data); -const char *get_lrec_opcode_str (uint8_t opcode); -void act_show (FILE *fd,struct act_info_t *act_info,uint32_t offset); -int tfc_em_show (FILE *fd,struct tfc *tfcp,uint8_t tsid,enum cfa_dir dir); -int tfc_wc_show (FILE *fd,struct tfc *tfcp,uint8_t tsid,enum cfa_dir dir); -int tfc_mpc_table_invalidate (struct tfc *tfcp, -uint8_t tsid, -enum cfa_dir dir, -uint32_t type, -uint32_t offset, -uint32_t words); -void act_process (uint32_t act_rec_ptr, -struct act_info_t *act_info, -struct tfc_ts_mem_cfg *act_mem_cfg); -void tfc_backing_store_dump (FILE *fd); -#endif
drivers/net/bnxt/tf_core/v3/tfc_em.c +169 -2
183 lines not on this page · raw message
drivers/net/bnxt/tf_core/v3/tfc_mpc_debug.c deleted +0 -1411
1,411 lines not on this page · raw message
drivers/net/bnxt/tf_core/v3/tfc_tcam_debug.c deleted +0 -1875
1,364 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.31.1
Part of the diff is not shown here. View the raw message.