]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
net/tls: Set count of SG entries if sk_alloc_sg returns -ENOSPC
authorVakul Garg <vakul.garg@nxp.com>
Thu, 6 Sep 2018 16:11:40 +0000 (21:41 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Sep 2018 06:37:58 +0000 (08:37 +0200)
[ Upstream commit 52ea992cfac357b73180d5c051dca43bc8d20c2a ]

tls_sw_sendmsg() allocates plaintext and encrypted SG entries using
function sk_alloc_sg(). In case the number of SG entries hit
MAX_SKB_FRAGS, sk_alloc_sg() returns -ENOSPC and sets the variable for
current SG index to '0'. This leads to calling of function
tls_push_record() with 'sg_encrypted_num_elem = 0' and later causes
kernel crash. To fix this, set the number of SG elements to the number
of elements in plaintext/encrypted SG arrays in case sk_alloc_sg()
returns -ENOSPC.

Fixes: 3c4d7559159b ("tls: kernel TLS support")
Signed-off-by: Vakul Garg <vakul.garg@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/tls/tls_sw.c

index fb79caf56d0e8fe4ec0a8baf08b3067c54666315..b81aa6d7dc45e590a4e75477041360ff132033a8 100644 (file)
@@ -170,6 +170,9 @@ static int alloc_encrypted_sg(struct sock *sk, int len)
        rc = alloc_sg(sk, len, ctx->sg_encrypted_data,
                      &ctx->sg_encrypted_num_elem, &ctx->sg_encrypted_size, 0);
 
+       if (rc == -ENOSPC)
+               ctx->sg_encrypted_num_elem = ARRAY_SIZE(ctx->sg_encrypted_data);
+
        return rc;
 }
 
@@ -183,6 +186,9 @@ static int alloc_plaintext_sg(struct sock *sk, int len)
                      &ctx->sg_plaintext_num_elem, &ctx->sg_plaintext_size,
                      tls_ctx->pending_open_record_frags);
 
+       if (rc == -ENOSPC)
+               ctx->sg_plaintext_num_elem = ARRAY_SIZE(ctx->sg_plaintext_data);
+
        return rc;
 }