Skip to contentSkip to conversation

driver: floppy: fix warning in __alloc_pages

PATCH New Dongliang Mu 1 participant 1 message Oct 12, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 driver: floppy: fix warning in __alloc_pages

If the user-provided length (ptr->length) is longer than one threshold, it will trigger a warning in __alloc_pages.

Fix this by checking get_order(ptr->length) >= MAX_ORDER.

---
 drivers/block/floppy.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/block/floppy.c +2 -0
index fef79ea52e3e..8b88960e2784 100644
@@ -3109,6 +3109,8 @@ static int raw_cmd_copyin(int cmd, void __user *param,
 	if (ptr->flags & (FD_RAW_READ | FD_RAW_WRITE)) {
 		if (ptr->length <= 0)
 			return -EINVAL;
+		if (get_order(ptr->length) >= MAX_ORDER)
+			return -EINVAL;
 		ptr->kernel_data = (char *)fd_dma_mem_alloc(ptr->length);
 		fallback_on_nodma_alloc(&ptr->kernel_data, ptr->length);
 		if (!ptr->kernel_data)
Signature · 1 line
2.25.1