]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
RDMA/hns: Validate the pkey index
authorKamal Heib <kamalheib1@gmail.com>
Wed, 17 Nov 2021 14:59:54 +0000 (16:59 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 Jan 2022 07:47:35 +0000 (08:47 +0100)
[ Upstream commit 2a67fcfa0db6b4075515bd23497750849b88850f ]

Before query pkey, make sure that the queried index is valid.

Fixes: 9a4435375cd1 ("IB/hns: Add driver files for hns RoCE driver")
Link: https://lore.kernel.org/r/20211117145954.123893-1-kamalheib1@gmail.com
Signed-off-by: Kamal Heib <kamalheib1@gmail.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/infiniband/hw/hns/hns_roce_main.c

index 764e35a54457e7c0c8bfde46577df1e3962d833c..852aac146ac78f3473aa692c94473a4e62108800 100644 (file)
@@ -475,6 +475,9 @@ static int hns_roce_query_gid(struct ib_device *ib_dev, u8 port_num, int index,
 static int hns_roce_query_pkey(struct ib_device *ib_dev, u8 port, u16 index,
                               u16 *pkey)
 {
+       if (index > 0)
+               return -EINVAL;
+
        *pkey = PKEY_ID;
 
        return 0;