netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: tls: fix possible race condition between do_tls_getsockopt_conf() and do_tls_setsockopt_conf()
@ 2023-02-24 10:58 Hangyu Hua
  2023-02-24 12:06 ` Florian Westphal
  0 siblings, 1 reply; 10+ messages in thread
From: Hangyu Hua @ 2023-02-24 10:58 UTC (permalink / raw)
  To: borisp, john.fastabend, kuba, davem, edumazet, pabeni,
	davejwatson, aviadye, ilyal, sd
  Cc: netdev, linux-kernel, Hangyu Hua

ctx->crypto_send.info is not protected by lock_sock in
do_tls_getsockopt_conf(). A race condition between do_tls_getsockopt_conf()
and do_tls_setsockopt_conf() can cause a NULL point dereference or
use-after-free read when memcpy.

Fixes: 3c4d7559159b ("tls: kernel TLS support")
Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
---
 net/tls/tls_main.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c
index 3735cb00905d..4956f5149b8e 100644
--- a/net/tls/tls_main.c
+++ b/net/tls/tls_main.c
@@ -374,6 +374,7 @@ static int do_tls_getsockopt_conf(struct sock *sk, char __user *optval,
 	}
 
 	/* get user crypto info */
+	lock_sock(sk);
 	if (tx) {
 		crypto_info = &ctx->crypto_send.info;
 		cctx = &ctx->tx;
@@ -381,6 +382,7 @@ static int do_tls_getsockopt_conf(struct sock *sk, char __user *optval,
 		crypto_info = &ctx->crypto_recv.info;
 		cctx = &ctx->rx;
 	}
+	release_sock(sk);
 
 	if (!TLS_CRYPTO_INFO_READY(crypto_info)) {
 		rc = -EBUSY;
-- 
2.34.1


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

end of thread, other threads:[~2023-02-28  1:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-24 10:58 [PATCH] net: tls: fix possible race condition between do_tls_getsockopt_conf() and do_tls_setsockopt_conf() Hangyu Hua
2023-02-24 12:06 ` Florian Westphal
2023-02-24 18:55   ` Jakub Kicinski
2023-02-24 20:22     ` Sabrina Dubroca
2023-02-24 21:06       ` Jakub Kicinski
2023-02-24 21:48         ` Sabrina Dubroca
2023-02-24 22:17           ` Jakub Kicinski
2023-02-27  3:26             ` Hangyu Hua
2023-02-27 19:07               ` Jakub Kicinski
2023-02-28  1:48                 ` Hangyu Hua

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).