diff mbox

sound/usb: Fix memory leak in media_snd_stream_delete() during unbind

Message ID 1458183486-8113-1-git-send-email-shuahkh@osg.samsung.com (mailing list archive)
State New, archived
Headers show

Commit Message

Shuah Khan March 17, 2016, 2:58 a.m. UTC
media_snd_stream_delete() fails to release resources during unbind. This
leads to use-after-free in media_gobj_create() on a subsequent bind.

[ 1445.086410] BUG: KASAN: use-after-free in media_gobj_create+0x3a1/0x470 [media] at addr ffff8801ead49998

[ 1445.086771] Call Trace:
[ 1445.086779]  [<ffffffff81ade373>] dump_stack+0x67/0x94
[ 1445.086785]  [<ffffffff81523c29>] print_trailer+0xf9/0x150
[ 1445.086790]  [<ffffffff81529644>] object_err+0x34/0x40
[ 1445.086796]  [<ffffffff8152b9e1>] kasan_report_error+0x221/0x530
[ 1445.086803]  [<ffffffff8152bfb3>] __asan_report_store8_noabort+0x43/0x50
[ 1445.086813]  [<ffffffffa0a79341>] ? media_gobj_create+0x3a1/0x470 [media]
[ 1445.086822]  [<ffffffffa0a79341>] media_gobj_create+0x3a1/0x470 [media]
[ 1445.086831]  [<ffffffffa0a705a9>] media_device_register_entity+0x259/0x6f0 [media]
[ 1445.086841]  [<ffffffffa0a70350>] ? media_device_unregister_entity_notify+0x100/0x100 [media]
[ 1445.086846]  [<ffffffff81526232>] ? ___slab_alloc+0x172/0x500
[ 1445.086854]  [<ffffffff81203548>] ? mark_held_locks+0xc8/0x120
[ 1445.086859]  [<ffffffff81526610>] ? __slab_alloc+0x50/0x70
[ 1445.086878]  [<ffffffffa0fe711c>] ? media_snd_mixer_init+0x16c/0x500 [snd_usb_audio]
[ 1445.086884]  [<ffffffff8152b086>] ? kasan_unpoison_shadow+0x36/0x50
[ 1445.086890]  [<ffffffff8152b086>] ? kasan_unpoison_shadow+0x36/0x50
[ 1445.086895]  [<ffffffff8152b0fe>] ? kasan_kmalloc+0x5e/0x70

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 sound/usb/media.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Shuah Khan March 17, 2016, 3:01 a.m. UTC | #1
Adding Takashi Iwai

On 03/16/2016 08:58 PM, Shuah Khan wrote:
> media_snd_stream_delete() fails to release resources during unbind. This
> leads to use-after-free in media_gobj_create() on a subsequent bind.
> 
> [ 1445.086410] BUG: KASAN: use-after-free in media_gobj_create+0x3a1/0x470 [media] at addr ffff8801ead49998
> 
> [ 1445.086771] Call Trace:
> [ 1445.086779]  [<ffffffff81ade373>] dump_stack+0x67/0x94
> [ 1445.086785]  [<ffffffff81523c29>] print_trailer+0xf9/0x150
> [ 1445.086790]  [<ffffffff81529644>] object_err+0x34/0x40
> [ 1445.086796]  [<ffffffff8152b9e1>] kasan_report_error+0x221/0x530
> [ 1445.086803]  [<ffffffff8152bfb3>] __asan_report_store8_noabort+0x43/0x50
> [ 1445.086813]  [<ffffffffa0a79341>] ? media_gobj_create+0x3a1/0x470 [media]
> [ 1445.086822]  [<ffffffffa0a79341>] media_gobj_create+0x3a1/0x470 [media]
> [ 1445.086831]  [<ffffffffa0a705a9>] media_device_register_entity+0x259/0x6f0 [media]
> [ 1445.086841]  [<ffffffffa0a70350>] ? media_device_unregister_entity_notify+0x100/0x100 [media]
> [ 1445.086846]  [<ffffffff81526232>] ? ___slab_alloc+0x172/0x500
> [ 1445.086854]  [<ffffffff81203548>] ? mark_held_locks+0xc8/0x120
> [ 1445.086859]  [<ffffffff81526610>] ? __slab_alloc+0x50/0x70
> [ 1445.086878]  [<ffffffffa0fe711c>] ? media_snd_mixer_init+0x16c/0x500 [snd_usb_audio]
> [ 1445.086884]  [<ffffffff8152b086>] ? kasan_unpoison_shadow+0x36/0x50
> [ 1445.086890]  [<ffffffff8152b086>] ? kasan_unpoison_shadow+0x36/0x50
> [ 1445.086895]  [<ffffffff8152b0fe>] ? kasan_kmalloc+0x5e/0x70
> 
> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
> ---
>  sound/usb/media.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/sound/usb/media.c b/sound/usb/media.c
> index 44a5de9..0d03773 100644
> --- a/sound/usb/media.c
> +++ b/sound/usb/media.c
> @@ -135,7 +135,7 @@ void media_snd_stream_delete(struct snd_usb_substream *subs)
>  	if (mctl && mctl->media_dev) {
>  		struct media_device *mdev;
>  
> -		mdev = subs->stream->chip->media_dev;
> +		mdev = mctl->media_dev;
>  		if (mdev && media_devnode_is_registered(&mdev->devnode)) {
>  			media_devnode_remove(mctl->intf_devnode);
>  			media_device_unregister_entity(&mctl->media_entity);
>
Takashi Iwai March 17, 2016, 9:26 a.m. UTC | #2
On Thu, 17 Mar 2016 03:58:06 +0100,
Shuah Khan wrote:
> 
> media_snd_stream_delete() fails to release resources during unbind. This
> leads to use-after-free in media_gobj_create() on a subsequent bind.
> 
> [ 1445.086410] BUG: KASAN: use-after-free in media_gobj_create+0x3a1/0x470 [media] at addr ffff8801ead49998
> 
> [ 1445.086771] Call Trace:
> [ 1445.086779]  [<ffffffff81ade373>] dump_stack+0x67/0x94
> [ 1445.086785]  [<ffffffff81523c29>] print_trailer+0xf9/0x150
> [ 1445.086790]  [<ffffffff81529644>] object_err+0x34/0x40
> [ 1445.086796]  [<ffffffff8152b9e1>] kasan_report_error+0x221/0x530
> [ 1445.086803]  [<ffffffff8152bfb3>] __asan_report_store8_noabort+0x43/0x50
> [ 1445.086813]  [<ffffffffa0a79341>] ? media_gobj_create+0x3a1/0x470 [media]
> [ 1445.086822]  [<ffffffffa0a79341>] media_gobj_create+0x3a1/0x470 [media]
> [ 1445.086831]  [<ffffffffa0a705a9>] media_device_register_entity+0x259/0x6f0 [media]
> [ 1445.086841]  [<ffffffffa0a70350>] ? media_device_unregister_entity_notify+0x100/0x100 [media]
> [ 1445.086846]  [<ffffffff81526232>] ? ___slab_alloc+0x172/0x500
> [ 1445.086854]  [<ffffffff81203548>] ? mark_held_locks+0xc8/0x120
> [ 1445.086859]  [<ffffffff81526610>] ? __slab_alloc+0x50/0x70
> [ 1445.086878]  [<ffffffffa0fe711c>] ? media_snd_mixer_init+0x16c/0x500 [snd_usb_audio]
> [ 1445.086884]  [<ffffffff8152b086>] ? kasan_unpoison_shadow+0x36/0x50
> [ 1445.086890]  [<ffffffff8152b086>] ? kasan_unpoison_shadow+0x36/0x50
> [ 1445.086895]  [<ffffffff8152b0fe>] ? kasan_kmalloc+0x5e/0x70
> 
> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>

Mauro, please take it through your tree.

Acked-by: Takashi Iwai <tiwai@suse.de>


thanks,

Takashi

> ---
>  sound/usb/media.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/sound/usb/media.c b/sound/usb/media.c
> index 44a5de9..0d03773 100644
> --- a/sound/usb/media.c
> +++ b/sound/usb/media.c
> @@ -135,7 +135,7 @@ void media_snd_stream_delete(struct snd_usb_substream *subs)
>  	if (mctl && mctl->media_dev) {
>  		struct media_device *mdev;
>  
> -		mdev = subs->stream->chip->media_dev;
> +		mdev = mctl->media_dev;
>  		if (mdev && media_devnode_is_registered(&mdev->devnode)) {
>  			media_devnode_remove(mctl->intf_devnode);
>  			media_device_unregister_entity(&mctl->media_entity);
> -- 
> 2.5.0
> 
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
>
diff mbox

Patch

diff --git a/sound/usb/media.c b/sound/usb/media.c
index 44a5de9..0d03773 100644
--- a/sound/usb/media.c
+++ b/sound/usb/media.c
@@ -135,7 +135,7 @@  void media_snd_stream_delete(struct snd_usb_substream *subs)
 	if (mctl && mctl->media_dev) {
 		struct media_device *mdev;
 
-		mdev = subs->stream->chip->media_dev;
+		mdev = mctl->media_dev;
 		if (mdev && media_devnode_is_registered(&mdev->devnode)) {
 			media_devnode_remove(mctl->intf_devnode);
 			media_device_unregister_entity(&mctl->media_entity);