Skip to contentSkip to conversation

rsxx: Use struct_size() in vmalloc()

PATCH Applied Gustavo A. R. Silva 3 participants 3 messages May 13, 2021 – May 15, 2021 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rsxx: Use struct_size() in vmalloc()

Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows.

This code was detected with the help of Coccinelle and, audited and fixed manually.

---
 drivers/block/rsxx/dma.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/block/rsxx/dma.c +2 -4
index 0574f4495755..ed182f3dd054 100644
@@ -74,9 +74,6 @@ struct dma_tracker {
 	struct rsxx_dma	*dma;
 };
 
-#define DMA_TRACKER_LIST_SIZE8 (sizeof(struct dma_tracker_list) + \
-		(sizeof(struct dma_tracker) * RSXX_MAX_OUTSTANDING_CMDS))
-
 struct dma_tracker_list {
 	spinlock_t		lock;
 	int			head;
@@ -808,7 +805,8 @@ static int rsxx_dma_ctrl_init(struct pci_dev *dev,
 
 	memset(&ctrl->stats, 0, sizeof(ctrl->stats));
 
-	ctrl->trackers = vmalloc(DMA_TRACKER_LIST_SIZE8);
+	ctrl->trackers = vmalloc(struct_size(ctrl->trackers, list,
+					     RSXX_MAX_OUTSTANDING_CMDS));
 	if (!ctrl->trackers)
 		return -ENOMEM;
 
Signature · 1 line
2.27.0
maintainer Applied
#1 lore raw
Quoted 6 lines · Gustavo A. R. Silva

Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows.

This code was detected with the help of Coccinelle and, audited and fixed manually.

Applied, thanks.

Signature · 1 line
Jens Axboe