chcr_ktls: add a defensive NULL check to prevent a possible null-pointer dereference in chcr_ktls_dev_del()
Subsystems (3)
PATCH 1/1 chcr_ktls: add a defensive NULL check to prevent a possible null-pointer dereference in chcr_ktls_dev_del()
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.
--- drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +2 -1
@@ -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];
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerQuoted 10 lines · On Tue, 6 Jan 2026 20:33:02 +0800 Tuo Li wrote:
In this function,
u_ctxis 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:
Quoted 6 lines
if (tx_info->tid != -1) { ... xa_erase(&u_ctx->tid_list, tx_info->tid); }Therefore, add a defensive NULL check to prevent this issue.
There seems to be no locking here.
It'd take much more to make this code safe, sprinking random ifs here and there seem like a waste of time.
Signature · 1 line
pw-bot: reject
Hi Jakub
Quoted 17 lines · Jakub Kicinski
Quoted 15 lines · On Tue, 6 Jan 2026 20:33:02 +0800 Tuo Li wrote:
In this function,
u_ctxis 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); }
Quoted 5 lines
Quoted 1 line
Therefore, add a defensive NULL check to prevent this issue.
There seems to be no locking here.
It'd take much more to make this code safe, sprinking random ifs here and there seem like a waste of time.
Thanks for pointing this out.
Given the lack of proper locking here, I'd rather drop this patch than add ad-hoc NULL checks.
Thanks for the review,
Tuo