Messages in this thread Patch in this message | | | From | Yuran Pereira <> | Subject | [PATCH 3/7] crypto: Fixes uninitialized skcipher_walk use in chacha_glue | Date | Thu, 2 Nov 2023 09:39:27 +0530 |
| |
In `chacha_simd_stream_xor()`, `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: 1456799 ("Unintialized scalar variable") Signed-off-by: Yuran Pereira <yuran.pereira@hotmail.com> --- arch/x86/crypto/chacha_glue.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/arch/x86/crypto/chacha_glue.c b/arch/x86/crypto/chacha_glue.c index 7b3a1cf0984b..be8dc756d205 100644 --- a/arch/x86/crypto/chacha_glue.c +++ b/arch/x86/crypto/chacha_glue.c @@ -13,6 +13,7 @@ #include <linux/kernel.h> #include <linux/module.h> #include <linux/sizes.h> +#include <linux/string.h> #include <asm/simd.h> asmlinkage void chacha_block_xor_ssse3(u32 *state, u8 *dst, const u8 *src, @@ -167,6 +168,7 @@ static int chacha_simd_stream_xor(struct skcipher_request *req, struct skcipher_walk walk; int err; + memset(&walk, 0, sizeof(walk)); err = skcipher_walk_virt(&walk, req, false); chacha_init_generic(state, ctx->key, iv); -- 2.25.1
| |