* [PATCH 2/7] crypto: Fixes uninitialized skcipher_walk use in des3_ede_glue
[not found] ` <20231102040931.1556061-1-yuran.pereira@hotmail.com>
@ 2023-11-02 4:09 ` Yuran Pereira
2023-11-02 4:09 ` [PATCH 3/7] crypto: Fixes uninitialized skcipher_walk use in chacha_glue Yuran Pereira
` (4 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: Yuran Pereira @ 2023-11-02 4:09 UTC (permalink / raw)
To: linux-crypto, herbert
Cc: Yuran Pereira, davem, tglx, mingo, bp, dave.hansen, x86, hpa,
linux-kernel, linux-kernel-mentees
In the following functions:
- `ecb_crypt`
- `cbc_encrypt`
- `cbc_decrypt`
`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: 1434673 ("Unintialized scalar variable")
Signed-off-by: Yuran Pereira <yuran.pereira@hotmail.com>
---
arch/x86/crypto/des3_ede_glue.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/x86/crypto/des3_ede_glue.c b/arch/x86/crypto/des3_ede_glue.c
index abb8b1fe123b..6f16b09b52fe 100644
--- a/arch/x86/crypto/des3_ede_glue.c
+++ b/arch/x86/crypto/des3_ede_glue.c
@@ -15,6 +15,7 @@
#include <linux/init.h>
#include <linux/module.h>
#include <linux/types.h>
+#include <linux/string.h>
struct des3_ede_x86_ctx {
struct des3_ede_ctx enc;
@@ -70,6 +71,7 @@ static int ecb_crypt(struct skcipher_request *req, const u32 *expkey)
unsigned int nbytes;
int err;
+ memset(&walk, 0, sizeof(walk));
err = skcipher_walk_virt(&walk, req, false);
while ((nbytes = walk.nbytes)) {
@@ -154,6 +156,7 @@ static int cbc_encrypt(struct skcipher_request *req)
unsigned int nbytes;
int err;
+ memset(&walk, 0, sizeof(walk));
err = skcipher_walk_virt(&walk, req, false);
while (walk.nbytes) {
@@ -233,6 +236,7 @@ static int cbc_decrypt(struct skcipher_request *req)
unsigned int nbytes;
int err;
+ memset(&walk, 0, sizeof(walk));
err = skcipher_walk_virt(&walk, req, false);
while (walk.nbytes) {
--
2.25.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 3/7] crypto: Fixes uninitialized skcipher_walk use in chacha_glue
[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 ` Yuran Pereira
2023-11-02 4:09 ` [PATCH 4/7] crypto: Fixes uninitialized skcipher_walk use in aesni-intel_glue Yuran Pereira
` (3 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: Yuran Pereira @ 2023-11-02 4:09 UTC (permalink / raw)
To: linux-crypto, herbert
Cc: Yuran Pereira, davem, tglx, mingo, bp, dave.hansen, x86, hpa,
linux-kernel, linux-kernel-mentees
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
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 4/7] crypto: Fixes uninitialized skcipher_walk use in aesni-intel_glue
[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 ` Yuran Pereira
2023-11-02 4:09 ` [PATCH 5/7] crypto: Fixes uninitialized skcipher_walk use in aria_aesni_avx2_glue Yuran Pereira
` (2 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: Yuran Pereira @ 2023-11-02 4:09 UTC (permalink / raw)
To: linux-crypto, herbert
Cc: Yuran Pereira, davem, tglx, mingo, bp, dave.hansen, x86, hpa,
linux-kernel, linux-kernel-mentees
In the following functions:
- `sm4_avx_ctr_crypt`
- `ecb_encrypt`
- `ecb_decrypt`
- `cbc_encrypt`
- `cbc_decrypt`
- `cts_cbc_encrypt`
- `cts_cbc_decrypt`
- `ctr_crypt`
- `xctr_crypt`
- `xts_crypt`
`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: 139545, 1508669 ("Unintialized scalar variable")
Signed-off-by: Yuran Pereira <yuran.pereira@hotmail.com>
---
arch/x86/crypto/aesni-intel_glue.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/arch/x86/crypto/aesni-intel_glue.c b/arch/x86/crypto/aesni-intel_glue.c
index 39d6a62ac627..d2c5f00a33ff 100644
--- a/arch/x86/crypto/aesni-intel_glue.c
+++ b/arch/x86/crypto/aesni-intel_glue.c
@@ -35,6 +35,7 @@
#include <linux/workqueue.h>
#include <linux/spinlock.h>
#include <linux/static_call.h>
+#include <linux/string.h>
#define AESNI_ALIGN 16
@@ -296,6 +297,7 @@ static int ecb_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)) {
@@ -318,6 +320,7 @@ static int ecb_decrypt(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)) {
@@ -340,6 +343,7 @@ static int cbc_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)) {
@@ -362,6 +366,7 @@ static int cbc_decrypt(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)) {
@@ -387,6 +392,8 @@ static int cts_cbc_encrypt(struct skcipher_request *req)
struct skcipher_walk walk;
int err;
+ memset(&walk, 0, sizeof(walk));
+
skcipher_request_set_tfm(&subreq, tfm);
skcipher_request_set_callback(&subreq, skcipher_request_flags(req),
NULL, NULL);
@@ -443,6 +450,8 @@ static int cts_cbc_decrypt(struct skcipher_request *req)
struct skcipher_walk walk;
int err;
+ memset(&walk, 0, sizeof(walk));
+
skcipher_request_set_tfm(&subreq, tfm);
skcipher_request_set_callback(&subreq, skcipher_request_flags(req),
NULL, NULL);
@@ -515,6 +524,7 @@ static int ctr_crypt(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) {
@@ -566,6 +576,7 @@ static int xctr_crypt(struct skcipher_request *req)
int err;
__le32 block[AES_BLOCK_SIZE / sizeof(__le32)];
+ memset(&walk, 0, sizeof(walk));
err = skcipher_walk_virt(&walk, req, false);
while ((nbytes = walk.nbytes) > 0) {
@@ -912,6 +923,7 @@ static int xts_crypt(struct skcipher_request *req, bool encrypt)
if (req->cryptlen < AES_BLOCK_SIZE)
return -EINVAL;
+ memset(&walk, 0, sizeof(walk));
err = skcipher_walk_virt(&walk, req, false);
if (!walk.nbytes)
return err;
--
2.25.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 5/7] crypto: Fixes uninitialized skcipher_walk use in aria_aesni_avx2_glue
[not found] ` <20231102040931.1556061-1-yuran.pereira@hotmail.com>
` (2 preceding siblings ...)
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 ` 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 ` [PATCH 7/7] crypto: Fixes uninitialized skcipher_walk use in aria_gfni_avx512_glue Yuran Pereira
5 siblings, 0 replies; 12+ messages in thread
From: Yuran Pereira @ 2023-11-02 4:09 UTC (permalink / raw)
To: linux-crypto, herbert
Cc: Yuran Pereira, davem, tglx, mingo, bp, dave.hansen, x86, hpa,
linux-kernel, linux-kernel-mentees
In `aria_avx2_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: 1521842 ("Unintialized scalar variable")
Signed-off-by: Yuran Pereira <yuran.pereira@hotmail.com>
---
arch/x86/crypto/aria_aesni_avx2_glue.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/x86/crypto/aria_aesni_avx2_glue.c b/arch/x86/crypto/aria_aesni_avx2_glue.c
index 87a11804fc77..d5a8077f9f96 100644
--- a/arch/x86/crypto/aria_aesni_avx2_glue.c
+++ b/arch/x86/crypto/aria_aesni_avx2_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"
@@ -94,6 +95,7 @@ static int aria_avx2_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
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 6/7] crypto: Fixes uninitialized skcipher_walk use in aria_aesni_avx_glue
[not found] ` <20231102040931.1556061-1-yuran.pereira@hotmail.com>
` (3 preceding siblings ...)
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 ` Yuran Pereira
2023-11-02 4:09 ` [PATCH 7/7] crypto: Fixes uninitialized skcipher_walk use in aria_gfni_avx512_glue Yuran Pereira
5 siblings, 0 replies; 12+ messages in thread
From: Yuran Pereira @ 2023-11-02 4:09 UTC (permalink / raw)
To: linux-crypto, herbert
Cc: Yuran Pereira, davem, tglx, mingo, bp, dave.hansen, x86, hpa,
linux-kernel, linux-kernel-mentees
In `aria_avx_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: 1516269 ("Unintialized scalar variable")
Signed-off-by: Yuran Pereira <yuran.pereira@hotmail.com>
---
arch/x86/crypto/aria_aesni_avx_glue.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/x86/crypto/aria_aesni_avx_glue.c b/arch/x86/crypto/aria_aesni_avx_glue.c
index 4e1516b76669..71589d58d0d3 100644
--- a/arch/x86/crypto/aria_aesni_avx_glue.c
+++ b/arch/x86/crypto/aria_aesni_avx_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"
@@ -92,6 +93,7 @@ static int aria_avx_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
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 7/7] crypto: Fixes uninitialized skcipher_walk use in aria_gfni_avx512_glue
[not found] ` <20231102040931.1556061-1-yuran.pereira@hotmail.com>
` (4 preceding siblings ...)
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
5 siblings, 0 replies; 12+ messages in thread
From: Yuran Pereira @ 2023-11-02 4:09 UTC (permalink / raw)
To: linux-crypto, herbert
Cc: Yuran Pereira, davem, tglx, mingo, bp, dave.hansen, x86, hpa,
linux-kernel, linux-kernel-mentees
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
^ permalink raw reply related [flat|nested] 12+ messages in thread