public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] chcr_ktls: add a defensive NULL check to prevent a possible null-pointer dereference in chcr_ktls_dev_del()
@ 2026-01-06 12:33 Tuo Li
  2026-01-09  1:53 ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: Tuo Li @ 2026-01-06 12:33 UTC (permalink / raw)
  To: ayush.sawal, andrew+netdev, davem, edumazet, kuba, pabeni,
	kernelxing
  Cc: netdev, linux-kernel, Tuo Li

In this function, u_ctx is guarded by an if statement, which indicates that
it may be NULL:

  u_ctx = tx_info->adap->uld[CXGB4_ULD_KTLS].handle;
  if (u_ctx && u_ctx->detach)
    return;

Consequently, a potential null-pointer dereference may occur when
tx_info->tid != -1, as shown below:

  if (tx_info->tid != -1) {
    ...
    xa_erase(&u_ctx->tid_list, tx_info->tid);
  }

Therefore, add a defensive NULL check to prevent this issue.

Fixes: 65e302a9bd57 ("cxgb4/ch_ktls: Clear resources when pf4 device is removed")
Signed-off-by: Tuo Li <islituo@gmail.com>
---
 drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c b/drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c
index 4e2096e49684..79292314a012 100644
--- a/drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c
+++ b/drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c
@@ -389,7 +389,8 @@ static void chcr_ktls_dev_del(struct net_device *netdev,
 		cxgb4_remove_tid(&tx_info->adap->tids, tx_info->tx_chan,
 				 tx_info->tid, tx_info->ip_family);
 
-		xa_erase(&u_ctx->tid_list, tx_info->tid);
+		if (u_ctx)
+			xa_erase(&u_ctx->tid_list, tx_info->tid);
 	}
 
 	port_stats = &tx_info->adap->ch_ktls_stats.ktls_port[tx_info->port_id];
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-01-11 17:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-06 12:33 [PATCH] chcr_ktls: add a defensive NULL check to prevent a possible null-pointer dereference in chcr_ktls_dev_del() Tuo Li
2026-01-09  1:53 ` Jakub Kicinski
2026-01-11 17:25   ` Tuo Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox