]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-6.6/tls-adjust-recv-return-with-async-crypto-and-failed-.patch
a02b76660b182e210b6ecd1830e9f160bd19f328
[thirdparty/kernel/stable-queue.git] / queue-6.6 / tls-adjust-recv-return-with-async-crypto-and-failed-.patch
1 From 84495576a9d8d0027e340123f307cb8a3bb70743 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Mon, 25 Mar 2024 16:56:46 +0100
4 Subject: tls: adjust recv return with async crypto and failed copy to
5 userspace
6
7 From: Sabrina Dubroca <sd@queasysnail.net>
8
9 [ Upstream commit 85eef9a41d019b59be7bc91793f26251909c0710 ]
10
11 process_rx_list may not copy as many bytes as we want to the userspace
12 buffer, for example in case we hit an EFAULT during the copy. If this
13 happens, we should only count the bytes that were actually copied,
14 which may be 0.
15
16 Subtracting async_copy_bytes is correct in both peek and !peek cases,
17 because decrypted == async_copy_bytes + peeked for the peek case: peek
18 is always !ZC, and we can go through either the sync or async path. In
19 the async case, we add chunk to both decrypted and
20 async_copy_bytes. In the sync case, we add chunk to both decrypted and
21 peeked. I missed that in commit 6caaf104423d ("tls: fix peeking with
22 sync+async decryption").
23
24 Fixes: 4d42cd6bc2ac ("tls: rx: fix return value for async crypto")
25 Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
26 Reviewed-by: Simon Horman <horms@kernel.org>
27 Link: https://lore.kernel.org/r/1b5a1eaab3c088a9dd5d9f1059ceecd7afe888d1.1711120964.git.sd@queasysnail.net
28 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
29 Signed-off-by: Sasha Levin <sashal@kernel.org>
30 ---
31 net/tls/tls_sw.c | 3 +++
32 1 file changed, 3 insertions(+)
33
34 diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
35 index 8e753d10e694a..925de4caa894a 100644
36 --- a/net/tls/tls_sw.c
37 +++ b/net/tls/tls_sw.c
38 @@ -2158,6 +2158,9 @@ int tls_sw_recvmsg(struct sock *sk,
39 else
40 err = process_rx_list(ctx, msg, &control, 0,
41 async_copy_bytes, is_peek, NULL);
42 +
43 + /* we could have copied less than we wanted, and possibly nothing */
44 + decrypted += max(err, 0) - async_copy_bytes;
45 }
46
47 copied += decrypted;
48 --
49 2.43.0
50