netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
	borisp@nvidia.com, john.fastabend@gmail.com, tariqt@nvidia.com,
	Jakub Kicinski <kuba@kernel.org>,
	Shai Amiram <samiram@nvidia.com>
Subject: [PATCH net 4/7] tls: rx: strp: fix determining record length in copy mode
Date: Tue, 16 May 2023 18:50:39 -0700	[thread overview]
Message-ID: <20230517015042.1243644-5-kuba@kernel.org> (raw)
In-Reply-To: <20230517015042.1243644-1-kuba@kernel.org>

We call tls_rx_msg_size(skb) before doing skb->len += chunk.
So the tls_rx_msg_size() code will see old skb->len, most
likely leading to an over-read.

Worst case we will over read an entire record, next iteration
will try to trim the skb but may end up turning frag len negative
or discarding the subsequent record (since we already told TCP
we've read it during previous read but now we'll trim it out of
the skb).

Fixes: 84c61fe1a75b ("tls: rx: do not use the standard strparser")
Tested-by: Shai Amiram <samiram@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 net/tls/tls_strp.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/net/tls/tls_strp.c b/net/tls/tls_strp.c
index 2b6fa9855999..e2e48217e7ac 100644
--- a/net/tls/tls_strp.c
+++ b/net/tls/tls_strp.c
@@ -210,19 +210,28 @@ static int tls_strp_copyin(read_descriptor_t *desc, struct sk_buff *in_skb,
 					   skb_frag_size(frag),
 					   chunk));
 
-		sz = tls_rx_msg_size(strp, strp->anchor);
+		skb->len += chunk;
+		skb->data_len += chunk;
+		skb_frag_size_add(frag, chunk);
+
+		sz = tls_rx_msg_size(strp, skb);
 		if (sz < 0) {
 			desc->error = sz;
 			return 0;
 		}
 
 		/* We may have over-read, sz == 0 is guaranteed under-read */
-		if (sz > 0)
-			chunk =	min_t(size_t, chunk, sz - skb->len);
+		if (unlikely(sz && sz < skb->len)) {
+			int over = skb->len - sz;
+
+			WARN_ON_ONCE(over > chunk);
+			skb->len -= over;
+			skb->data_len -= over;
+			skb_frag_size_add(frag, -over);
+
+			chunk -= over;
+		}
 
-		skb->len += chunk;
-		skb->data_len += chunk;
-		skb_frag_size_add(frag, chunk);
 		frag++;
 		len -= chunk;
 		offset += chunk;
-- 
2.40.1


  parent reply	other threads:[~2023-05-17  1:50 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-17  1:50 [PATCH net 0/7] tls: rx: strp: fix inline crypto offload Jakub Kicinski
2023-05-17  1:50 ` [PATCH net 1/7] tls: rx: device: fix checking decryption status Jakub Kicinski
2023-05-18 15:42   ` Simon Horman
2023-05-17  1:50 ` [PATCH net 2/7] tls: rx: strp: set the skb->len of detached / CoW'ed skbs Jakub Kicinski
2023-05-18 15:44   ` Simon Horman
2023-05-17  1:50 ` [PATCH net 3/7] tls: rx: strp: force mixed decrypted records into copy mode Jakub Kicinski
2023-05-18 15:43   ` Simon Horman
2023-05-17  1:50 ` Jakub Kicinski [this message]
2023-05-18 15:44   ` [PATCH net 4/7] tls: rx: strp: fix determining record length in " Simon Horman
2023-05-17  1:50 ` [PATCH net 5/7] tls: rx: strp: factor out copying skb data Jakub Kicinski
2023-05-18 15:45   ` Simon Horman
2023-05-17  1:50 ` [PATCH net 6/7] tls: rx: strp: preserve decryption status of skbs when needed Jakub Kicinski
2023-05-18 15:46   ` Simon Horman
2023-05-17  1:50 ` [PATCH net 7/7] tls: rx: strp: don't use GFP_KERNEL in softirq context Jakub Kicinski
2023-05-18 15:45   ` Simon Horman
2023-05-19  7:50 ` [PATCH net 0/7] tls: rx: strp: fix inline crypto offload patchwork-bot+netdevbpf

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=20230517015042.1243644-5-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=borisp@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=samiram@nvidia.com \
    --cc=tariqt@nvidia.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).