Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp304930pxj; Thu, 20 May 2021 09:42:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjSDoLNUPIkj+Od6WZwqZsKCzvP2TtumNLh4E+c1SSa808qKtjMiA7QwZR4/5pQf+yRtcd X-Received: by 2002:a05:6402:1b10:: with SMTP id by16mr5788297edb.172.1621528958972; Thu, 20 May 2021 09:42:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621528958; cv=none; d=google.com; s=arc-20160816; b=vyqBUl1U/HQwM5TesbGfoPFKRwBiWzZMIxQlqoIeT2tvL/UcbnGmQpiV3NosmL2NbI FDTHdgjTkdRMo3Dn06P2AWkN2IS9AK2I7AfxxQ98dDjyyWV27ueW8/Wyml5hQSMyyEWu 4Jw897h4aOKPY2cDXvKAlOoQMLC1O12mBunNvlUtvfmK388DdOErMhIbS0MuZ9pmBHDA 9w9upJ7hVW7F3RLqd7bhxN3n5C+LK0qdZOyMC4+sKqErw2hwC5Pw2q5pDY2bJfwY+xDy LXABGjESpyhAIqYtrf3DcDFYEb7rJwHIkFPIzbB7lG2sbBfNEHI/84HCk3kckZn1APZb HU0w== 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=SlscUe2fqDV8GglQsSynf71SQMRHqNRoVWfV6UXG6kk=; b=0ZOESecaiBb96Eu3TkGVlM/dNe1J/ntOQQRi4RsbtzBRv1BI3V7Zyv1CTaeDQvNgWu IEpHKMZpqNxbi4iUBQ3JxEzmAiXNH52yjklYsjYK5zXDYTnR1YvbESZ6MiFf/qP5y+mF LMgpatZqwsUL78SvJYpMIWfXFsmrN6cSvZPZcAW0sf2WTe8JabkmQ91nDcMf5MQNGbP2 5zp+4eHSe51863/xhys7tWCWW2saIdztfJqnBVyHYxmzS+g0busiY1rSAAJa0S4GvTSO QVIxux8ok5PcF8/XXypFK2isVgM35gMcviIuuUCj6d5av17bJUBTMiM+3NBxD8YZyEeS 2Yug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UU3ouFPD; 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 t19si2987050eje.44.2021.05.20.09.42.14; Thu, 20 May 2021 09:42:38 -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=UU3ouFPD; 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 S233126AbhETJrU (ORCPT + 99 others); Thu, 20 May 2021 05:47:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:47674 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233766AbhETJoV (ORCPT ); Thu, 20 May 2021 05:44:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1BBE9613D8; Thu, 20 May 2021 09:33:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503190; bh=/CncAhzPTjBPbmdbXKkNiHClkxizzGCCXUoVLQh2+CA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UU3ouFPD6AVzI1KhExZU4srcTXxh/OUAAPcsMKLM3a+L5QL2mnhsVKBjyr0H21zx3 LOj9FO5N+TqucSPm9ca1DAcg6QOnlzWSmLtzT98bChGvCNoFfX9wsnXFZ75S1sZeJ6 LCZDR0F52c4nAsQe+r2rJV6UhkLgjnQ6IuRGG48w= 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.19 076/425] ALSA: sb: Fix two use after free in snd_sb_qsound_build Date: Thu, 20 May 2021 11:17:25 +0200 Message-Id: <20210520092133.944431198@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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 4fb44dd2c1dda18606348acdfdb97e8759dde9df upstream. In snd_sb_qsound_build, snd_ctl_add(..,p->qsound_switch...) and snd_ctl_add(..,p->qsound_space..) are called. But the second arguments of snd_ctl_add() could be freed via snd_ctl_add_replace() ->snd_ctl_free_one(). After the error code is returned, snd_sb_qsound_destroy(p) is called in __error branch. But in snd_sb_qsound_destroy(), the freed p->qsound_switch and p->qsound_space are still used by snd_ctl_remove(). My patch set p->qsound_switch and p->qsound_space to NULL if snd_ctl_add() failed to avoid the uaf bugs. But these codes need to further be improved with the code style. Signed-off-by: Lv Yunlong Cc: Link: https://lore.kernel.org/r/20210426145541.8070-1-lyl2019@mail.ustc.edu.cn Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/isa/sb/sb16_csp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/sound/isa/sb/sb16_csp.c +++ b/sound/isa/sb/sb16_csp.c @@ -1059,10 +1059,14 @@ static int snd_sb_qsound_build(struct sn spin_lock_init(&p->q_lock); - if ((err = snd_ctl_add(card, p->qsound_switch = snd_ctl_new1(&snd_sb_qsound_switch, p))) < 0) + if ((err = snd_ctl_add(card, p->qsound_switch = snd_ctl_new1(&snd_sb_qsound_switch, p))) < 0) { + p->qsound_switch = NULL; goto __error; - if ((err = snd_ctl_add(card, p->qsound_space = snd_ctl_new1(&snd_sb_qsound_space, p))) < 0) + } + if ((err = snd_ctl_add(card, p->qsound_space = snd_ctl_new1(&snd_sb_qsound_space, p))) < 0) { + p->qsound_space = NULL; goto __error; + } return 0;