Skip to contentSkip to conversation

RDMA/mthca: Fix off-by-one in mthca_map_user_db()

PATCH Applied Serhat Kumral 4 participants 4 messages Oct 23 – Nov 3 InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RDMA/mthca: Fix off-by-one in mthca_map_user_db()

db_tab->page[] has uarc_size / MTHCA_ICM_PAGE_SIZE elements, so valid doorbell indices are in the range [0, uarc_size / 8 - 1]. Allowing index == uarc_size / 8 results in an out-of-bounds access at db_tab->page[npages]. Use '>=' instead of '>' in the bounds check.

Fixes 56483ec1b702 ("[PATCH] IB uverbs: add mthca user doorbell record support")
---
 drivers/infiniband/hw/mthca/mthca_memfree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/mthca/mthca_memfree.c +1 -1
index 9c5eb03f354d..39d82dc73807 100644
@@ -453,7 +453,7 @@ int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
 	if (!mthca_is_memfree(dev))
 		return 0;
 
-	if (index < 0 || index > dev->uar_table.uarc_size / 8)
+	if (index < 0 || index >= dev->uar_table.uarc_size / 8)
 		return -EINVAL;
 
 	mutex_lock(&db_tab->mutex);
Signature · 1 line
2.53.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

db_tab->page[] has uarc_size / MTHCA_ICM_PAGE_SIZE elements, so valid doorbell indices are in the range [0, uarc_size / 8 - 1]. Allowing index == uarc_size / 8 results in an out-of-bounds access at db_tab->page[npages]. Use '>=' instead of '>' in the bounds check.

Fixes 56483ec1b702 ("[PATCH] IB uverbs: add mthca user doorbell record support")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v1 1/1
#2 lore raw
In reply to Serhat Kumral
Quoted 27 lines · Serhat Kumral

db_tab->page[] has uarc_size / MTHCA_ICM_PAGE_SIZE elements, so valid doorbell indices are in the range [0, uarc_size / 8 - 1]. Allowing index == uarc_size / 8 results in an out-of-bounds access at db_tab->page[npages]. Use '>=' instead of '>' in the bounds check.

Fixes 56483ec1b702 ("[PATCH] IB uverbs: add mthca user doorbell record support")
---
 drivers/infiniband/hw/mthca/mthca_memfree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/mthca/mthca_memfree.c +1 -1
index 9c5eb03f354d..39d82dc73807 100644
@@ -453,7 +453,7 @@ int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
 	if (!mthca_is_memfree(dev))
 		return 0;
 
-	if (index < 0 || index > dev->uar_table.uarc_size / 8)
+	if (index < 0 || index >= dev->uar_table.uarc_size / 8)
 		return -EINVAL;
 
 	mutex_lock(&db_tab->mutex);
Signature · 1 line
2.53.0

LGTM

Thanks
Chenguang

#3 lore raw
In reply to Serhat Kumral
Quoted 4 lines · Serhat Kumral

db_tab->page[] has uarc_size / MTHCA_ICM_PAGE_SIZE elements, so valid doorbell indices are in the range [0, uarc_size / 8 - 1]. Allowing index == uarc_size / 8 results in an out-of-bounds access at db_tab->page[npages]. Use '>=' instead of '>' in the bounds check.

Applied, thanks!

[1/1] RDMA/mthca: Fix off-by-one in mthca_map_user_db()

      https://git.kernel.org/rdma/rdma/c/0246639e79a413

Best regards,

Signature · 1 line
Leon Romanovsky <[email protected]>