Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2468141pxj; Mon, 10 May 2021 03:50:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFNZa/j+GQ7XR5xgCBgu/w+z1rjsSWKGYxS/XuxV6WpbRLCa4Lhr1ESu3OSRr89PKAF5yW X-Received: by 2002:a92:340a:: with SMTP id b10mr20970739ila.301.1620643818259; Mon, 10 May 2021 03:50:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620643818; cv=none; d=google.com; s=arc-20160816; b=YPUw9JQwlS2PVHhhcdpw2QSsPB9SwFqk8iXOnWndKd3wsxwgHvjsQRdwAOdBwDKK9h HYKFTn3uWTi2N5yMf71IgyN8XTTz8DPnBvoTmCXduRJcyJTckKImF7S6o1tAPsyI7Sna 2J7dRzgTUJx30ohyfe41dFWb12UINykz1fT0KILWmKH39RjRgUjLPvgloouRlDeQKIqk TYgUoTWYOyqc1MRFoOYxnaKpB02h83Ra+u7ti9WzwPHiVpN48Sch2cZ3s9Fk8oqoIOWx tGiZlua/vfIT+HfsjFiCDY8by0MzirFjNjCk9n/5ZmspQxc/dJGlUyGzI1DV3q0WM7Wb pAPg== 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=mteoiy/OQXtWvwzRQWurZRLcIcYdqDlTHdCE2gzE6mDVeKwRWgtwXM4ca5U+aW6zel LKK6ETXMjT8fmt8DSWjLMH3hibfVbflI0yxxuJi4MTQxl1f3chESnLGQ2fNjCkmlTkjP usK0loVGtf8B0kEqigljJ0iNstYB4KQ5Rtvt1raFPlkeKnU3/Dh25knNHmt8mJ2bgBZI Ulbv4Hwwb+EWZjP87oZJrCBQ83DJB4nyByUVY2jhm1RqoxMPQm8QC9JTuDWl0YowTuAK hTUBLnRBuBLxN/8vVVqDc1xlHGH8IkHrKKiWr7eQvkhp7shFrn4eH7DqSQK0EdkrwUCM kHjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=b06ayzPM; 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 i14si9592826ilv.131.2021.05.10.03.50.05; Mon, 10 May 2021 03:50:18 -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=b06ayzPM; 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 S232967AbhEJKtT (ORCPT + 99 others); Mon, 10 May 2021 06:49:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:48982 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231497AbhEJKiN (ORCPT ); Mon, 10 May 2021 06:38:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 830A36194D; Mon, 10 May 2021 10:30:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620642602; bh=gwPx88FQUSun16PDktMHt4w2R/nn90Cn3ZCyjqLPprA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b06ayzPMXCBWgS0YNX4JcgHvX9PpjyEAszhUAWcBpSM1E2mHRDn0o42AK1mWzSy2o qT8y8K3C3+wJNYq4+x2bNNW5dcukOzmQNhxLSpfAVm7oxqoADwZlWgUEolREoXsru7 xuMleyzzXF3JR57ycimETjblM1ixZ5AXtEaOk4Io= 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.4 127/184] ALSA: sb: Fix two use after free in snd_sb_qsound_build Date: Mon, 10 May 2021 12:20:21 +0200 Message-Id: <20210510101954.334013342@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510101950.200777181@linuxfoundation.org> References: <20210510101950.200777181@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;