LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] crypto: x86/aes-ni - check walk.nbytes instead of err
@ 2021-09-11 11:07 Shreyansh Chouhan
  2021-09-17  3:21 ` Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Shreyansh Chouhan @ 2021-09-11 11:07 UTC (permalink / raw)
  To: herbert, davem, tglx, mingo, bp, x86, hpa
  Cc: Shreyansh Chouhan, linux-crypto, linux-kernel, Dan Carpenter

In the code for xts_crypt(), we check for the err value returned by
skcipher_walk_virt() and return from the function if it is non zero.
However, skcipher_walk_virt() can set walk.nbytes to 0, which would cause
us to call kernel_fpu_begin(), and then skip the kernel_fpu_end() call.

This patch checks for the walk.nbytes value instead, and returns if
walk.nbytes is 0. This prevents us from calling kernel_fpu_begin() in
the first place and also covers the case of having a non zero err value
returned from skcipher_walk_virt().

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Shreyansh Chouhan <chouhan.shreyansh630@gmail.com>
---
 arch/x86/crypto/aesni-intel_glue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/crypto/aesni-intel_glue.c b/arch/x86/crypto/aesni-intel_glue.c
index 0fc961bef299..e09f4672dd38 100644
--- a/arch/x86/crypto/aesni-intel_glue.c
+++ b/arch/x86/crypto/aesni-intel_glue.c
@@ -866,7 +866,7 @@ static int xts_crypt(struct skcipher_request *req, bool encrypt)
 		req = &subreq;
 
 		err = skcipher_walk_virt(&walk, req, false);
-		if (err)
+		if (!walk.nbytes)
 			return err;
 	} else {
 		tail = 0;
-- 
2.31.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] crypto: x86/aes-ni - check walk.nbytes instead of err
  2021-09-11 11:07 [PATCH] crypto: x86/aes-ni - check walk.nbytes instead of err Shreyansh Chouhan
@ 2021-09-17  3:21 ` Herbert Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2021-09-17  3:21 UTC (permalink / raw)
  To: Shreyansh Chouhan
  Cc: davem, tglx, mingo, bp, x86, hpa, linux-crypto, linux-kernel,
	Dan Carpenter

On Sat, Sep 11, 2021 at 04:37:59PM +0530, Shreyansh Chouhan wrote:
> In the code for xts_crypt(), we check for the err value returned by
> skcipher_walk_virt() and return from the function if it is non zero.
> However, skcipher_walk_virt() can set walk.nbytes to 0, which would cause
> us to call kernel_fpu_begin(), and then skip the kernel_fpu_end() call.
> 
> This patch checks for the walk.nbytes value instead, and returns if
> walk.nbytes is 0. This prevents us from calling kernel_fpu_begin() in
> the first place and also covers the case of having a non zero err value
> returned from skcipher_walk_virt().
> 
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Shreyansh Chouhan <chouhan.shreyansh630@gmail.com>
> ---
>  arch/x86/crypto/aesni-intel_glue.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-09-17  3:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-11 11:07 [PATCH] crypto: x86/aes-ni - check walk.nbytes instead of err Shreyansh Chouhan
2021-09-17  3:21 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).