crypto: algif_hash - Allocate hash state with kmalloc
Allocating the hash state on the stack limits its size. Change this to use kmalloc so the limit can be removed for new drivers. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
686cd976b6
commit
acc03d8908
@ -235,24 +235,31 @@ static int hash_accept(struct socket *sock, struct socket *newsock, int flags,
|
|||||||
struct alg_sock *ask = alg_sk(sk);
|
struct alg_sock *ask = alg_sk(sk);
|
||||||
struct hash_ctx *ctx = ask->private;
|
struct hash_ctx *ctx = ask->private;
|
||||||
struct ahash_request *req = &ctx->req;
|
struct ahash_request *req = &ctx->req;
|
||||||
char state[HASH_MAX_STATESIZE];
|
struct crypto_ahash *tfm;
|
||||||
struct sock *sk2;
|
struct sock *sk2;
|
||||||
struct alg_sock *ask2;
|
struct alg_sock *ask2;
|
||||||
struct hash_ctx *ctx2;
|
struct hash_ctx *ctx2;
|
||||||
|
char *state;
|
||||||
bool more;
|
bool more;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
tfm = crypto_ahash_reqtfm(req);
|
||||||
|
state = kmalloc(crypto_ahash_statesize(tfm), GFP_KERNEL);
|
||||||
|
err = -ENOMEM;
|
||||||
|
if (!state)
|
||||||
|
goto out;
|
||||||
|
|
||||||
lock_sock(sk);
|
lock_sock(sk);
|
||||||
more = ctx->more;
|
more = ctx->more;
|
||||||
err = more ? crypto_ahash_export(req, state) : 0;
|
err = more ? crypto_ahash_export(req, state) : 0;
|
||||||
release_sock(sk);
|
release_sock(sk);
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
goto out_free_state;
|
||||||
|
|
||||||
err = af_alg_accept(ask->parent, newsock, kern);
|
err = af_alg_accept(ask->parent, newsock, kern);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
goto out_free_state;
|
||||||
|
|
||||||
sk2 = newsock->sk;
|
sk2 = newsock->sk;
|
||||||
ask2 = alg_sk(sk2);
|
ask2 = alg_sk(sk2);
|
||||||
@ -260,7 +267,7 @@ static int hash_accept(struct socket *sock, struct socket *newsock, int flags,
|
|||||||
ctx2->more = more;
|
ctx2->more = more;
|
||||||
|
|
||||||
if (!more)
|
if (!more)
|
||||||
return err;
|
goto out_free_state;
|
||||||
|
|
||||||
err = crypto_ahash_import(&ctx2->req, state);
|
err = crypto_ahash_import(&ctx2->req, state);
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -268,6 +275,10 @@ static int hash_accept(struct socket *sock, struct socket *newsock, int flags,
|
|||||||
sock_put(sk2);
|
sock_put(sk2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out_free_state:
|
||||||
|
kfree_sensitive(state);
|
||||||
|
|
||||||
|
out:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user