Skip to content

Commit 369a9c0

Browse files
gscuigregkh
authored andcommitted
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: 02fe26f ("firmware_loader: Add debug message with checksum for FW file") Signed-off-by: Gaosheng Cui <[email protected]> Reviewed-by: Amadeusz Sławiński <[email protected]> Reviewed-by: Russ Weight <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f841224 commit 369a9c0

File tree

1 file changed

+2
-3
lines changed
  • drivers/base/firmware_loader

1 file changed

+2
-3
lines changed

drivers/base/firmware_loader/main.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -829,19 +829,18 @@ static void fw_log_firmware_info(const struct firmware *fw, const char *name, st
829829
shash->tfm = alg;
830830

831831
if (crypto_shash_digest(shash, fw->data, fw->size, sha256buf) < 0)
832-
goto out_shash;
832+
goto out_free;
833833

834834
for (int i = 0; i < SHA256_DIGEST_SIZE; i++)
835835
sprintf(&outbuf[i * 2], "%02x", sha256buf[i]);
836836
outbuf[SHA256_BLOCK_SIZE] = 0;
837837
dev_dbg(device, "Loaded FW: %s, sha256: %s\n", name, outbuf);
838838

839-
out_shash:
840-
crypto_free_shash(alg);
841839
out_free:
842840
kfree(shash);
843841
kfree(outbuf);
844842
kfree(sha256buf);
843+
crypto_free_shash(alg);
845844
}
846845
#else
847846
static void fw_log_firmware_info(const struct firmware *fw, const char *name,

0 commit comments

Comments
 (0)