IB/core: Fix a potential array overrun in CMA and SA agent
authorMark Bloch <markb@mellanox.com>
Fri, 6 May 2016 19:45:26 +0000 (22:45 +0300)
committerDoug Ledford <dledford@redhat.com>
Fri, 13 May 2016 23:40:02 +0000 (19:40 -0400)
Fix array overrun when going over callback table.
In declaration of callback table, the max size isn't provided and
in registration phase, it is provided.

There is potential scenario where a new operation is added
and it is not supported by current client. The acceptance of
such operation by ib_netlink will cause to array overrun.

Fixes: 809d5fc9bf65 ("infiniband: pass rdma_cm module to netlink_dump_start")
Fixes: b493d91d333e ("iwcm: common code for port mapper")
Fixes: 2ca546b92a02 ("IB/sa: Route SA pathrecord query through netlink")
Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/core/cma.c
drivers/infiniband/core/iwcm.c
drivers/infiniband/core/sa_query.c

index 93ab0ae9720889f9cf51d6629a72469b67d646d4..b575bd5e509e7a5633dadd132e634971ed026f43 100644 (file)
@@ -4294,7 +4294,8 @@ static int __init cma_init(void)
        if (ret)
                goto err;
 
-       if (ibnl_add_client(RDMA_NL_RDMA_CM, RDMA_NL_RDMA_CM_NUM_OPS, cma_cb_table))
+       if (ibnl_add_client(RDMA_NL_RDMA_CM, ARRAY_SIZE(cma_cb_table),
+                           cma_cb_table))
                pr_warn("RDMA CMA: failed to add netlink callback\n");
        cma_configfs_init();
 
index fe0bd6c9df3d22bb8e717e3ddad7a88799057062..f0572049d291e8b862d88f5d45a63092cc61ffeb 100644 (file)
@@ -1175,7 +1175,7 @@ static int __init iw_cm_init(void)
        if (ret)
                pr_err("iw_cm: couldn't init iwpm\n");
 
-       ret = ibnl_add_client(RDMA_NL_IWCM, RDMA_NL_IWPM_NUM_OPS,
+       ret = ibnl_add_client(RDMA_NL_IWCM, ARRAY_SIZE(iwcm_nl_cb_table),
                              iwcm_nl_cb_table);
        if (ret)
                pr_err("iw_cm: couldn't register netlink callbacks\n");
index 8a09c0fb268d8d89529f0f22249422ee3fe05320..1e7c652fa8a5e421d2182949362d9bb64f4bb714 100644 (file)
@@ -1820,7 +1820,7 @@ static int __init ib_sa_init(void)
                goto err3;
        }
 
-       if (ibnl_add_client(RDMA_NL_LS, RDMA_NL_LS_NUM_OPS,
+       if (ibnl_add_client(RDMA_NL_LS, ARRAY_SIZE(ib_sa_cb_table),
                            ib_sa_cb_table)) {
                pr_err("Failed to add netlink callback\n");
                ret = -EINVAL;