From: Jie Liu <[email protected]>
sxe2_dev_pci_res_seg_map() indexes adapter->map_ctxt.addr_info[] with
res_type without bounds checking, which can access out of bounds when
an invalid resource type is passed.
Add a bounds check on res_type and return -EINVAL.
Fixes: 66a10eb60e ("net/sxe2: add PCI BAR mapping")
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Jie Liu <[email protected]>
---
drivers/net/sxe2/sxe2_ethdev.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/net/sxe2/sxe2_ethdev.c b/drivers/net/sxe2/sxe2_ethdev.c
index 09f5daa715..f76d4db6f7 100644
--- a/drivers/net/sxe2/sxe2_ethdev.c
+++ b/drivers/net/sxe2/sxe2_ethdev.c
@@ -1556,6 +1556,12 @@ int32_t sxe2_dev_pci_res_seg_map(struct sxe2_adapter
*adapter,
struct sxe2_pci_map_addr_info *addr_info = NULL;
int32_t ret = 0;
+ if (unlikely(res_type >= SXE2_PCI_MAP_RES_MAX_COUNT)) {
+ PMD_DEV_LOG_ERR(adapter, INIT, "Invalid resource type %u",
res_type);
+ ret = -EINVAL;
+ goto l_end;
+ }
+
addr_info = &adapter->map_ctxt.addr_info[res_type];
if (!addr_info || addr_info->bar_idx == SXE2_PCI_MAP_BAR_INVALID) {
PMD_DEV_LOG_ERR(adapter, INIT, "Invalid bar index with resource
type %d", res_type);
--
2.52.0