2018-10-07 11:58:10

by Michael Schupikov

[permalink] [raw]
Subject: [PATCH] crypto/testmgr.c: fix sizeof() on COMP_BUF_SIZE

After allocation, output and decomp_output both point to memory chunks of
size COMP_BUF_SIZE. Then, only the first bytes are zeroed out using
sizeof(COMP_BUF_SIZE) as parameter to memset(), because
sizeof(COMP_BUF_SIZE) provides the size of the constant and not the size of
allocated memory.

Instead, the whole allocated memory is meant to be zeroed out. Use
COMP_BUF_SIZE as parameter to memset() directly in order to accomplish
this.

Fixes: 336073840a872 ("crypto: testmgr - Allow different compression results")

Signed-off-by: Michael Schupikov <[email protected]>
---
crypto/testmgr.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index a1d42245082a..790aa3536631 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -1400,8 +1400,8 @@ static int test_comp(struct crypto_comp *tfm,
int ilen;
unsigned int dlen = COMP_BUF_SIZE;

- memset(output, 0, sizeof(COMP_BUF_SIZE));
- memset(decomp_output, 0, sizeof(COMP_BUF_SIZE));
+ memset(output, 0, COMP_BUF_SIZE);
+ memset(decomp_output, 0, COMP_BUF_SIZE);

ilen = ctemplate[i].inlen;
ret = crypto_comp_compress(tfm, ctemplate[i].input,
@@ -1445,7 +1445,7 @@ static int test_comp(struct crypto_comp *tfm,
int ilen;
unsigned int dlen = COMP_BUF_SIZE;

- memset(decomp_output, 0, sizeof(COMP_BUF_SIZE));
+ memset(decomp_output, 0, COMP_BUF_SIZE);

ilen = dtemplate[i].inlen;
ret = crypto_comp_decompress(tfm, dtemplate[i].input,
--
2.19.0


2018-10-08 11:39:29

by Ard Biesheuvel

[permalink] [raw]
Subject: Re: [PATCH] crypto/testmgr.c: fix sizeof() on COMP_BUF_SIZE

On 7 October 2018 at 13:58, Michael Schupikov <[email protected]> wrote:
> After allocation, output and decomp_output both point to memory chunks of
> size COMP_BUF_SIZE. Then, only the first bytes are zeroed out using
> sizeof(COMP_BUF_SIZE) as parameter to memset(), because
> sizeof(COMP_BUF_SIZE) provides the size of the constant and not the size of
> allocated memory.
>
> Instead, the whole allocated memory is meant to be zeroed out. Use
> COMP_BUF_SIZE as parameter to memset() directly in order to accomplish
> this.
>
> Fixes: 336073840a872 ("crypto: testmgr - Allow different compression results")
>
> Signed-off-by: Michael Schupikov <[email protected]>

Nice catch

Reviewed-by: Ard Biesheuvel <[email protected]>

> ---
> crypto/testmgr.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/crypto/testmgr.c b/crypto/testmgr.c
> index a1d42245082a..790aa3536631 100644
> --- a/crypto/testmgr.c
> +++ b/crypto/testmgr.c
> @@ -1400,8 +1400,8 @@ static int test_comp(struct crypto_comp *tfm,
> int ilen;
> unsigned int dlen = COMP_BUF_SIZE;
>
> - memset(output, 0, sizeof(COMP_BUF_SIZE));
> - memset(decomp_output, 0, sizeof(COMP_BUF_SIZE));
> + memset(output, 0, COMP_BUF_SIZE);
> + memset(decomp_output, 0, COMP_BUF_SIZE);
>
> ilen = ctemplate[i].inlen;
> ret = crypto_comp_compress(tfm, ctemplate[i].input,
> @@ -1445,7 +1445,7 @@ static int test_comp(struct crypto_comp *tfm,
> int ilen;
> unsigned int dlen = COMP_BUF_SIZE;
>
> - memset(decomp_output, 0, sizeof(COMP_BUF_SIZE));
> + memset(decomp_output, 0, COMP_BUF_SIZE);
>
> ilen = dtemplate[i].inlen;
> ret = crypto_comp_decompress(tfm, dtemplate[i].input,
> --
> 2.19.0
>

2018-10-12 06:23:10

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH] crypto/testmgr.c: fix sizeof() on COMP_BUF_SIZE

On Sun, Oct 07, 2018 at 01:58:10PM +0200, Michael Schupikov wrote:
> After allocation, output and decomp_output both point to memory chunks of
> size COMP_BUF_SIZE. Then, only the first bytes are zeroed out using
> sizeof(COMP_BUF_SIZE) as parameter to memset(), because
> sizeof(COMP_BUF_SIZE) provides the size of the constant and not the size of
> allocated memory.
>
> Instead, the whole allocated memory is meant to be zeroed out. Use
> COMP_BUF_SIZE as parameter to memset() directly in order to accomplish
> this.
>
> Fixes: 336073840a872 ("crypto: testmgr - Allow different compression results")
>
> Signed-off-by: Michael Schupikov <[email protected]>
> ---
> crypto/testmgr.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)

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