Skip to content

Commit 97e1caa

Browse files
Jakub Kicinskidavem330
authored andcommitted
net/tls: don't copy negative amounts of data in reencrypt
There is no guarantee the record starts before the skb frags. If we don't check for this condition copy amount will get negative, leading to reads and writes to random memory locations. Familiar hilarity ensues. Fixes: 4799ac8 ("tls: Add rx inline crypto offload") Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: John Hurley <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b2a20fd commit 97e1caa

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

net/tls/tls_device.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -628,14 +628,16 @@ static int tls_device_reencrypt(struct sock *sk, struct sk_buff *skb)
628628
else
629629
err = 0;
630630

631-
copy = min_t(int, skb_pagelen(skb) - offset,
632-
rxm->full_len - TLS_CIPHER_AES_GCM_128_TAG_SIZE);
631+
if (skb_pagelen(skb) > offset) {
632+
copy = min_t(int, skb_pagelen(skb) - offset,
633+
rxm->full_len - TLS_CIPHER_AES_GCM_128_TAG_SIZE);
633634

634-
if (skb->decrypted)
635-
skb_store_bits(skb, offset, buf, copy);
635+
if (skb->decrypted)
636+
skb_store_bits(skb, offset, buf, copy);
636637

637-
offset += copy;
638-
buf += copy;
638+
offset += copy;
639+
buf += copy;
640+
}
639641

640642
skb_walk_frags(skb, skb_iter) {
641643
copy = min_t(int, skb_iter->len,

0 commit comments

Comments
 (0)