From mboxrd@z Thu Jan 1 00:00:00 1970 From: Takashi Iwai Subject: Re: BUG: KASAN: use-after-free in snd_usb_audio_free Date: Mon, 14 Nov 2016 11:25:01 +0100 Message-ID: References: Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Return-path: In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org To: Shuah Khan Cc: alsa-devel@alsa-project.org, shuahkh@osg.samsung.com, LKML List-Id: alsa-devel@alsa-project.org 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; }