ALSA: caiaq: fix usb_dev refcount leak on probe failure
Subsystems (3)
PATCH 1/1 ALSA: caiaq: fix usb_dev refcount leak on probe failure
create_card() takes a reference on the USB device with usb_get_dev() and stores the matching usb_put_dev() in card_free(), which is installed as the snd_card's ->private_free destructor.
However, ->private_free is only assigned near the end of init_card(), after several failure points (usb_set_interface(), EP type checks, usb_submit_urb(), the EP1_CMD_GET_DEVICE_INFO exchange, and its timeout). When any of those fail, init_card() returns an error to snd_probe(), which calls snd_card_free(card). Because ->private_free is still NULL, card_free() never runs, the usb_get_dev() reference is not dropped, and the struct usb_device leaks along with its descriptor allocations and device_private.
syzbot reproduces this with a malformed UAC3 device whose only valid altsetting is 0; init_card()'s usb_set_interface(usb_dev, 0, 1) call fails with -EIO and triggers the leak.
Move the ->private_free assignment into create_card(), immediately after usb_get_dev(), so that every error path reaching snd_card_free() balances the reference. card_free()'s callees (snd_usb_caiaq_input_free, free_urbs, kfree) already tolerate the partially-initialized state because the chip private area is zero-initialized by snd_card_new().
--- sound/usb/caiaq/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/usb/caiaq/device.c +1 -1
@@ -423,6 +423,7 @@ static int create_card(struct usb_device *usb_dev, cdev =caiaqdev (card); cdev->chip.dev =usb_get_dev (usb_dev); + card->private_free = card_free; cdev->chip.card = card; cdev->chip.usb_id =USB_ID (le16_to_cpu (usb_dev->descriptor.idVendor),le16_to_cpu (usb_dev->descriptor.idProduct));
@@ -511,7 +512,6 @@ static int init_card(struct snd_usb_caiaqdev *cdev)scnprintf (card->longname,sizeof (card->longname),"%s %s (%s)" , cdev->vendor_name, cdev->product_name, usbpath); - card->private_free = card_free; err =setup_card (cdev);if (err <0 )return err;
Signature · 1 line
2.43.0
Quoted 24 lines · Deepanshu Kartikey
create_card()takes a reference on the USB device withusb_get_dev()and stores the matchingusb_put_dev()incard_free(), which is installed as the snd_card's ->private_free destructor.However, ->private_free is only assigned near the end of
init_card(), after several failure points (usb_set_interface(), EP type checks,usb_submit_urb(), theEP1_CMD_GET_DEVICE_INFOexchange, and its timeout). When any of those fail,init_card()returns an error tosnd_probe(), which callssnd_card_free(card). Because ->private_free is still NULL,card_free()never runs, theusb_get_dev()reference is not dropped, and the structusb_deviceleaks along with its descriptor allocations anddevice_private.syzbot reproduces this with a malformed UAC3 device whose only valid altsetting is 0; init_card()'s
usb_set_interface(usb_dev, 0, 1)call fails with-EIOand triggers the leak.Move the ->private_free assignment into
create_card(), immediately afterusb_get_dev(), so that every error path reachingsnd_card_free()balances the reference. card_free()'s callees (snd_usb_caiaq_input_free,free_urbs, kfree) already tolerate the partially-initialized state because the chip private area is zero-initialized bysnd_card_new().
Quoted 5 lines
Reported-by [email protected]Tested-by [email protected]Signed-off-by Deepanshu Kartikey <[email protected]>
Applied now. Thanks.
Takashi