Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1151626pxv; Fri, 9 Jul 2021 19:40:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0K+Bs+Ny/JCOCqhVSIiXSynXhVUgFjggBIbktH7oq3S+HB3Z6NMqflUEK4A8bzDhrP8DB X-Received: by 2002:a05:6402:1488:: with SMTP id e8mr26992856edv.341.1625884819099; Fri, 09 Jul 2021 19:40:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625884819; cv=none; d=google.com; s=arc-20160816; b=C/mNyf4j478obKCo4dU3lJRzK8DauYsvphZ83e1NQ225T81wwMm7fmv2vUAOHGfOVy G1UXz3RcfZB/cNcD6eFXiKOYMg0rTXtuZ/e+QunB8iY1UViJtRll2v7qfennsXBF/N2m 2/sG02DBNa8IIui3TDPFbst4zdXQM7KPScER5G0ve905yKa46hOPmgsUmunAZNeEJvlp HTmWtsg96WnVoSZjce5UTvgTJTSIiY/CvFlCnLRPExS/mfrRRilKFvHcDAgJR/xvnIkY 3pa9Aso5PZo8k1sGDzjB5u1Jzlx7hAetWciHRCF4Km7uis36I/UofGXJ0rfHu8j+rcLt MorA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KRftm9IT/U2KUQzmPj5RI69zNNJf3MdbSbqqMhbp3c8=; b=uIg5Ak5ddezf7gAvYVM2JtAJUHysHb8AmRicOL0e53J2OJUy7EzTTy29zG8ocr4JGk QJJUnxkjuBlbHFBvTcBtlrH+40hJgK/T+aE15OC1jX9r/1MoEJg8XK4gZu8RlwtGL+UD X46QTJBJAzw5neoSVaI98HOJJas3BsCg+5qapgGIRfqeZ5rZ9z566hd/yhz9RcSjqT16 P8ZqRJSnln2yQdGiol/8k46Fmhv0yO5bAMz/TMu+5X0bJoe0/+Y0qq1F/uPB7IwGP1ZI Qd8mC/WUEHSoWeqj+ZDNUJvxjWtl+IsNd/kI3GkQ4sBMg5MlFH+cK3tFeBZ89H2hI5c8 AskQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AZs4rpum; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z8si8202210edx.581.2021.07.09.19.39.55; Fri, 09 Jul 2021 19:40:19 -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=@kernel.org header.s=k20201202 header.b=AZs4rpum; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235088AbhGJCjT (ORCPT + 99 others); Fri, 9 Jul 2021 22:39:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:53522 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234065AbhGJCfa (ORCPT ); Fri, 9 Jul 2021 22:35:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 66D6561421; Sat, 10 Jul 2021 02:32:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625884350; bh=e56wCNtzipbCruyvGQJOp9CBwWPfNJuoSaIZ7Nckhbc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AZs4rpumhbBvM/b+vJamc5MAVt9nmGKq605h+9zVakS03U0PgfOlTXkxpFXirjBn5 LLBdjsqJ3zB+QeW03GEmBahOO/7nQ/4PBvFu52h9HtMERnQfJfun1/9sIOEvitgGq/ H8bSYvjyG/QvPuptfeYyzZTXPxLQ+t8jxY6JKRSTYJXsoVywSt2EXnvh+bM3ybwpLs dMrDrlqEQfaX1p8c2NZ0oem+FDrqau1SMk963f+wbviDL26ocPOK/plMGNtosQWxq2 wPJSl8m9OPHDkdTLtoHDM4GPYQk0HQyBSm9UPvzISSUHVYj/FUM3XnqjumefcNmu8x +jtxMdKuCfy5w== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Takashi Iwai , Sasha Levin , alsa-devel@alsa-project.org Subject: [PATCH AUTOSEL 4.19 21/39] ALSA: sb: Fix potential double-free of CSP mixer elements Date: Fri, 9 Jul 2021 22:31:46 -0400 Message-Id: <20210710023204.3171428-21-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710023204.3171428-1-sashal@kernel.org> References: <20210710023204.3171428-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Takashi Iwai [ Upstream commit c305366a37441c2ac90b08711cb6f032b43672f2 ] snd_sb_qsound_destroy() contains the calls of removing the previously created mixer controls, but it doesn't clear the pointers. As snd_sb_qsound_destroy() itself may be repeatedly called via ioctl, this could lead to double-free potentially. Fix it by clearing the struct fields properly afterwards. Link: https://lore.kernel.org/r/20210608140540.17885-4-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/isa/sb/sb16_csp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sound/isa/sb/sb16_csp.c b/sound/isa/sb/sb16_csp.c index 2e00b64ef13b..b3eecde0b612 100644 --- a/sound/isa/sb/sb16_csp.c +++ b/sound/isa/sb/sb16_csp.c @@ -1086,10 +1086,14 @@ static void snd_sb_qsound_destroy(struct snd_sb_csp * p) card = p->chip->card; down_write(&card->controls_rwsem); - if (p->qsound_switch) + if (p->qsound_switch) { snd_ctl_remove(card, p->qsound_switch); - if (p->qsound_space) + p->qsound_switch = NULL; + } + if (p->qsound_space) { snd_ctl_remove(card, p->qsound_space); + p->qsound_space = NULL; + } up_write(&card->controls_rwsem); /* cancel pending transfer of QSound parameters */ -- 2.30.2