Received: by 2002:a05:6520:4211:b029:f4:110d:56bc with SMTP id o17csp2108230lkv; Thu, 20 May 2021 03:36:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6/qgMv2VMIGZsoMKF0ZV0guWtnpu8KxDJNMhMBVIzvKMFI+vdZe6QtDVd5YztodcqkXUE X-Received: by 2002:a92:c046:: with SMTP id o6mr4342030ilf.296.1621506975438; Thu, 20 May 2021 03:36:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621506975; cv=none; d=google.com; s=arc-20160816; b=xZbexqjq7BKc7ZwUFrmogtG1RF8KQ4a41MNraJgIfiez1qkMqLkGXE4KWDT+817CjK bftEsGz7JqKPSXmYBg+MR+2HsZ8XFYvSQhwNXKrG4k/SkSaBEBY/Y0NMtDz16mGeJ65h KYv4h2kXASXbsMbJUocF0hVVWalgHVCG0pfwQgfFeJHmk2WSTUSyiiTGKXCQzpTzoGNW s6TyM6qfDB0lxTb3UKIFhGLnwy+dJf9ipM7fAxHcNEeZEf7Z1XArPXUC0R28MGpWoQSA nJkVKNmNdwzuRVP3Nd4HgirDA61I1b9wF+YB3VxwjfRWyGCQJj+8RNqcdQK+cBaQqmC5 bTXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rmkNeZErbIuNx3iHhNadWsLwJ7xnVcWCxc6ik1uq5a0=; b=AGZWvyG7zpLIXtoDPDyDgxFxd1H40b6v2buCVmnCmAh6KjS7rPFZDgk/2B6q6n0+0l fvaV9nkDG7YuV+uTB7qXCRvzZmFYRl722KNJWOqmgeUh3RfkH9Rx3bS6p885tZzwB8ct QxXX5uGpPkSkqM7zlV3KCfr/0vGbbVYn5AYBxRsGGt3NiRptGrMvST9+xH3rj29G+uz8 uYRzmeFtVuNlMTAkfpQeHa0GnfswFBMlYXdUMMeEMAozK6qdSlmiLDvsj9xhuWiohWfb 27XPiltRunaYTnCMI0D/0pJt8XBz0cR2RfZ7bKbGCecrxccX7RFvYRXSTYwdEbpyKsjr rkBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2HU3tqtU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w14si2705600ilu.141.2021.05.20.03.35.42; Thu, 20 May 2021 03:36:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2HU3tqtU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237437AbhETKe3 (ORCPT + 99 others); Thu, 20 May 2021 06:34:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:51822 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235633AbhETKUf (ORCPT ); Thu, 20 May 2021 06:20:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 14472619AC; Thu, 20 May 2021 09:47:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504056; bh=AL7u/WMym1lYfDxy4MVtqLMV/bv2ffPUd+7yZssaMYs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2HU3tqtUo6sC4IC9a4vrZLUaRmfp9PuRDwgrjuMMvr9wYS9nscp7tOrXJp0T6bPDm 5SDQK1+8znC1/QsEhC4i96dnht+jdUdHUXjQZOHqqXES0eCUP0qlIElKtrIiDYuhiC 8UwvOk8kN/k01Ufa7oPSfsEOC4+Ox22A5mRllXXg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lv Yunlong , Takashi Iwai Subject: [PATCH 4.14 073/323] ALSA: emu8000: Fix a use after free in snd_emu8000_create_mixer Date: Thu, 20 May 2021 11:19:25 +0200 Message-Id: <20210520092122.598012427@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lv Yunlong commit 1c98f574403dbcf2eb832d5535a10d967333ef2d upstream. Our code analyzer reported a uaf. In snd_emu8000_create_mixer, the callee snd_ctl_add(..,emu->controls[i]) calls snd_ctl_add_replace(.., kcontrol,..). Inside snd_ctl_add_replace(), if error happens, kcontrol will be freed by snd_ctl_free_one(kcontrol). Then emu->controls[i] points to a freed memory, and the execution comes to __error branch of snd_emu8000_create_mixer. The freed emu->controls[i] is used in snd_ctl_remove(card, emu->controls[i]). My patch set emu->controls[i] to NULL if snd_ctl_add() failed to avoid the uaf. Signed-off-by: Lv Yunlong Cc: Link: https://lore.kernel.org/r/20210426131129.4796-1-lyl2019@mail.ustc.edu.cn Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/isa/sb/emu8000.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/sound/isa/sb/emu8000.c +++ b/sound/isa/sb/emu8000.c @@ -1042,8 +1042,10 @@ snd_emu8000_create_mixer(struct snd_card memset(emu->controls, 0, sizeof(emu->controls)); for (i = 0; i < EMU8000_NUM_CONTROLS; i++) { - if ((err = snd_ctl_add(card, emu->controls[i] = snd_ctl_new1(mixer_defs[i], emu))) < 0) + if ((err = snd_ctl_add(card, emu->controls[i] = snd_ctl_new1(mixer_defs[i], emu))) < 0) { + emu->controls[i] = NULL; goto __error; + } } return 0;