Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932970AbcKNKZf (ORCPT ); Mon, 14 Nov 2016 05:25:35 -0500 Received: from mx2.suse.de ([195.135.220.15]:60918 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752632AbcKNKZD (ORCPT ); Mon, 14 Nov 2016 05:25:03 -0500 Date: Mon, 14 Nov 2016 11:25:01 +0100 Message-ID: From: Takashi Iwai To: Shuah Khan Cc: alsa-devel@alsa-project.org, shuahkh@osg.samsung.com, LKML Subject: Re: BUG: KASAN: use-after-free in snd_usb_audio_free In-Reply-To: References: User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/24.5 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 802 Lines: 30 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; }