Skip to contentSkip to conversation

RDMA/hfi1: Use struct_size() and flex_array_size() helpers

PATCH Applied Gustavo A. R. Silva 2 participants 3 messages Sep 27, 2021

Subsystems (2)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RDMA/hfi1: Use struct_size() and flex_array_size() helpers

Make use of the struct_size() and flex_array_size() helpers instead of open-coded versions, in order to avoid any potential type mistakes or integer overflows that, in the worse scenario, could lead to heap overflows.

---
 drivers/infiniband/hw/hfi1/user_exp_rcv.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/infiniband/hw/hfi1/user_exp_rcv.c +2 -3
index 0c86e9d354f8..186d30291260 100644
@@ -692,8 +692,7 @@ static int set_rcvarray_entry(struct hfi1_filedata *fd,
 	 * Allocate the node first so we can handle a potential
 	 * failure before we've programmed anything.
 	 */
-	node = kzalloc(sizeof(*node) + (sizeof(struct page *) * npages),
-		       GFP_KERNEL);
+	node = kzalloc(struct_size(node, pages, npages), GFP_KERNEL);
 	if (!node)
 		return -ENOMEM;
 
@@ -713,7 +712,7 @@ static int set_rcvarray_entry(struct hfi1_filedata *fd,
 	node->dma_addr = phys;
 	node->grp = grp;
 	node->freed = false;
-	memcpy(node->pages, pages, sizeof(struct page *) * npages);
+	memcpy(node->pages, pages, flex_array_size(node, pages, npages));
 
 	if (fd->use_mn) {
 		ret = mmu_interval_notifier_insert(
Signature · 1 line
2.27.0
maintainer Applied
#1 lore raw
Quoted 10 lines · Gustavo A. R. Silva

Make use of the struct_size() and flex_array_size() helpers instead of open-coded versions, in order to avoid any potential type mistakes or integer overflows that, in the worse scenario, could lead to heap overflows.

---
 drivers/infiniband/hw/hfi1/user_exp_rcv.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Applied to for-next, thanks

Jason

#2 lore raw
Quoted 2 lines · Jason Gunthorpe

Applied to for-next, thanks

Thanks, Jason.
--
Gustavo