Skip to content

Commit 990b1e3

Browse files
committed
accel/ivpu: Limit FW version string length
Limit FW version string, when parsing FW binary, to 256 bytes and always add NULL-terminate it. Reviewed-by: Karol Wachowski <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Jacek Lawrynowicz <[email protected]>
1 parent 4bc988b commit 990b1e3

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

drivers/accel/ivpu/ivpu_fw.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#define FW_SHAVE_NN_MAX_SIZE SZ_2M
2626
#define FW_RUNTIME_MIN_ADDR (FW_GLOBAL_MEM_START)
2727
#define FW_RUNTIME_MAX_ADDR (FW_GLOBAL_MEM_END - FW_SHARED_MEM_SIZE)
28-
#define FW_VERSION_HEADER_SIZE SZ_4K
2928
#define FW_FILE_IMAGE_OFFSET (VPU_FW_HEADER_SIZE + FW_VERSION_HEADER_SIZE)
3029

3130
#define WATCHDOG_MSS_REDIRECT 32
@@ -191,8 +190,10 @@ static int ivpu_fw_parse(struct ivpu_device *vdev)
191190
ivpu_dbg(vdev, FW_BOOT, "Header version: 0x%x, format 0x%x\n",
192191
fw_hdr->header_version, fw_hdr->image_format);
193192

194-
ivpu_info(vdev, "Firmware: %s, version: %s", fw->name,
195-
(const char *)fw_hdr + VPU_FW_HEADER_SIZE);
193+
if (!scnprintf(fw->version, sizeof(fw->version), "%s", fw->file->data + VPU_FW_HEADER_SIZE))
194+
ivpu_warn(vdev, "Missing firmware version\n");
195+
196+
ivpu_info(vdev, "Firmware: %s, version: %s\n", fw->name, fw->version);
196197

197198
if (IVPU_FW_CHECK_API_COMPAT(vdev, fw_hdr, BOOT, 3))
198199
return -EINVAL;

drivers/accel/ivpu/ivpu_fw.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
/* SPDX-License-Identifier: GPL-2.0-only */
22
/*
3-
* Copyright (C) 2020-2023 Intel Corporation
3+
* Copyright (C) 2020-2024 Intel Corporation
44
*/
55

66
#ifndef __IVPU_FW_H__
77
#define __IVPU_FW_H__
88

9+
#define FW_VERSION_HEADER_SIZE SZ_4K
10+
#define FW_VERSION_STR_SIZE SZ_256
11+
912
struct ivpu_device;
1013
struct ivpu_bo;
1114
struct vpu_boot_params;
1215

1316
struct ivpu_fw_info {
1417
const struct firmware *file;
1518
const char *name;
19+
char version[FW_VERSION_STR_SIZE];
1620
struct ivpu_bo *mem;
1721
struct ivpu_bo *mem_shave_nn;
1822
struct ivpu_bo *mem_log_crit;

0 commit comments

Comments
 (0)