raw/ifpga/base: check size before assigning
authorWei Huang <wei.huang@intel.com>
Thu, 8 Apr 2021 08:51:51 +0000 (04:51 -0400)
committerQi Zhang <qi.z.zhang@intel.com>
Mon, 19 Apr 2021 08:13:27 +0000 (10:13 +0200)
In max10_staging_area_init(), variable "size" from fdt_get_reg() may
be invalid, it should be checked before assigning to member variable
"staging_area_size" of structure "intel_max10_device".

Coverity issue: 367480, 367482
Fixes: 96ebfcf8125c ("raw/ifpga/base: add SPI and MAX10 device driver")
Cc: stable@dpdk.org
Signed-off-by: Wei Huang <wei.huang@intel.com>
Acked-by: Tianfei Zhang <tianfei.zhang@intel.com>
drivers/raw/ifpga/base/opae_intel_max10.c
drivers/raw/ifpga/base/opae_intel_max10.h

index 443e248..c223faf 100644 (file)
@@ -593,7 +593,7 @@ static int max10_staging_area_init(struct intel_max10_device *dev)
                        continue;
 
                ret = fdt_get_reg(fdt_root, offset, 0, &start, &size);
-               if (!ret) {
+               if (!ret && (size <= MAX_STAGING_AREA_SIZE)) {
                        dev->staging_area_base = start;
                        dev->staging_area_size = size;
                }
index 670683f..e7142d6 100644 (file)
@@ -182,6 +182,7 @@ struct opae_retimer_status {
 #define   SBUS_VERSION                 GENMASK(31, 16)
 
 #define DFT_MAX_SIZE           0x7e0000
+#define MAX_STAGING_AREA_SIZE  0x3800000
 
 int max10_reg_read(struct intel_max10_device *dev,
        unsigned int reg, unsigned int *val);