Skip to contentSkip to conversation

usb: fix potential integer overflow in usb_sg_init

PATCH In review Insu Yun 2 participants 2 messages Jan 18, 2016 USB

lore
Share & tools
lore

Insu Yun

author
#0 lore raw

PATCH 1/1 usb: fix potential integer overflow in usb_sg_init

If nents value is sufficient large, e.g 0x40000000, then it can overflow size in kmalloc and heap overflow happesns. Therefore nents value needs to be checked to prevent overflow.

---
 drivers/usb/core/message.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/core/message.c +2 -1
index 8e641b5..53393d5 100644
@@ -367,7 +367,8 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev,
 	if (!io || !dev || !sg
 			|| usb_pipecontrol(pipe)
 			|| usb_pipeisoc(pipe)
-			|| nents <= 0)
+			|| nents <= 0
+			|| nents >= UINT_MAX / sizeof(*io->urbs))
 		return -EINVAL;
 
 	spin_lock_init(&io->lock);
Signature · 1 line
1.9.1
#1 lore raw
Quoted 3 lines · Insu Yun

If nents value is sufficient large, e.g 0x40000000, then it can overflow size in kmalloc and heap overflow happesns. Therefore nents value needs to be checked to prevent overflow.

I don't see why. You seem to be assuming that failure with -EINVAL is better than failure with a heap overflow. I disagree; a heap overflow provides more debugging information to help locate the reason for the underlying problem.

Alan Stern