Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2483893pxj; Mon, 10 May 2021 04:12:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxz9+IreE+fHb3+tXTP0+U27J9h1PUTnIeMUXTig0fgFZrr8djR5C9xq4ePGtI/TYAuYQqO X-Received: by 2002:a05:6602:24d1:: with SMTP id h17mr16927055ioe.99.1620645125162; Mon, 10 May 2021 04:12:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620645125; cv=none; d=google.com; s=arc-20160816; b=stKM44/n2neZc+ntrbyfy8eToIAPyt8Z0x88gdFHAba5UmeFaClJ79OyvuY3So2nP+ FrPJRG8pcrn20zGftAmDQgwVap6qBiY+j7mMzVS2phAs3MBkOlmalfEeB5Siw4JVMt2i KKRijmEq+5o+Kf47KYM8/wp4J7Zg3EODWbEYR0vp61QMKTHgX7QRSAgCY8PslBzuFyNx aDxYESZwOQ9SaOCDWjhIKGt1zD+ZXfKzeGY3H3+dO0ngb2EYefs1olMnZ/SPAI7/3Gnu zM8cLSjGs+y0C5yARSd0zwb/1dNxT+UhNJ3zkU70+UpfIvZ7X6rV03MhjNjEhp7scn1T gzDg== 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=RsOlX3TorMu1aOe6wzoZNjVreg8S2RDZ9nIpISuxt9w=; b=0JcZBvuuRzpoT2J4vtw9bV80z4f+nSFtwenbBd6B5SlWoSEL4cnjk1Fmat174cdEdC 0wJmrBN3pWu0pS/LD90Ed2uow8Sqy/4tETw0VQHz218Pl7xqdB9E076Uv01W29nBhdtp eFnDTpredjkF1MHC5lgj+dC5Irv0KJP1rYEyiquL1vkSkHAjc+00ksOBG/ZDrBGgYNW9 JouCLnRddqtX81GQIWx8aZ9831b/5yfrWQY6blBIswTz92t5D5x1PhIPF/pm+MyBuxVr nPnHau/uxodzZXb7eRY2136wwhl7i7gR2rAfmEo7fkH8zBO5vavAwwIayLih1kv9rkUo Ttbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vEKfDNG1; 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 t14si14487506iol.93.2021.05.10.04.11.52; Mon, 10 May 2021 04:12:05 -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=vEKfDNG1; 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 S237083AbhEJLLT (ORCPT + 99 others); Mon, 10 May 2021 07:11:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:41986 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233602AbhEJKuT (ORCPT ); Mon, 10 May 2021 06:50:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C06636194F; Mon, 10 May 2021 10:39:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643175; bh=2x17qympeKNR+HljtLITMAh+gayFVjXH0nYXirtyFrw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vEKfDNG1cUuPFd9UvLtIR0H1+AcUQWs7/79J51fNb/dS4PaUpw34v8dMnXWDa8P8u obH4RQoFLpP2iH0KZBFkdBb/7P6tHm9rbGna8ytfRQdWhq4FepYfNIQ/bL+1bgNui9 cCO9bUKRvouyF6s5+DwRHH7aBm9euAlEpsVzS9+s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lv Yunlong , Takashi Iwai Subject: [PATCH 5.10 209/299] ALSA: emu8000: Fix a use after free in snd_emu8000_create_mixer Date: Mon, 10 May 2021 12:20:06 +0200 Message-Id: <20210510102011.847870766@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102004.821838356@linuxfoundation.org> References: <20210510102004.821838356@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 @@ -1029,8 +1029,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;