Skip to content

Commit 6caaf10

Browse files
qsnkuba-moo
authored andcommitted
tls: fix peeking with sync+async decryption
If we peek from 2 records with a currently empty rx_list, and the first record is decrypted synchronously but the second record is decrypted async, the following happens: 1. decrypt record 1 (sync) 2. copy from record 1 to the userspace's msg 3. queue the decrypted record to rx_list for future read(!PEEK) 4. decrypt record 2 (async) 5. queue record 2 to rx_list 6. call process_rx_list to copy data from the 2nd record We currently pass copied=0 as skip offset to process_rx_list, so we end up copying once again from the first record. We should skip over the data we've already copied. Seen with selftest tls.12_aes_gcm.recv_peek_large_buf_mult_recs Fixes: 692d7b5 ("tls: Fix recvmsg() to be able to peek across multiple records") Signed-off-by: Sabrina Dubroca <[email protected]> Link: https://lore.kernel.org/r/1b132d2b2b99296bfde54e8a67672d90d6d16e71.1709132643.git.sd@queasysnail.net Signed-off-by: Jakub Kicinski <[email protected]>
1 parent f7fa16d commit 6caaf10

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

net/tls/tls_sw.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,6 +1950,7 @@ int tls_sw_recvmsg(struct sock *sk,
19501950
struct strp_msg *rxm;
19511951
struct tls_msg *tlm;
19521952
ssize_t copied = 0;
1953+
ssize_t peeked = 0;
19531954
bool async = false;
19541955
int target, err;
19551956
bool is_kvec = iov_iter_is_kvec(&msg->msg_iter);
@@ -2097,8 +2098,10 @@ int tls_sw_recvmsg(struct sock *sk,
20972098
if (err < 0)
20982099
goto put_on_rx_list_err;
20992100

2100-
if (is_peek)
2101+
if (is_peek) {
2102+
peeked += chunk;
21012103
goto put_on_rx_list;
2104+
}
21022105

21032106
if (partially_consumed) {
21042107
rxm->offset += chunk;
@@ -2137,8 +2140,8 @@ int tls_sw_recvmsg(struct sock *sk,
21372140

21382141
/* Drain records from the rx_list & copy if required */
21392142
if (is_peek || is_kvec)
2140-
err = process_rx_list(ctx, msg, &control, copied,
2141-
decrypted, is_peek, NULL);
2143+
err = process_rx_list(ctx, msg, &control, copied + peeked,
2144+
decrypted - peeked, is_peek, NULL);
21422145
else
21432146
err = process_rx_list(ctx, msg, &control, 0,
21442147
async_copy_bytes, is_peek, NULL);

0 commit comments

Comments
 (0)