linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Shuah Khan <shuahkhan@gmail.com>
Cc: alsa-devel@alsa-project.org, shuahkh@osg.samsung.com,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: BUG: KASAN: use-after-free in snd_usb_audio_free
Date: Mon, 14 Nov 2016 11:25:01 +0100	[thread overview]
Message-ID: <s5hr36e2waq.wl-tiwai@suse.de> (raw)
In-Reply-To: <CAKocOOPt1s2m1JBGSqEBwO1SdeOt-CinDmw-Lp3JFUz5gMT5Bg@mail.gmail.com>

On Sat, 12 Nov 2016 00:34:38 +0100,
Shuah Khan wrote:
> 
> Hi Takashi,
> 
> I am seeing the following use-after-free error when I disconnect an
> USB speaker. I saw this on 4.9-rc4 and 4.8.7. There might be race
> condition between the disconnect and pcm close perhaps.

Thanks, this looks like a new discovery.
Could you check whether the patch below works?


Takashi

---
diff --git a/sound/usb/card.c b/sound/usb/card.c
index 9e5276d6dda0..2ddc034673a8 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -315,7 +315,8 @@ static int snd_usb_audio_free(struct snd_usb_audio *chip)
 		snd_usb_endpoint_free(ep);
 
 	mutex_destroy(&chip->mutex);
-	dev_set_drvdata(&chip->dev->dev, NULL);
+	if (!atomic_read(&chip->shutdown))
+		dev_set_drvdata(&chip->dev->dev, NULL);
 	kfree(chip);
 	return 0;
 }

  reply	other threads:[~2016-11-14 10:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-11 23:34 BUG: KASAN: use-after-free in snd_usb_audio_free Shuah Khan
2016-11-14 10:25 ` Takashi Iwai [this message]
2016-11-14 16:55   ` Shuah Khan
2016-11-14 21:06     ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s5hr36e2waq.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shuahkh@osg.samsung.com \
    --cc=shuahkhan@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).