Skip to content

Commit bce382a

Browse files
ofirbittogabbay
authored andcommitted
habanalabs: validate FW file size
We must validate FW size in order not to corrupt memory in case a malicious FW file will be present in system. Signed-off-by: Ofir Bitton <[email protected]> Signed-off-by: Oded Gabbay <[email protected]>
1 parent 804d057 commit bce382a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/misc/habanalabs/common/firmware_if.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/io-64-nonatomic-lo-hi.h>
1414
#include <linux/slab.h>
1515

16+
#define FW_FILE_MAX_SIZE 0x1400000 /* maximum size of 20MB */
1617
/**
1718
* hl_fw_load_fw_to_device() - Load F/W code to device's memory.
1819
*
@@ -48,6 +49,14 @@ int hl_fw_load_fw_to_device(struct hl_device *hdev, const char *fw_name,
4849

4950
dev_dbg(hdev->dev, "%s firmware size == %zu\n", fw_name, fw_size);
5051

52+
if (fw_size > FW_FILE_MAX_SIZE) {
53+
dev_err(hdev->dev,
54+
"FW file size %zu exceeds maximum of %u bytes\n",
55+
fw_size, FW_FILE_MAX_SIZE);
56+
rc = -EINVAL;
57+
goto out;
58+
}
59+
5160
fw_data = (const u64 *) fw->data;
5261

5362
memcpy_toio(dst, fw_data, fw_size);

0 commit comments

Comments
 (0)