[PATCH] net/tls: Fix possible UAF in tls_set_device_offload

From: Lu Jialin
Date: Thu Nov 17 2022 - 05:45:00 EST


In tls_set_device_offload(), the error path "goto release_lock" will
not remove start_marker_record->list from offload_ctx->records_list,
but start_marker_record will be freed, then list traversal may cause UAF.

This fixes the following smatch warning:

net/tls/tls_device.c:1241 tls_set_device_offload() warn: '&start_marker_record->list' not removed from list

Fixes: e8f69799810c ("net/tls: Add generic NIC offload infrastructure")
Signed-off-by: Lu Jialin <lujialin4@xxxxxxxxxx>
---
net/tls/tls_device.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c
index a03d66046ca3..2def20870c58 100644
--- a/net/tls/tls_device.c
+++ b/net/tls/tls_device.c
@@ -1234,6 +1234,7 @@ int tls_set_device_offload(struct sock *sk, struct tls_context *ctx)
up_read(&device_offload_lock);
clean_acked_data_disable(inet_csk(sk));
crypto_free_aead(offload_ctx->aead_send);
+ list_del(&start_marker_record->list);
free_offload_ctx:
kfree(offload_ctx);
ctx->priv_ctx_tx = NULL;
--
2.17.1