firmware_loader: Fix possible resource leak in fw_log_firmware_info()
The alg instance should be released under the exception path, otherwise
there may be resource leak here.
To mitigate this, free the alg instance with crypto_free_shash when kmalloc
fails.
Fixes: 02fe26f253 ("firmware_loader: Add debug message with checksum for FW file")
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
Reviewed-by: Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com>
Reviewed-by: Russ Weight <russ.weight@linux.dev>
Link: https://lore.kernel.org/r/20241016110335.3677924-1-cuigaosheng1@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
f841224f03
commit
369a9c046c
@@ -829,19 +829,18 @@ static void fw_log_firmware_info(const struct firmware *fw, const char *name, st
|
|||||||
shash->tfm = alg;
|
shash->tfm = alg;
|
||||||
|
|
||||||
if (crypto_shash_digest(shash, fw->data, fw->size, sha256buf) < 0)
|
if (crypto_shash_digest(shash, fw->data, fw->size, sha256buf) < 0)
|
||||||
goto out_shash;
|
goto out_free;
|
||||||
|
|
||||||
for (int i = 0; i < SHA256_DIGEST_SIZE; i++)
|
for (int i = 0; i < SHA256_DIGEST_SIZE; i++)
|
||||||
sprintf(&outbuf[i * 2], "%02x", sha256buf[i]);
|
sprintf(&outbuf[i * 2], "%02x", sha256buf[i]);
|
||||||
outbuf[SHA256_BLOCK_SIZE] = 0;
|
outbuf[SHA256_BLOCK_SIZE] = 0;
|
||||||
dev_dbg(device, "Loaded FW: %s, sha256: %s\n", name, outbuf);
|
dev_dbg(device, "Loaded FW: %s, sha256: %s\n", name, outbuf);
|
||||||
|
|
||||||
out_shash:
|
|
||||||
crypto_free_shash(alg);
|
|
||||||
out_free:
|
out_free:
|
||||||
kfree(shash);
|
kfree(shash);
|
||||||
kfree(outbuf);
|
kfree(outbuf);
|
||||||
kfree(sha256buf);
|
kfree(sha256buf);
|
||||||
|
crypto_free_shash(alg);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static void fw_log_firmware_info(const struct firmware *fw, const char *name,
|
static void fw_log_firmware_info(const struct firmware *fw, const char *name,
|
||||||
|
|||||||
Reference in New Issue
Block a user