From: Alejandro Lucero Date: Fri, 12 May 2017 10:18:25 +0000 (+0100) Subject: vfio: fix array bounds check X-Git-Tag: spdx-start~3187 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=4af00fb1a2449f23a7c0fc32159207ae68b0fbbb;p=dpdk.git vfio: fix array bounds check Checking against VFIO_MAX_GROUPS goes beyond the maximum array index which should be (VFIO_MAX_GROUPS - 1). Coverity issue: 144555, 144556, 144557 Fixes: 94c0776b1bad ("support hotplug") Cc: stable@dpdk.org Signed-off-by: Alejandro Lucero Acked-by: Anatoly Burakov --- diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c index 53ac725d22..946df7e31f 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c @@ -189,7 +189,7 @@ vfio_group_device_get(int vfio_group_fd) int i; i = get_vfio_group_idx(vfio_group_fd); - if (i < 0 || i > VFIO_MAX_GROUPS) + if (i < 0 || i > (VFIO_MAX_GROUPS - 1)) RTE_LOG(ERR, EAL, " wrong vfio_group index (%d)\n", i); else vfio_cfg.vfio_groups[i].devices++; @@ -201,7 +201,7 @@ vfio_group_device_put(int vfio_group_fd) int i; i = get_vfio_group_idx(vfio_group_fd); - if (i < 0 || i > VFIO_MAX_GROUPS) + if (i < 0 || i > (VFIO_MAX_GROUPS - 1)) RTE_LOG(ERR, EAL, " wrong vfio_group index (%d)\n", i); else vfio_cfg.vfio_groups[i].devices--; @@ -213,7 +213,7 @@ vfio_group_device_count(int vfio_group_fd) int i; i = get_vfio_group_idx(vfio_group_fd); - if (i < 0 || i > VFIO_MAX_GROUPS) { + if (i < 0 || i > (VFIO_MAX_GROUPS - 1)) { RTE_LOG(ERR, EAL, " wrong vfio_group index (%d)\n", i); return -1; }