linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] ALSA: usx2y: fix a double free bug
@ 2019-04-29 17:45 Wenwen Wang
  2019-04-29 17:57 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Wenwen Wang @ 2019-04-29 17:45 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Jaroslav Kysela, Takashi Iwai, Kees Cook, moderated list:SOUND,
	open list

In usX2Y_In04_init(), a new urb is firstly created through usb_alloc_urb()
and saved to 'usX2Y->In04urb'. Then, a buffer is allocated through
kmalloc() and saved to 'usX2Y->In04Buf'. If the allocation of the buffer
fails, the error code ENOMEM is returned after usb_free_urb(), which frees
the created urb. However, the urb is actually freed at card->private_free
callback, i.e., snd_usX2Y_card_private_free(). So the free operation here
leads to a double free bug.

To fix the above issue, simply remove usb_free_urb().

Signed-off-by: Wenwen Wang <wang6495@umn.edu>
---
 sound/usb/usx2y/usbusx2y.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/sound/usb/usx2y/usbusx2y.c b/sound/usb/usx2y/usbusx2y.c
index da4a5a5..1f0b0100 100644
--- a/sound/usb/usx2y/usbusx2y.c
+++ b/sound/usb/usx2y/usbusx2y.c
@@ -293,10 +293,8 @@ int usX2Y_In04_init(struct usX2Ydev *usX2Y)
 	if (! (usX2Y->In04urb = usb_alloc_urb(0, GFP_KERNEL)))
 		return -ENOMEM;
 
-	if (! (usX2Y->In04Buf = kmalloc(21, GFP_KERNEL))) {
-		usb_free_urb(usX2Y->In04urb);
+	if (! (usX2Y->In04Buf = kmalloc(21, GFP_KERNEL)))
 		return -ENOMEM;
-	}
 	 
 	init_waitqueue_head(&usX2Y->In04WaitQueue);
 	usb_fill_int_urb(usX2Y->In04urb, usX2Y->dev, usb_rcvintpipe(usX2Y->dev, 0x4),
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] ALSA: usx2y: fix a double free bug
  2019-04-29 17:45 [PATCH v2] ALSA: usx2y: fix a double free bug Wenwen Wang
@ 2019-04-29 17:57 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2019-04-29 17:57 UTC (permalink / raw)
  To: Wenwen Wang; +Cc: moderated list:SOUND, Kees Cook, Jaroslav Kysela, open list

On Mon, 29 Apr 2019 19:45:40 +0200,
Wenwen Wang wrote:
> 
> In usX2Y_In04_init(), a new urb is firstly created through usb_alloc_urb()
> and saved to 'usX2Y->In04urb'. Then, a buffer is allocated through
> kmalloc() and saved to 'usX2Y->In04Buf'. If the allocation of the buffer
> fails, the error code ENOMEM is returned after usb_free_urb(), which frees
> the created urb. However, the urb is actually freed at card->private_free
> callback, i.e., snd_usX2Y_card_private_free(). So the free operation here
> leads to a double free bug.
> 
> To fix the above issue, simply remove usb_free_urb().
> 
> Signed-off-by: Wenwen Wang <wang6495@umn.edu>

Applied now.  Thanks.


Takashi

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-04-29 17:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-29 17:45 [PATCH v2] ALSA: usx2y: fix a double free bug Wenwen Wang
2019-04-29 17:57 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).