[PATCH] ubifs: Allocate shash export state on stack
Herbert Xu
herbert at gondor.apana.org.au
Thu Jun 19 20:45:05 PDT 2025
The output size of crypto_shash_export should be obtained via
crypto_shash_statesize and not crypto_shash_descsize. The latter
could be too small (but is usually big enough).
However, as state sizes are API-limited, simply allocate it on the
stack.
Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au>
diff --git a/fs/ubifs/auth.c b/fs/ubifs/auth.c
index a4a0158f712d..edf012aa51bf 100644
--- a/fs/ubifs/auth.c
+++ b/fs/ubifs/auth.c
@@ -474,13 +474,9 @@ int __ubifs_node_verify_hmac(const struct ubifs_info *c, const void *node,
int __ubifs_shash_copy_state(const struct ubifs_info *c, struct shash_desc *src,
struct shash_desc *target)
{
- u8 *state;
+ u8 state[HASH_MAX_STATESIZE];
int err;
- state = kmalloc(crypto_shash_descsize(src->tfm), GFP_NOFS);
- if (!state)
- return -ENOMEM;
-
err = crypto_shash_export(src, state);
if (err)
goto out;
@@ -488,8 +484,6 @@ int __ubifs_shash_copy_state(const struct ubifs_info *c, struct shash_desc *src,
err = crypto_shash_import(target, state);
out:
- kfree(state);
-
return err;
}
--
Email: Herbert Xu <herbert at gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
More information about the linux-mtd
mailing list