2016-02-23 17:02:09

by Sasha Levin

[permalink] [raw]
Subject: [PATCH] crypto: algif_hash - correctly handle algos without state

Algorithms without state will cause the creation of a 0 sized array, which
is undefined outside of structs.

Signed-off-by: Sasha Levin <[email protected]>
---
crypto/algif_hash.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/algif_hash.c b/crypto/algif_hash.c
index 68a5cea..a9f923f 100644
--- a/crypto/algif_hash.c
+++ b/crypto/algif_hash.c
@@ -184,7 +184,7 @@ static int hash_accept(struct socket *sock, struct socket *newsock, int flags)
struct alg_sock *ask = alg_sk(sk);
struct hash_ctx *ctx = ask->private;
struct ahash_request *req = &ctx->req;
- char state[crypto_ahash_statesize(crypto_ahash_reqtfm(req))];
+ char state[crypto_ahash_statesize(crypto_ahash_reqtfm(req))?:1];
struct sock *sk2;
struct alg_sock *ask2;
struct hash_ctx *ctx2;
--
1.7.10.4


2016-02-27 17:10:49

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH] crypto: algif_hash - correctly handle algos without state

On Tue, Feb 23, 2016 at 12:01:56PM -0500, Sasha Levin wrote:
> Algorithms without state will cause the creation of a 0 sized array, which
> is undefined outside of structs.
>
> Signed-off-by: Sasha Levin <[email protected]>

Actually the state size should never be zero and we check it upon
algorithm registration, so how can this possibly happen?

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