Skip to contentSkip to conversation

hw: rdma: fix an off-by-one issue

PATCH In review Li Qiang 2 participants 2 messages Jan 3, 2019 – Jan 7, 2019

lore
Share & tools
lore

Li Qiang

author
#0 lore raw

PATCH 1/1 hw: rdma: fix an off-by-one issue

In rdma_rm_get_backend_gid_index(), the 'sgid_idx' is used to index the array 'dev_res->port.gid_tbl' which size is MAX_PORT_GIDS. Current the 'sgid_idx' may be MAX_PORT_GIDS thus cause an off-by-one issue.

Spotted by Coverity: CID 1398594

---
 hw/rdma/rdma_rm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/rdma/rdma_rm.c +1 -1
index f5b1295890..1bbc5f128f 100644
@@ -576,7 +576,7 @@ int rdma_rm_del_gid(RdmaDeviceResources *dev_res, RdmaBackendDev *backend_dev,
 int rdma_rm_get_backend_gid_index(RdmaDeviceResources *dev_res,
                                   RdmaBackendDev *backend_dev, int sgid_idx)
 {
-    if (unlikely(sgid_idx < 0 || sgid_idx > MAX_PORT_GIDS)) {
+    if (unlikely(sgid_idx < 0 || sgid_idx >= MAX_PORT_GIDS)) {
         pr_dbg("Got invalid sgid_idx %d\n", sgid_idx);
         return -EINVAL;
     }
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Li Qiang

In rdma_rm_get_backend_gid_index(), the 'sgid_idx' is used to index the array 'dev_res->port.gid_tbl' which size is MAX_PORT_GIDS. Current the 'sgid_idx' may be MAX_PORT_GIDS thus cause an off-by-one issue.

Spotted by Coverity: CID 1398594

---
  hw/rdma/rdma_rm.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/rdma/rdma_rm.c +0 -0
index f5b1295890..1bbc5f128f 100644

hw/rdma/rdma_rm.c int rdma_rm_del_gid(RdmaDeviceResources *dev_res, RdmaBackendDev *backend_dev, · line 582

Quoted 8 lines
hw/rdma/rdma_rm.c +1 -1
@@ -576,7 +576,7 @@ int rdma_rm_del_gid(RdmaDeviceResources *dev_res, RdmaBackendDev *backend_dev,
  int rdma_rm_get_backend_gid_index(RdmaDeviceResources *dev_res,
                                    RdmaBackendDev *backend_dev, int sgid_idx)
  {
-    if (unlikely(sgid_idx < 0 || sgid_idx > MAX_PORT_GIDS)) {
+    if (unlikely(sgid_idx < 0 || sgid_idx >= MAX_PORT_GIDS)) {
          pr_dbg("Got invalid sgid_idx %d\n", sgid_idx);
          return -EINVAL;
      }

Thanks,
Marcel