tls: don't skip over different type records from the rx_list
[ Upstream commit ec823bf3a479d42c589dc0f28ef4951c49cd2d2a ]
If we queue 3 records:
- record 1, type DATA
- record 2, some other type
- record 3, type DATA
and do a recv(PEEK), the rx_list will contain the first two records.
The next large recv will walk through the rx_list and copy data from
record 1, then stop because record 2 is a different type. Since we
haven't filled up our buffer, we will process the next available
record. It's also DATA, so we can merge it with the current read.
We shouldn't do that, since there was a record in between that we
ignored.
Add a flag to let process_rx_list inform tls_sw_recvmsg that it had
more data available.
Fixes: 692d7b5d1f
("tls: Fix recvmsg() to be able to peek across multiple records")
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Link: https://lore.kernel.org/r/f00c0c0afa080c60f016df1471158c1caf983c34.1708007371.git.sd@queasysnail.net
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
6756168add
commit
bdaf6bbfc1
|
@ -1845,7 +1845,8 @@ static int process_rx_list(struct tls_sw_context_rx *ctx,
|
|||
u8 *control,
|
||||
size_t skip,
|
||||
size_t len,
|
||||
bool is_peek)
|
||||
bool is_peek,
|
||||
bool *more)
|
||||
{
|
||||
struct sk_buff *skb = skb_peek(&ctx->rx_list);
|
||||
struct tls_msg *tlm;
|
||||
|
@ -1858,7 +1859,7 @@ static int process_rx_list(struct tls_sw_context_rx *ctx,
|
|||
|
||||
err = tls_record_content_type(msg, tlm, control);
|
||||
if (err <= 0)
|
||||
goto out;
|
||||
goto more;
|
||||
|
||||
if (skip < rxm->full_len)
|
||||
break;
|
||||
|
@ -1876,12 +1877,12 @@ static int process_rx_list(struct tls_sw_context_rx *ctx,
|
|||
|
||||
err = tls_record_content_type(msg, tlm, control);
|
||||
if (err <= 0)
|
||||
goto out;
|
||||
goto more;
|
||||
|
||||
err = skb_copy_datagram_msg(skb, rxm->offset + skip,
|
||||
msg, chunk);
|
||||
if (err < 0)
|
||||
goto out;
|
||||
goto more;
|
||||
|
||||
len = len - chunk;
|
||||
copied = copied + chunk;
|
||||
|
@ -1917,6 +1918,10 @@ static int process_rx_list(struct tls_sw_context_rx *ctx,
|
|||
|
||||
out:
|
||||
return copied ? : err;
|
||||
more:
|
||||
if (more)
|
||||
*more = true;
|
||||
goto out;
|
||||
}
|
||||
|
||||
static bool
|
||||
|
@ -2020,6 +2025,7 @@ int tls_sw_recvmsg(struct sock *sk,
|
|||
int target, err;
|
||||
bool is_kvec = iov_iter_is_kvec(&msg->msg_iter);
|
||||
bool is_peek = flags & MSG_PEEK;
|
||||
bool rx_more = false;
|
||||
bool released = true;
|
||||
bool bpf_strp_enabled;
|
||||
bool zc_capable;
|
||||
|
@ -2039,12 +2045,12 @@ int tls_sw_recvmsg(struct sock *sk,
|
|||
goto end;
|
||||
|
||||
/* Process pending decrypted records. It must be non-zero-copy */
|
||||
err = process_rx_list(ctx, msg, &control, 0, len, is_peek);
|
||||
err = process_rx_list(ctx, msg, &control, 0, len, is_peek, &rx_more);
|
||||
if (err < 0)
|
||||
goto end;
|
||||
|
||||
copied = err;
|
||||
if (len <= copied || (copied && control != TLS_RECORD_TYPE_DATA))
|
||||
if (len <= copied || (copied && control != TLS_RECORD_TYPE_DATA) || rx_more)
|
||||
goto end;
|
||||
|
||||
target = sock_rcvlowat(sk, flags & MSG_WAITALL, len);
|
||||
|
@ -2203,10 +2209,10 @@ int tls_sw_recvmsg(struct sock *sk,
|
|||
/* Drain records from the rx_list & copy if required */
|
||||
if (is_peek || is_kvec)
|
||||
err = process_rx_list(ctx, msg, &control, copied,
|
||||
decrypted, is_peek);
|
||||
decrypted, is_peek, NULL);
|
||||
else
|
||||
err = process_rx_list(ctx, msg, &control, 0,
|
||||
async_copy_bytes, is_peek);
|
||||
async_copy_bytes, is_peek, NULL);
|
||||
}
|
||||
|
||||
copied += decrypted;
|
||||
|
|
Loading…
Reference in New Issue