Received: by 2002:a05:6520:4211:b029:f4:110d:56bc with SMTP id o17csp2108371lkv; Thu, 20 May 2021 03:36:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIgSqbzG4nF6So+aq947dkN4pGCZv1D8jn6U/Krm63sh3UCfMtNrT3hoMwXvL9cqYpZKpQ X-Received: by 2002:a92:2a09:: with SMTP id r9mr4460990ile.300.1621506987887; Thu, 20 May 2021 03:36:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621506987; cv=none; d=google.com; s=arc-20160816; b=khrYhHHePRFY54o2O0M6XIWuDXlrD8ENOlUvqTKB2IHSJcMQAFCuU93/y44exgqwF+ UtZt1YoRlR/O/0aWsD8MXq+ND460sSjIELcr5UzZ5ei5pzbZVqqWJ0X87z8e3mfVgSxe n6LtA2qH0Yde91RjXcsgFrO+Svp3E7k/i/qMgOt1/R2G1fmnjoJQhLvdCdQTqsVoJkSc NtzN36RsjsK7wzAY6UoH/0wcJvlEXrjW6e6W6kYh1eDtYOckXx7ZRk0hp8DS+B8ecknY wpa0RGuWh95qWgKhYOr3ZUplK3Ws2/YezrE//mKZqSjYwcxNzGhiQcbTqkSoSdKoV5J+ Gfqg== 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=jxfgVBxuLuD3f4JggiDtHLTUGxbkoBdHlEQj98hIb32cejKbMRdMasyT3ln8eA/09o TaolBojgTUDYrIajck4DSOGYL1adTj/uquKy+vPV6Wiq0IEKil4BnBNMmYTa+3inHmR7 vFxHKHaujRlIXwpFvF9z5SAt4RZvwoWJEVlH+5cMX19YGsi1x0VCJsoMecWcVp7Q526g Rjg+o710JDlOYyzu3vugfHxhSNJXa0j0WSa12uULCMDRXJYAg8iP6WUnT6nti+Er9NUN gefZutW3IgRCinq6sWjUrrFiM1c3WFrKADv+zSDUn/lNzXuiy/LknxbXkDRjwdU82xJ0 9C/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=h6ZOem0b; 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 b11si1854810iok.1.2021.05.20.03.35.52; Thu, 20 May 2021 03:36:27 -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=h6ZOem0b; 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 S237407AbhETKeR (ORCPT + 99 others); Thu, 20 May 2021 06:34:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:51828 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234614AbhETKUf (ORCPT ); Thu, 20 May 2021 06:20:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AB40561458; Thu, 20 May 2021 09:47:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504063; bh=/CncAhzPTjBPbmdbXKkNiHClkxizzGCCXUoVLQh2+CA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h6ZOem0bidhA7ZFnNlHUAxfEffV9Irndjm2QFAkjj4cy1qTFU3U2da4JwaEidzMoe euM9YGKFvErjW/KVHxj8z/Bmynf6U+63bi19sWwKBN5bzWCwNN60qDJwZ7QvUimVCc Xc2r1jq1Tb9+XiphcvamFVhuJHF0r5WFas5ndcug= 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 075/323] ALSA: sb: Fix two use after free in snd_sb_qsound_build Date: Thu, 20 May 2021 11:19:27 +0200 Message-Id: <20210520092122.661337024@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 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;