hw: rdma: fix an off-by-one issue
authorLi Qiang <liq3ea@163.com>
Thu, 3 Jan 2019 13:12:51 +0000 (05:12 -0800)
committerMarcel Apfelbaum <marcel.apfelbaum@gmail.com>
Sat, 19 Jan 2019 08:57:48 +0000 (10:57 +0200)
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

Signed-off-by: Li Qiang <liq3ea@163.com>
Message-Id: <20190103131251.49271-1-liq3ea@163.com>
Signed-off-by: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
hw/rdma/rdma_rm.c

index 8bf241e91f38bafd2e270c67d04d1a240d937efd..268ff633a48e1b67df0414761cbe67648b7573db 100644 (file)
@@ -579,7 +579,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;
     }