1 From a788848116454d753b13a4888e0e31ada3c4d393 Mon Sep 17 00:00:00 2001
2 From: Mikulas Patocka <mpatocka@redhat.com>
3 Date: Wed, 5 Sep 2018 09:18:43 -0400
4 Subject: crypto: aesni - don't use GFP_ATOMIC allocation if the request doesn't cross a page in gcm
6 From: Mikulas Patocka <mpatocka@redhat.com>
8 commit a788848116454d753b13a4888e0e31ada3c4d393 upstream.
10 This patch fixes gcmaes_crypt_by_sg so that it won't use memory
11 allocation if the data doesn't cross a page boundary.
13 Authenticated encryption may be used by dm-crypt. If the encryption or
14 decryption fails, it would result in I/O error and filesystem corruption.
15 The function gcmaes_crypt_by_sg is using GFP_ATOMIC allocation that can
16 fail anytime. This patch fixes the logic so that it won't attempt the
17 failing allocation if the data doesn't cross a page boundary.
19 Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
20 Cc: stable@vger.kernel.org
21 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
22 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
25 arch/x86/crypto/aesni-intel_glue.c | 2 +-
26 1 file changed, 1 insertion(+), 1 deletion(-)
28 --- a/arch/x86/crypto/aesni-intel_glue.c
29 +++ b/arch/x86/crypto/aesni-intel_glue.c
30 @@ -817,7 +817,7 @@ static int gcmaes_crypt_by_sg(bool enc,
31 /* Linearize assoc, if not already linear */
32 if (req->src->length >= assoclen && req->src->length &&
33 (!PageHighMem(sg_page(req->src)) ||
34 - req->src->offset + req->src->length < PAGE_SIZE)) {
35 + req->src->offset + req->src->length <= PAGE_SIZE)) {
36 scatterwalk_start(&assoc_sg_walk, req->src);
37 assoc = scatterwalk_map(&assoc_sg_walk);