mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yuran Pereira <yuran.pereira@hotmail.com>
To: linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au
Cc: Yuran Pereira <yuran.pereira@hotmail.com>,
	davem@davemloft.net, tglx@linutronix.de, mingo@redhat.com,
	bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org,
	hpa@zytor.com, linux-kernel@vger.kernel.org,
	linux-kernel-mentees@lists.linuxfoundation.org
Subject: [PATCH 7/7] crypto: Fixes uninitialized skcipher_walk use in aria_gfni_avx512_glue
Date: Thu,  2 Nov 2023 09:39:31 +0530	[thread overview]
Message-ID: <DB3PR10MB68357FC2BB716211CB846DBFE8A6A@DB3PR10MB6835.EURPRD10.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <20231102040931.1556061-1-yuran.pereira@hotmail.com>

In `aria_avx512_ctr_encrypt`, `struct skcipher_walk *walk` is not fully
initialized before its use.

Although the call to `skcipher_walk_virt()` and subsequent functions
that this function calls seem to initialize some fields of this struct,

there is a chance that `skcipher_walk_virt()` returns
without fully clearing or properly initializing the `->flags` field
which means that the following flags:
`SKCIPHER_WALK_DIFF`, `SKCIPHER_WALK_COPY`, `SKCIPHER_WALK_SLOW`
could be storing junk values by the time `skcipher_walk_done()` is called.

This could lead to buggy or undefined behaviour since these flags
are checked in `skcipher_walk_done()`:

```C
int skcipher_walk_done(struct skcipher_walk *walk, int err)
{
	...
    if (likely(!(walk->flags & (SKCIPHER_WALK_PHYS |
        SKCIPHER_WALK_SLOW |
        SKCIPHER_WALK_COPY |
        SKCIPHER_WALK_DIFF)))) {
    ...
}
```

To prevent this, this patch ensures that instances of
`struct skcipher_walk` are correctly initialized prior to their use.

Addresses-Coverity-IDs: 15916159 ("Unintialized scalar variable")
Signed-off-by: Yuran Pereira <yuran.pereira@hotmail.com>
---
 arch/x86/crypto/aria_gfni_avx512_glue.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/crypto/aria_gfni_avx512_glue.c b/arch/x86/crypto/aria_gfni_avx512_glue.c
index f4a2208d2638..cf689cc880df 100644
--- a/arch/x86/crypto/aria_gfni_avx512_glue.c
+++ b/arch/x86/crypto/aria_gfni_avx512_glue.c
@@ -12,6 +12,7 @@
 #include <linux/err.h>
 #include <linux/module.h>
 #include <linux/types.h>
+#include <linux/string.h>
 
 #include "ecb_cbc_helpers.h"
 #include "aria-avx.h"
@@ -81,6 +82,7 @@ static int aria_avx512_ctr_encrypt(struct skcipher_request *req)
 	unsigned int nbytes;
 	int err;
 
+	memset(&walk, 0, sizeof(walk));
 	err = skcipher_walk_virt(&walk, req, false);
 
 	while ((nbytes = walk.nbytes) > 0) {
-- 
2.25.1


  parent reply	other threads:[~2023-11-02  4:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-02  4:04 [PATCH 0/7] crypto: Proper Initialization of `struct skcipher_walk` in x86 Glue Files Yuran Pereira
2023-11-02  4:09 ` [PATCH 1/7] crypto: Fixes uninitialized skcipher_walk use in sm4_aesni_avx_glue Yuran Pereira
     [not found] ` <20231102040931.1556061-1-yuran.pereira@hotmail.com>
2023-11-02  4:09   ` [PATCH 2/7] crypto: Fixes uninitialized skcipher_walk use in des3_ede_glue Yuran Pereira
2023-11-02  4:09   ` [PATCH 3/7] crypto: Fixes uninitialized skcipher_walk use in chacha_glue Yuran Pereira
2023-11-02  4:09   ` [PATCH 4/7] crypto: Fixes uninitialized skcipher_walk use in aesni-intel_glue Yuran Pereira
2023-11-02  4:09   ` [PATCH 5/7] crypto: Fixes uninitialized skcipher_walk use in aria_aesni_avx2_glue Yuran Pereira
2023-11-02  4:09   ` [PATCH 6/7] crypto: Fixes uninitialized skcipher_walk use in aria_aesni_avx_glue Yuran Pereira
2023-11-02  4:09   ` Yuran Pereira [this message]
2023-11-02  4:20 ` [PATCH 0/7] crypto: Proper Initialization of `struct skcipher_walk` in x86 Glue Files Eric Biggers
2023-11-02  4:30   ` Herbert Xu
2023-11-02  4:57     ` Yuran Pereira
2023-11-02  5:00       ` Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DB3PR10MB68357FC2BB716211CB846DBFE8A6A@DB3PR10MB6835.EURPRD10.PROD.OUTLOOK.COM \
    --to=yuran.pereira@hotmail.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=hpa@zytor.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®