Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2487861pxj; Mon, 10 May 2021 04:18:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4g5FzIeWStuUiI/X28pYY4d99oVsYQpaliQN4Sky95PFFIt6KFbbwG+r/eKxTRM8eW40a X-Received: by 2002:a05:6602:27c2:: with SMTP id l2mr17563393ios.71.1620645484667; Mon, 10 May 2021 04:18:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620645484; cv=none; d=google.com; s=arc-20160816; b=zgZ3Et4gVjOchlC4sgnUJpu8Zg3MlEVsitJrpUt8QhLF2AaUNdMJAQethuk4M7NyCb MKMCaowJzXfAWC00QPt2DylwIqaodPKsO70SscIt9E34FsWXqY8UfzUy9oL8pZN2Pq48 ORaE18imKzHM44Yor/zZLVENoMKwzIDo/RenUhV6g3ldaJUZ6TiiwEMEqu77pOKe3RIz Md/1XZjFu6Q7+UyGrsJMITAnbgnAupteNwn2INzZoUFOoUxzXgeY1W5V8PBf5zQUnP5F 4wybP6lMq93uidE57tgsEMb328tXGIHIsxuVC6BIvZDrsyfHlDqZXyvQjWHY1juJ5tkS jc1g== 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=oZknzziQBTlkfhoCVf73rKAoBcBUzQbxWXjMOW04974=; b=OFDDg+LEaZsJ0Pi3gK2ZQknqsmvU52KMY4dFPvsMF8FHum6kLkPPoP+exoDhOnivGP gpbQ5yAVKEUY9EpzqEfSV9mRZrkJntYLskxMTwVhUmgOqbqfLU9gQ3bgNCM6dSbZ+DNq oMtCfNkIWoHdw5/kE1eLviJ1TNGYcEy0LjbIVuMMnCYxhndIWFGS5fez6Hxn03BD6Ffr MmiXw37kAi09oKKW21j/1Mzh2WGKkbsJ5aqjtpY7aDz1AbEOFKiKk5QPX1YcYBK2+mQl jP8LhD38depZh6a0o8OaKo8suVDT28bNeP88Ce6cIUVz+GH3Fy5oi/EqWSGgQ+vAVjta QddA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EmS+6FHl; 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 d7si18930364jak.52.2021.05.10.04.17.52; Mon, 10 May 2021 04:18:04 -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=EmS+6FHl; 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 S235300AbhEJLOA (ORCPT + 99 others); Mon, 10 May 2021 07:14:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:42076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233650AbhEJKu2 (ORCPT ); Mon, 10 May 2021 06:50:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B384061950; Mon, 10 May 2021 10:39:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643180; bh=gwPx88FQUSun16PDktMHt4w2R/nn90Cn3ZCyjqLPprA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EmS+6FHlRyeM1odfkRdZ7PNr+3GGScjGZY/iCsQOTpsj0SCt239NLLbLoy0Xbwvqm ZDXMGRxlHuM/HLBTxvKORZrPkQyUEwBgCsGF6bAm2Rvl2zdl806lrsotis1M6RK/Vy nrt7aMZ+1Igt1pnnweHKjBSVsAnGFq2rjOFesr94= 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 211/299] ALSA: sb: Fix two use after free in snd_sb_qsound_build Date: Mon, 10 May 2021 12:20:08 +0200 Message-Id: <20210510102011.913518888@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 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 @@ -1045,10 +1045,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;