From: Hangyu Hua <hbh25y@gmail.com>
To: borisp@nvidia.com, john.fastabend@gmail.com, kuba@kernel.org,
davem@davemloft.net, edumazet@google.com, pabeni@redhat.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Hangyu Hua <hbh25y@gmail.com>
Subject: [PATCH] net: tls: Fix possible NULL-pointer dereference in tls_decrypt_device() and tls_decrypt_sw()
Date: Mon, 23 Oct 2023 16:06:11 +0800 [thread overview]
Message-ID: <20231023080611.19244-1-hbh25y@gmail.com> (raw)
tls_rx_one_record can be called in tls_sw_splice_read and tls_sw_read_sock
with msg being NULL. This may lead to null pointer dereferences in
tls_decrypt_device and tls_decrypt_sw.
Fix this by adding a check.
Fixes: dd47ed3620e6 ("tls: rx: factor SW handling out of tls_rx_one_record()")
Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
---
net/tls/tls_sw.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index e9d1e83a859d..411bf148f707 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -1612,7 +1612,11 @@ tls_decrypt_sw(struct sock *sk, struct tls_context *tls_ctx,
struct strp_msg *rxm;
int pad, err;
- err = tls_decrypt_sg(sk, &msg->msg_iter, NULL, darg);
+ if (msg == NULL)
+ err = tls_decrypt_sg(sk, NULL, NULL, darg);
+ else
+ err = tls_decrypt_sg(sk, &msg->msg_iter, NULL, darg);
+
if (err < 0) {
if (err == -EBADMSG)
TLS_INC_STATS(sock_net(sk), LINUX_MIB_TLSDECRYPTERROR);
@@ -1686,7 +1690,8 @@ tls_decrypt_device(struct sock *sk, struct msghdr *msg,
off = rxm->offset + prot->prepend_size;
len = rxm->full_len - prot->overhead_size;
- err = skb_copy_datagram_msg(darg->skb, off, msg, len);
+ if (msg != NULL)
+ err = skb_copy_datagram_msg(darg->skb, off, msg, len);
if (err)
return err;
}
--
2.34.1
next reply other threads:[~2023-10-23 8:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-23 8:06 Hangyu Hua [this message]
2023-10-23 14:03 ` [PATCH] net: tls: Fix possible NULL-pointer dereference in tls_decrypt_device() and tls_decrypt_sw() Sabrina Dubroca
2023-10-24 2:17 ` Hangyu Hua
2023-10-25 10:27 ` Sabrina Dubroca
2023-10-25 14:14 ` Jakub Kicinski
2023-10-25 21:20 ` Sabrina Dubroca
2023-10-25 21:30 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231023080611.19244-1-hbh25y@gmail.com \
--to=hbh25y@gmail.com \
--cc=borisp@nvidia.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).