Skip to content

Commit

Permalink
crypto: algif_hash - Allocate hash state with kmalloc
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
herbertx committed Apr 6, 2023
1 parent 686cd97 commit acc03d8
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions crypto/algif_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,39 +235,50 @@ 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[HASH_MAX_STATESIZE];
struct crypto_ahash *tfm;
struct sock *sk2;
struct alg_sock *ask2;
struct hash_ctx *ctx2;
char *state;
bool more;
int err;

tfm = crypto_ahash_reqtfm(req);
state = kmalloc(crypto_ahash_statesize(tfm), GFP_KERNEL);
err = -ENOMEM;
if (!state)
goto out;

lock_sock(sk);
more = ctx->more;
err = more ? crypto_ahash_export(req, state) : 0;
release_sock(sk);

if (err)
return err;
goto out_free_state;

err = af_alg_accept(ask->parent, newsock, kern);
if (err)
return err;
goto out_free_state;

sk2 = newsock->sk;
ask2 = alg_sk(sk2);
ctx2 = ask2->private;
ctx2->more = more;

if (!more)
return err;
goto out_free_state;

err = crypto_ahash_import(&ctx2->req, state);
if (err) {
sock_orphan(sk2);
sock_put(sk2);
}

out_free_state:
kfree_sensitive(state);

out:
return err;
}

Expand Down

0 comments on commit acc03d8

Please sign in to comment.