From: Michael J. Ruhl Date: Sun, 9 Apr 2017 17:15:51 +0000 (-0700) Subject: IB/core: For multicast functions, verify that LIDs are multicast LIDs X-Git-Tag: v4.1.12-124.31.3~515 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=18874f887965aca155216cccc74fbd148fa350bd;p=users%2Fjedix%2Flinux-maple.git IB/core: For multicast functions, verify that LIDs are multicast LIDs The Infiniband spec defines "A multicast address is defined by a MGID and a MLID" (section 10.5). Currently the MLID value is not validated. Add check to verify that the MLID value is in the correct address range. Fixes: 0c33aeedb2cf ("[IB] Add checks to multicast attach and detach") Cc: stable@vger.kernel.org Reviewed-by: Ira Weiny Reviewed-by: Dasaratharaman Chandramouli Signed-off-by: Michael J. Ruhl Signed-off-by: Dennis Dalessandro Reviewed-by: Leon Romanovsky Signed-off-by: Doug Ledford (cherry picked from commit 8561eae60ff9417a50fa1fb2b83ae950dc5c1e21) The reason for applying this patch is a bug in ibacm, which goes undetected without this patch. For further information, see https://patchwork.kernel.org/patch/10008461/ Signed-off-by: Brian Maly Conflicts: * Had to add the define IB_MULTICAST_LID_BASE in include/rdma/ib_verbs.h, due to missing commit b4e64397dabc ("IB/rdmavt: Break rdma_vt main include header file up"). Orabug: 28700490 Signed-off-by: HÃ¥kon Bugge Reviewed-by: Shannon Nelson --- v2 -> v3: * Added Shannon's r-b v1 -> v2: * Adding IB_MULTICAST_LID_BASE to ib_verbs.h * A little more verbose commit message Signed-off-by: Brian Maly --- diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c index dbc1afff750e..b48755ba5615 100644 --- a/drivers/infiniband/core/verbs.c +++ b/drivers/infiniband/core/verbs.c @@ -1417,7 +1417,9 @@ int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid) if (!qp->device->attach_mcast) return -ENOSYS; - if (gid->raw[0] != 0xff || qp->qp_type != IB_QPT_UD) + if (gid->raw[0] != 0xff || qp->qp_type != IB_QPT_UD || + lid < be16_to_cpu(IB_MULTICAST_LID_BASE) || + lid == be16_to_cpu(IB_LID_PERMISSIVE)) return -EINVAL; ret = qp->device->attach_mcast(qp, gid, lid); @@ -1433,7 +1435,9 @@ int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid) if (!qp->device->detach_mcast) return -ENOSYS; - if (gid->raw[0] != 0xff || qp->qp_type != IB_QPT_UD) + if (gid->raw[0] != 0xff || qp->qp_type != IB_QPT_UD || + lid < be16_to_cpu(IB_MULTICAST_LID_BASE) || + lid == be16_to_cpu(IB_LID_PERMISSIVE)) return -EINVAL; ret = qp->device->detach_mcast(qp, gid, lid); diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index 44c758cf8f5b..9517c614bb8f 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -469,6 +469,7 @@ enum { }; #define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF) +#define IB_MULTICAST_LID_BASE cpu_to_be16(0xC000) enum ib_ah_flags { IB_AH_GRH = 1