Skip to content

Commit 32b55c5

Browse files
qsndavem330
authored andcommitted
net: tls: fix use-after-free with partial reads and async decrypt
tls_decrypt_sg doesn't take a reference on the pages from clear_skb, so the put_page() in tls_decrypt_done releases them, and we trigger a use-after-free in process_rx_list when we try to read from the partially-read skb. Fixes: fd31f39 ("tls: rx: decrypt into a fresh skb") Signed-off-by: Sabrina Dubroca <sd@queasysnail.net> Signed-off-by: Jakub Kicinski <kuba@kernel.org> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8590541 commit 32b55c5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

net/tls/tls_sw.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ struct tls_decrypt_ctx {
6363
u8 iv[TLS_MAX_IV_SIZE];
6464
u8 aad[TLS_MAX_AAD_SIZE];
6565
u8 tail;
66+
bool free_sgout;
6667
struct scatterlist sg[];
6768
};
6869

@@ -187,7 +188,6 @@ static void tls_decrypt_done(void *data, int err)
187188
struct aead_request *aead_req = data;
188189
struct crypto_aead *aead = crypto_aead_reqtfm(aead_req);
189190
struct scatterlist *sgout = aead_req->dst;
190-
struct scatterlist *sgin = aead_req->src;
191191
struct tls_sw_context_rx *ctx;
192192
struct tls_decrypt_ctx *dctx;
193193
struct tls_context *tls_ctx;
@@ -224,7 +224,7 @@ static void tls_decrypt_done(void *data, int err)
224224
}
225225

226226
/* Free the destination pages if skb was not decrypted inplace */
227-
if (sgout != sgin) {
227+
if (dctx->free_sgout) {
228228
/* Skip the first S/G entry as it points to AAD */
229229
for_each_sg(sg_next(sgout), sg, UINT_MAX, pages) {
230230
if (!sg)
@@ -1583,6 +1583,7 @@ static int tls_decrypt_sg(struct sock *sk, struct iov_iter *out_iov,
15831583
} else if (out_sg) {
15841584
memcpy(sgout, out_sg, n_sgout * sizeof(*sgout));
15851585
}
1586+
dctx->free_sgout = !!pages;
15861587

15871588
/* Prepare and submit AEAD request */
15881589
err = tls_do_decryption(sk, sgin, sgout, dctx->iv,

0 commit comments

Comments
 (0)