]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
Fixes for 5.15
authorSasha Levin <sashal@kernel.org>
Sat, 25 Mar 2023 00:41:55 +0000 (20:41 -0400)
committerSasha Levin <sashal@kernel.org>
Sat, 25 Mar 2023 00:41:55 +0000 (20:41 -0400)
Signed-off-by: Sasha Levin <sashal@kernel.org>
queue-5.15/net-tls-fix-possible-race-condition-between-do_tls_g.patch [new file with mode: 0644]
queue-5.15/series

diff --git a/queue-5.15/net-tls-fix-possible-race-condition-between-do_tls_g.patch b/queue-5.15/net-tls-fix-possible-race-condition-between-do_tls_g.patch
new file mode 100644 (file)
index 0000000..4751729
--- /dev/null
@@ -0,0 +1,81 @@
+From 634a61fd4d1b186f84437b09ddc46a51ebb6fb2b Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Thu, 23 Mar 2023 00:54:40 +0000
+Subject: net: tls: fix possible race condition between
+ do_tls_getsockopt_conf() and do_tls_setsockopt_conf()
+
+From: Hangyu Hua <hbh25y@gmail.com>
+
+commit 49c47cc21b5b7a3d8deb18fc57b0aa2ab1286962 upstream.
+
+ctx->crypto_send.info is not protected by lock_sock in
+do_tls_getsockopt_conf(). A race condition between do_tls_getsockopt_conf()
+and error paths of do_tls_setsockopt_conf() may lead to a use-after-free
+or null-deref.
+
+More discussion:  https://lore.kernel.org/all/Y/ht6gQL+u6fj3dG@hog/
+
+Fixes: 3c4d7559159b ("tls: kernel TLS support")
+Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
+Link: https://lore.kernel.org/r/20230228023344.9623-1-hbh25y@gmail.com
+Signed-off-by: Jakub Kicinski <kuba@kernel.org>
+Signed-off-by: Meena Shanmugam <meenashanmugam@google.com>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ net/tls/tls_main.c | 9 +++++----
+ 1 file changed, 5 insertions(+), 4 deletions(-)
+
+diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c
+index a947cfb100bda..abd0c4557cb93 100644
+--- a/net/tls/tls_main.c
++++ b/net/tls/tls_main.c
+@@ -386,13 +386,11 @@ static int do_tls_getsockopt_conf(struct sock *sk, char __user *optval,
+                       rc = -EINVAL;
+                       goto out;
+               }
+-              lock_sock(sk);
+               memcpy(crypto_info_aes_gcm_128->iv,
+                      cctx->iv + TLS_CIPHER_AES_GCM_128_SALT_SIZE,
+                      TLS_CIPHER_AES_GCM_128_IV_SIZE);
+               memcpy(crypto_info_aes_gcm_128->rec_seq, cctx->rec_seq,
+                      TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE);
+-              release_sock(sk);
+               if (copy_to_user(optval,
+                                crypto_info_aes_gcm_128,
+                                sizeof(*crypto_info_aes_gcm_128)))
+@@ -410,13 +408,11 @@ static int do_tls_getsockopt_conf(struct sock *sk, char __user *optval,
+                       rc = -EINVAL;
+                       goto out;
+               }
+-              lock_sock(sk);
+               memcpy(crypto_info_aes_gcm_256->iv,
+                      cctx->iv + TLS_CIPHER_AES_GCM_256_SALT_SIZE,
+                      TLS_CIPHER_AES_GCM_256_IV_SIZE);
+               memcpy(crypto_info_aes_gcm_256->rec_seq, cctx->rec_seq,
+                      TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE);
+-              release_sock(sk);
+               if (copy_to_user(optval,
+                                crypto_info_aes_gcm_256,
+                                sizeof(*crypto_info_aes_gcm_256)))
+@@ -436,6 +432,8 @@ static int do_tls_getsockopt(struct sock *sk, int optname,
+ {
+       int rc = 0;
++      lock_sock(sk);
++
+       switch (optname) {
+       case TLS_TX:
+       case TLS_RX:
+@@ -446,6 +444,9 @@ static int do_tls_getsockopt(struct sock *sk, int optname,
+               rc = -ENOPROTOOPT;
+               break;
+       }
++
++      release_sock(sk);
++
+       return rc;
+ }
+-- 
+2.39.2
+
index beeeaa881333b32c20d564645efcbf73ce907b93..e5a1d6d13f2c3defa32344b32abc228736a76161 100644 (file)
@@ -12,3 +12,4 @@ interconnect-qcom-msm8974-fix-registration-race.patch
 kthread-add-the-helper-function-kthread_run_on_cpu.patch
 trace-hwlat-make-use-of-the-helper-function-kthread_.patch
 trace-hwlat-do-not-start-per-cpu-thread-if-it-is-alr.patch
+net-tls-fix-possible-race-condition-between-do_tls_g.patch