Skip to contentSkip to conversation

raw/ifpga/base: check address before assigning

PATCH Applied Wei Huang 2 participants 2 messages May 31, 2021 – Jun 1, 2021

lore
Share & tools
lore

Wei Huang

author
#0 lore raw

PATCH 1/1 raw/ifpga/base: check address before assigning

In max10_staging_area_init(), variable "start" from fdt_get_reg() may be invalid, it should be checked before assigning to member variable "staging_area_base" of structure "intel_max10_device".

Coverity issue: 367480, 367482

Fixes a05bd1b40bde ("raw/ifpga: add FPGA RSU APIs")
---
 drivers/raw/ifpga/base/opae_intel_max10.c | 14 ++++++++++----
 drivers/raw/ifpga/base/opae_intel_max10.h |  1 +
 2 files changed, 11 insertions(+), 4 deletions(-)
drivers/raw/ifpga/base/opae_intel_max10.c +10 -4
index c223faf..9d82fb0 100644
@@ -593,10 +593,16 @@ static int max10_staging_area_init(struct intel_max10_device *dev)
 			continue;
 
 		ret = fdt_get_reg(fdt_root, offset, 0, &start, &size);
-		if (!ret && (size <= MAX_STAGING_AREA_SIZE)) {
-			dev->staging_area_base = start;
-			dev->staging_area_size = size;
-		}
+		if (ret)
+			return ret;
+
+		if ((start & 0x3) || (start > MAX_STAGING_AREA_BASE) ||
+			(size > MAX_STAGING_AREA_SIZE))
+			return -EINVAL;
+
+		dev->staging_area_base = start;
+		dev->staging_area_size = size;
+
 		return ret;
 	}
 
drivers/raw/ifpga/base/opae_intel_max10.h +1 -0
index e7142d6..e761d7e 100644
@@ -182,6 +182,7 @@ struct opae_retimer_status {
 #define   SBUS_VERSION			GENMASK(31, 16)
 
 #define DFT_MAX_SIZE		0x7e0000
+#define MAX_STAGING_AREA_BASE	0xffffffff
 #define MAX_STAGING_AREA_SIZE	0x3800000
 
 int max10_reg_read(struct intel_max10_device *dev,
Signature · 1 line
1.8.3.1
Applied
#1 lore raw
Quoted 15 lines

-----Original Message-----
From: Huang, Wei <[email protected]>
Sent: Monday, May 31, 2021 1:23 PM
To: [email protected]; Xu, Rosen <[email protected]>; Zhang, Qi Z <[email protected]>
Cc: [email protected]; Zhang, Tianfei <[email protected]>; Yigit, Ferruh <[email protected]>; Huang, Wei <[email protected]>
Subject: [PATCH v1] raw/ifpga/base: check address before assigning

In max10_staging_area_init(), variable "start" from fdt_get_reg() may be invalid, it should be checked before assigning to member variable "staging_area_base" of structure "intel_max10_device".

Quoted 6 lines

Coverity issue: 367480, 367482

Fixes a05bd1b40bde ("raw/ifpga: add FPGA RSU APIs")

Applied to dpdk-next-net-intel.

Thanks
Qi