Skip to content

Commit

Permalink
net/tls: don't copy negative amounts of data in reencrypt
Browse files Browse the repository at this point in the history
[ Upstream commit 97e1caa ]

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 <jakub.kicinski@netronome.com>
Reviewed-by: John Hurley <john.hurley@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Jakub Kicinski authored and Greg Kroah-Hartman committed May 5, 2019
1 parent 126255f commit f7f4d4b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions net/tls/tls_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,14 +610,16 @@ static int tls_device_reencrypt(struct sock *sk, struct sk_buff *skb)
else
err = 0;

copy = min_t(int, skb_pagelen(skb) - offset,
rxm->full_len - TLS_CIPHER_AES_GCM_128_TAG_SIZE);
if (skb_pagelen(skb) > offset) {
copy = min_t(int, skb_pagelen(skb) - offset,
rxm->full_len - TLS_CIPHER_AES_GCM_128_TAG_SIZE);

if (skb->decrypted)
skb_store_bits(skb, offset, buf, copy);
if (skb->decrypted)
skb_store_bits(skb, offset, buf, copy);

offset += copy;
buf += copy;
offset += copy;
buf += copy;
}

skb_walk_frags(skb, skb_iter) {
copy = min_t(int, skb_iter->len,
Expand Down

0 comments on commit f7f4d4b

Please sign in to comment.