Linux cryptographic layer development
 help / color / mirror / Atom feed
* [PATCH net] net/tls: fix sk_msg trim on fallback to copy mode
@ 2019-10-30 16:05 Jakub Kicinski
  2019-10-31 21:16 ` Jakub Kicinski
  2019-10-31 22:05 ` John Fastabend
  0 siblings, 2 replies; 14+ messages in thread
From: Jakub Kicinski @ 2019-10-30 16:05 UTC (permalink / raw)
  To: davem
  Cc: netdev, oss-drivers, borisp, aviadye, john.fastabend, daniel,
	Jakub Kicinski, syzbot+f8495bff23a879a6d0bd,
	syzbot+6f50c99e8f6194bf363f, Eric Biggers, herbert, glider,
	linux-crypto

sk_msg_trim() tries to only update curr pointer if it falls into
the trimmed region. The logic, however, does not take into the
account pointer wrapping that sk_msg_iter_var_prev() does.
This means that when the message was trimmed completely, the new
curr pointer would have the value of MAX_MSG_FRAGS - 1, which is
neither smaller than any other value, nor would it actually be
correct.

Special case the trimming to 0 length a little bit.

This bug caused the TLS code to not copy all of the message, if
zero copy filled in fewer sg entries than memcopy would need.

Big thanks to Alexander Potapenko for the non-KMSAN reproducer.

Fixes: d829e9c4112b ("tls: convert to generic sk_msg interface")
Reported-by: syzbot+f8495bff23a879a6d0bd@syzkaller.appspotmail.com
Reported-by: syzbot+6f50c99e8f6194bf363f@syzkaller.appspotmail.com
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
Daniel, John, does this look okay?

CC: Eric Biggers <ebiggers@kernel.org>
CC: herbert@gondor.apana.org.au
CC: glider@google.com
CC: linux-crypto@vger.kernel.org

 net/core/skmsg.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/core/skmsg.c b/net/core/skmsg.c
index cf390e0aa73d..c42c145216b1 100644
--- a/net/core/skmsg.c
+++ b/net/core/skmsg.c
@@ -276,7 +276,10 @@ void sk_msg_trim(struct sock *sk, struct sk_msg *msg, int len)
 	 * However trimed data that has not yet been used in a copy op
 	 * does not require an update.
 	 */
-	if (msg->sg.curr >= i) {
+	if (!msg->sg.size) {
+		msg->sg.curr = 0;
+		msg->sg.copybreak = 0;
+	} else if (msg->sg.curr >= i) {
 		msg->sg.curr = i;
 		msg->sg.copybreak = msg->sg.data[i].length;
 	}
-- 
2.23.0


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

end of thread, other threads:[~2019-11-04 22:58 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-30 16:05 [PATCH net] net/tls: fix sk_msg trim on fallback to copy mode Jakub Kicinski
2019-10-31 21:16 ` Jakub Kicinski
2019-10-31 22:05 ` John Fastabend
2019-10-31 22:08   ` John Fastabend
2019-10-31 22:24   ` Jakub Kicinski
2019-11-01  1:41     ` Jakub Kicinski
2019-11-01  4:44     ` John Fastabend
2019-11-01  4:54       ` Jakub Kicinski
2019-11-01 15:01         ` John Fastabend
2019-11-01 17:22           ` [oss-drivers] " Jakub Kicinski
2019-11-01 19:51             ` Jakub Kicinski
2019-11-04 18:56               ` John Fastabend
2019-11-04 19:34                 ` Jakub Kicinski
2019-11-04 22:58                   ` John Fastabend

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox