Commit 990b1e3d authored by Jacek Lawrynowicz's avatar Jacek Lawrynowicz
Browse files

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: default avatarKarol Wachowski <karol.wachowski@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240930195322.461209-7-jacek.lawrynowicz@linux.intel.com


Signed-off-by: default avatarJacek Lawrynowicz <jacek.lawrynowicz@linux.intel.com>
parent 4bc988b4
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@
#define FW_SHAVE_NN_MAX_SIZE	SZ_2M
#define FW_RUNTIME_MIN_ADDR	(FW_GLOBAL_MEM_START)
#define FW_RUNTIME_MAX_ADDR	(FW_GLOBAL_MEM_END - FW_SHARED_MEM_SIZE)
#define FW_VERSION_HEADER_SIZE	SZ_4K
#define FW_FILE_IMAGE_OFFSET	(VPU_FW_HEADER_SIZE + FW_VERSION_HEADER_SIZE)

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

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

	ivpu_info(vdev, "Firmware: %s, version: %s\n", fw->name, fw->version);

	if (IVPU_FW_CHECK_API_COMPAT(vdev, fw_hdr, BOOT, 3))
		return -EINVAL;
+5 −1
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (C) 2020-2023 Intel Corporation
 * Copyright (C) 2020-2024 Intel Corporation
 */

#ifndef __IVPU_FW_H__
#define __IVPU_FW_H__

#define FW_VERSION_HEADER_SIZE	SZ_4K
#define FW_VERSION_STR_SIZE	SZ_256

struct ivpu_device;
struct ivpu_bo;
struct vpu_boot_params;
@@ -13,6 +16,7 @@ struct vpu_boot_params;
struct ivpu_fw_info {
	const struct firmware *file;
	const char *name;
	char version[FW_VERSION_STR_SIZE];
	struct ivpu_bo *mem;
	struct ivpu_bo *mem_shave_nn;
	struct ivpu_bo *mem_log_crit;