Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754101AbcC3UbU (ORCPT ); Wed, 30 Mar 2016 16:31:20 -0400 Received: from mx2.suse.de ([195.135.220.15]:40854 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751344AbcC3UbR (ORCPT ); Wed, 30 Mar 2016 16:31:17 -0400 Date: Wed, 30 Mar 2016 22:31:15 +0200 Message-ID: From: Takashi Iwai To: "Vladis Dronov" Cc: , "Jaroslav Kysela" , , Subject: Re: [PATCH] ALSA: usb-audio: Fix double-free in snd_usb_add_audio_stream() In-Reply-To: <1459364602-28997-2-git-send-email-vdronov@redhat.com> References: <1459364602-28997-1-git-send-email-vdronov@redhat.com> <1459364602-28997-2-git-send-email-vdronov@redhat.com> 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: 1267 Lines: 45 On Wed, 30 Mar 2016 21:03:22 +0200, Vladis Dronov wrote: > > There is a double-free bug in [snd-usb-audio] module due to alloc/free logic > flaw in snd_usb_add_audio_stream() function. This leads to kernel structures > corruption and panic. Fix the code flow and alloc/free logic so there is no > double-free. > > The detailed analysis: https://bugzilla.redhat.com/show_bug.cgi?id=1283358 > > Reported-by: Ralf Spenneberg > Signed-off-by: Vladis Dronov Thanks for the report. But how about a simpler fix like below? Takashi --- diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c index fb62bce2435c..0e154ae7924e 100644 --- a/sound/usb/quirks.c +++ b/sound/usb/quirks.c @@ -150,6 +150,7 @@ static int create_fixed_stream_quirk(struct snd_usb_audio *chip, usb_audio_err(chip, "cannot memdup\n"); return -ENOMEM; } + INIT_LIST_HEAD(&fp->list); if (fp->nr_rates > MAX_NR_RATES) { kfree(fp); return -EINVAL; @@ -193,8 +194,11 @@ static int create_fixed_stream_quirk(struct snd_usb_audio *chip, return 0; error: - kfree(fp); - kfree(rate_table); + /* linked fp will be removed in snd_usb_audio_pcm_free() */ + if (list_empty(&fp->list)) { + kfree(fp); + kfree(rate_table); + } return err; }