Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1896544lqm; Fri, 3 May 2024 09:22:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUIDsgIHKJoKf5zs/ZZs8pfzEvsW0FzzGPuburuhyY5WGll/kjKEDrL8y1NUTj1c+CGoDIpAnmJ3vSLyrrJ2rnM6nta1BLeeCYc2TuTaw== X-Google-Smtp-Source: AGHT+IG8JpsBcQZCbjNIfQS+XxUQ/Lvutkn/3+oT4tUZ2jKKW5WOn+M2FkqQPSQXeVdJAPjhy65h X-Received: by 2002:a17:906:1b43:b0:a55:387b:eef9 with SMTP id p3-20020a1709061b4300b00a55387beef9mr1922438ejg.10.1714753348775; Fri, 03 May 2024 09:22:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714753348; cv=pass; d=google.com; s=arc-20160816; b=NIPY4qSAh93ghyCe7ijPYB/BwiOP2PTfNDpaUnpkV4nJJHAvl9iRcw5REnPZLWKdhG +akMRKNGpvGPcm+PApej5le8AgIXdWLwonSow9TN7mpKg2FVT5mw7tcHeLEBGkPcZzGO fyiOe0LfuhZaf2I0reNM5/oNqRifw1D63bVbhFG1JRA2WebDnTPPDwxTs6Kdgaa1GL7w OOg4JaltKzchXYrp0s7MTUhhmnxxU8Np/dXLHw1OyMyin+pTymJBhaHck8vfXIiKYCRe p6/aBqWHMLWnSW7zxqgeS1e8hUa4ZPzVa+4gWRkbbgSxxYoyCBtZepHPxFsqf7BrsM/b MNPA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:references:in-reply-to:subject:cc:to:from:message-id :date:dkim-signature:dkim-signature:dkim-signature:dkim-signature; bh=oiTqZfHoHoeBGnqeqSO0b2VdvRk2sjq5+PSJaOuL1J4=; fh=m4f0pUTbTjq4cSWYPK8zWVu3WlMv42DHo3+RxWKQq2M=; b=hVgFYdNzpsRFleaR2c+05Q0+dTIvlhkQZWdhb2j64uvkdlpE9eupTtCltDigdOLyF7 FihiQaLeFuRK5HEJF0gT+dn8lYMtH5GfuDFbfr1n8fFnB7oc+u0nuhkaTCjBn4ocRnKX P7RWoYgzJA/DqEEjGcxPcHExlgvscbd7qhF8V093oC0gFSk9LMt+d+OdKGp1+/vUHmML JpfCzWvYEiKmKpabvRuIf4TqrgNITpvra0NNrrmUnKP528Za6MX2U3wH82nKYlmN+Ir4 fNyAu9hpGowkjDwQpZTeK563zpahZOqA6Go0VKD+RW8kQwc7L4jFqe/42y5naQFhL345 hzGQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=DmHHtJ+M; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=DmHHtJ+M; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-167889-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167889-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id i19-20020a170906265300b00a58e38ce488si1718568ejc.94.2024.05.03.09.22.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 09:22:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167889-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=DmHHtJ+M; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=DmHHtJ+M; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-167889-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167889-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 44F981F24A61 for ; Fri, 3 May 2024 16:16:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C330A15533F; Fri, 3 May 2024 16:16:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="DmHHtJ+M"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="iFUIqD0I"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="DmHHtJ+M"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="iFUIqD0I" Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D0A8152DFE; Fri, 3 May 2024 16:16:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714752981; cv=none; b=aW9dZ1RqbnIwOfNDE7FE8WbDpoolI1uvhJxXiU/VTH00BhJRW6Wa/NIGJ8LD/vSOD1tHttZriCI62K4PefFkE7NZvwqYRyhH4LoJAoGbAA3iUKBMZ7+0tE6kYHncX5zgyseMosNudGszK5atj1NVnhariQyF4UDxxCu2ngk/WtM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714752981; c=relaxed/simple; bh=9JAuqzmFfvLFHF54ovz6fulY0osoFcF5ZH4aXMlz1PQ=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=i6g1iHVyDNM2nnwcmdGcdBxr2rwSXMyqnqESdx+R7S3iybbWVD8rKnHswzFeUoIp36+DvKTQ0hWj6O2WKENEZtgkNPsbY5Lx+yJQrJWNXuBzvfzy68odTfH9NgH9xTNnMbkjr1rAJTaWtKbKvndeaXlz6O+u+gExcxNoMIHDSRA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=DmHHtJ+M; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=iFUIqD0I; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=DmHHtJ+M; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=iFUIqD0I; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 465EA1FDB7; Fri, 3 May 2024 16:16:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1714752978; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=oiTqZfHoHoeBGnqeqSO0b2VdvRk2sjq5+PSJaOuL1J4=; b=DmHHtJ+MYCJdNH6JIU0KC553fLk/9sAAgAovImFzpQ1vMzLklTjNuokU5eFvCtdGzQZ5BC YmgpNV0YYjKKne8RUldDaWDlJvi6vwV6W20qAAtIWLW3exBwh3/ozBNqAvkZXOOv9jOLvM HrLC0NGd3YlYNFICqYhbuJI7yb8VQu4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1714752978; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=oiTqZfHoHoeBGnqeqSO0b2VdvRk2sjq5+PSJaOuL1J4=; b=iFUIqD0Ijr2dnAw7WNVSjNJUdzuZdNwFXAVyezKDbdLRK5P3NHxHjrQ+jfEG+j8O/owkEd tmRkXYZZdOyZK6DQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1714752978; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=oiTqZfHoHoeBGnqeqSO0b2VdvRk2sjq5+PSJaOuL1J4=; b=DmHHtJ+MYCJdNH6JIU0KC553fLk/9sAAgAovImFzpQ1vMzLklTjNuokU5eFvCtdGzQZ5BC YmgpNV0YYjKKne8RUldDaWDlJvi6vwV6W20qAAtIWLW3exBwh3/ozBNqAvkZXOOv9jOLvM HrLC0NGd3YlYNFICqYhbuJI7yb8VQu4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1714752978; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=oiTqZfHoHoeBGnqeqSO0b2VdvRk2sjq5+PSJaOuL1J4=; b=iFUIqD0Ijr2dnAw7WNVSjNJUdzuZdNwFXAVyezKDbdLRK5P3NHxHjrQ+jfEG+j8O/owkEd tmRkXYZZdOyZK6DQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 0B6AB13991; Fri, 3 May 2024 16:16:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id Txw+AdINNWboOwAAD6G6ig (envelope-from ); Fri, 03 May 2024 16:16:18 +0000 Date: Fri, 03 May 2024 18:16:31 +0200 Message-ID: <87bk5man1c.wl-tiwai@suse.de> From: Takashi Iwai To: Richard Fitzgerald Cc: , , , , Subject: Re: [PATCH] ALSA: hda/cs_dsp_ctl: Actually remove ALSA controls In-Reply-To: References: <20240503144920.61075-1-rf@opensource.cirrus.com> <87msp79b7o.wl-tiwai@suse.de> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-Spam-Flag: NO X-Spam-Score: -3.30 X-Spam-Level: X-Spamd-Result: default: False [-3.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-0.995]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_FIVE(0.00)[6]; RCVD_COUNT_TWO(0.00)[2]; RCVD_VIA_SMTP_AUTH(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns] On Fri, 03 May 2024 17:31:15 +0200, Richard Fitzgerald wrote: > > On 03/05/2024 16:17, Takashi Iwai wrote: > > On Fri, 03 May 2024 16:49:20 +0200, > > Richard Fitzgerald wrote: > >> > >> hda_cs_dsp_control_remove() must remove the ALSA control when > >> deleting all the infrastructure for handling the control. > >> > >> Without this it is possible for ALSA controls to be left in > >> the Soundcard after the amp driver module has been unloaded. > >> So the get/set callbacks point to code that no longer exists. > >> > >> Signed-off-by: Richard Fitzgerald > >> Fixes: 3233b978af23 ("ALSA: hda: hda_cs_dsp_ctl: Add Library to support CS_DSP ALSA controls") > >> --- > >> Note: it would be better to use the control private_free to do the > >> cleanup, and that is my plan long-term. But that is a larger change > >> to the code. > >> > >> I like to keep bugfix patches as simple as possible so they are > >> low-risk and easy to cherry-pick into older kernels. So this patch > >> fixes the bug. Sometime I will send a patch for future kernel > >> versions that reworks the cleanup to use private_free. > > > > I also like to keep as simple as possible :) > > > > One slight concern is whether cs_dsp kctls can be deleted at the > > snd_card removal (disconnect) before this function gets called. > > That is, snd_card_free() of the main card may delete all associated > > kctls, and may this function be called afterwards? > > If yes, this change would lead to a UAF. > > > > That's a good question. This is is safe for the cs35l56 driver because > if the soundcard (or HDA codec driver) is removed, the HDA codec will > destroy the component binding in its HDA_FIXUP_ACT_FREE. This will cause > an unbind() call to the amp driver, which will (indirectly) call this > function to remove all the controls. So they will have been removed > before the soundcard is cleaned up. > > But it turns out that the cs35l41 driver doesn't clean up the cs_dsp > instance in its unbind() call so the controls _won't_ be cleaned up > and a double-free is possible. The firmware handling in the cs35l41 > driver is strange and confusing so I'm not sure whether this is a bug > or something necessary. OK, then setting kctl->private_free additionally like below could work around it, I suppose. Takashi --- a/sound/pci/hda/hda_cs_dsp_ctl.c +++ b/sound/pci/hda/hda_cs_dsp_ctl.c @@ -97,6 +97,14 @@ static unsigned int wmfw_convert_flags(unsigned int in) return out; } +static void hda_cs_dsp_coeff_free(struct snd_kcontrol *kctl) +{ + struct hda_cs_dsp_coeff_ctl *ctl = snd_kcontrol_chip(kctl); + + if (ctl) + ctl->kctl = NULL; +} + static void hda_cs_dsp_add_kcontrol(struct hda_cs_dsp_coeff_ctl *ctl, const char *name) { struct cs_dsp_coeff_ctl *cs_ctl = ctl->cs_ctl; @@ -130,6 +138,7 @@ static void hda_cs_dsp_add_kcontrol(struct hda_cs_dsp_coeff_ctl *ctl, const char } dev_dbg(cs_ctl->dsp->dev, "Added KControl: %s\n", kcontrol.name); + kctl->private_free = hda_cs_dsp_coeff_free; ctl->kctl = kctl; }