[PATCH] ubifs: Allocate shash export state on stack
Zhihao Cheng
chengzhihao1 at huawei.com
Thu Jun 19 23:31:34 PDT 2025
在 2025/6/20 11:45, Herbert Xu 写道:
> 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>
>
Reviewed-by: Zhihao Cheng <chengzhihao1 at huawei.com>
Maybe adding a fix tag is better, commit 49525e5eecca5e1("ubifs: Add
helper functions for authentication support").
> 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;
> }
>
>
More information about the linux-mtd
mailing list