RDMA/hns: Fix memory corruption when allocating XRCDN
Subsystems (2)
PATCH v2 1/1 RDMA/hns: Fix memory corruption when allocating XRCDN
It's incorrect to cast the type of pointer to xrcdn from (u32 *) to (unsigned long *), then pass it into hns_roce_bitmap_alloc(), this will lead to a memory corruption.
---
Changes since v1:
- xrcdn won't be set if hns_roce_bitmap_alloc() fails.
- Link: https://patchwork.kernel.org/project/linux-rdma/patch/[email protected]/
drivers/infiniband/hw/hns/hns_roce_pd.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/infiniband/hw/hns/hns_roce_pd.c +10 -2
@@ -140,8 +140,16 @@ void hns_roce_cleanup_uar_table(struct hns_roce_dev *hr_dev)static int hns_roce_xrcd_alloc (struct hns_roce_dev *hr_dev,u32 *xrcdn) { -return hns_roce_bitmap_alloc (&hr_dev->xrcd_bitmap, - (unsigned long *)xrcdn); +unsigned long obj; +int ret; + + ret =hns_roce_bitmap_alloc (&hr_dev->xrcd_bitmap, &obj); +if (ret) +return ret; + + *xrcdn = (u32 )obj; + +return 0 ; } static void hns_roce_xrcd_free(struct hns_roce_dev *hr_dev,
Signature · 1 line
2.8.1
Quoted 7 lines · Weihang Li
It's incorrect to cast the type of pointer to xrcdn from (u32 *) to (unsigned long *), then pass it into
hns_roce_bitmap_alloc(), this will lead to a memory corruption.Fixes 32548870d438 ("RDMA/hns: Add support for XRC on HIP09")Reported-by Dan Carpenter <[email protected]>Signed-off-by Weihang Li <[email protected]>
Quoted 8 lines
---
Changes since v1:
- xrcdn won't be set ifhns_roce_bitmap_alloc()fails.
- Link: https://patchwork.kernel.org/project/linux-rdma/patch/[email protected]/drivers/infiniband/hw/hns/hns_roce_pd.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
Thanks,
Quoted 8 lines · Weihang Li
It's incorrect to cast the type of pointer to xrcdn from (u32 *) to (unsigned long *), then pass it into
hns_roce_bitmap_alloc(), this will lead to a memory corruption.Fixes 32548870d438 ("RDMA/hns: Add support for XRC on HIP09")Reported-by Dan Carpenter <[email protected]>Signed-off-by Weihang Li <[email protected]>Reviewed-by Leon Romanovsky <[email protected]>
Quoted 7 lines
---
Changes since v1:
- xrcdn won't be set ifhns_roce_bitmap_alloc()fails.
- Link: https://patchwork.kernel.org/project/linux-rdma/patch/[email protected]/drivers/infiniband/hw/hns/hns_roce_pd.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
Applied to for-next
Quoted 8 lines
drivers/infiniband/hw/hns/hns_roce_pd.c +0
-0@@ -140,8 +140,16 @@ void hns_roce_cleanup_uar_table(struct hns_roce_dev *hr_dev)static int hns_roce_xrcd_alloc (struct hns_roce_dev *hr_dev,u32 *xrcdn) {
drivers/infiniband/hw/hns/hns_roce_pd.c void hns_roce_cleanup_uar_table(struct hns_roce_dev *hr_dev) · line 150
Quoted 10 lines
drivers/infiniband/hw/hns/hns_roce_pd.c +8
-2-return hns_roce_bitmap_alloc (&hr_dev->xrcd_bitmap, - (unsigned long *)xrcdn); +unsigned long obj; +int ret; + + ret =hns_roce_bitmap_alloc (&hr_dev->xrcd_bitmap, &obj); +if (ret) +return ret; + + *xrcdn = (u32 )obj;
Though this cast is useless, I removed it
Thanks,
Jason