From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385017; b=RhOg6n0VAldtdQgDwBuPgcos8zhyGsRb1BG/Hg4mpjGFRMG2Ayvtx2o5XxkvRrS3E4Zv 1KBDhLsO0Cooic6mgk5AkjlGSp/ssSDor1ZCjthI6JJIa22Fek3YoRFYccHTzYCt1EUqV AUnFhuszg0hx9IdYMzCuWZ0Lz7m/Ei5YlNX3qYKhcB8gSlrAQTi5pOMIGmG3bNEdDonKb xB2wpzbL1qQpNZ+VzORQRmvJC7fGDhsnL/PjlLuZ8vmjcL2rKzo+wEWI8ODV5NpYy+Nb/ LtjU6CNBn4wRkesoEVwYKib82sxYKmwtCmjsVGN8NC/YM3dnKBIa+FABlhF21aT6AXg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385017; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=s/bFUn7/5EtaHAFLDaQcjYoRXX1g77K1x2aSgTxDzMQ=; b=aiTSfoMEs1klktpbF5vDOOXGlZsBjadBCxbjIGP/ek9edc32UD8eGAJFA9WJAsN2pYES 4y7FHrelW5h4dJSBLO3dCVE3aRbi4y2BQjuLB8h4BA2qdfflhlYo/yGrTMmmmMh4i0ZuS J1Ig+VxoM8V5UIZ29XgzNShfTO2tdiEhNjFaO0rNFjs/6mcokkMiVPSDPkdoTQ1bmMAct ciujM6frFUzzSwK0EjWhVkCaNdK1OukjUkCXPtIQY1Dsdl9CB4xoouh7EXlBRPsGfcUQO 8oOxOEWuhvUh6AJCJgexCmCLoG6O1oHwWE0SZyYiX1y4x+rfRwY4MLC7s5OeDRht92w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=1GPhGZoo; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06229606A339; Fri, 4 Dec 2026 11:50:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=1GPhGZoo Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2937A1F00936; Fri, 4 Dec 2026 11:50:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385016; bh=s/bFUn7/5EtaHAFLDaQcjYoRXX1g77K1x2aSgTxDzMQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1GPhGZooHNl2nNqqLQMQPZyEN2q8zQxohkoHLctfcgghBNeJxpsYlr7+QEcCzcNMW 3mvRlEFRMNFB18/q94mqYJzmscPWU+9IqenoO8Ut6FTPWEYFDUk/iat9b3lzicOU3v xiSMNO4uKgCUvV3SaziSD+cW2YrpDHGjAziJnIgQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Takashi Iwai , Sasha Levin Subject: [PATCH 6.6 0386/1167] ALSA: hda: Dont free card at probe error in vga_switcheroo handler Date: Fri, 4 Dec 2026 18:56:53 +0900 Message-ID: <20261204100712.075035549@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Takashi Iwai [ Upstream commit 7e1ad3c55baa80399f1727dfd2303fa4d1558d9a ] The vga_switcheroo handler azx_vs_set_state() calls azx_probe_contine() for enabling the audio, and if an error happens during the probe, azx_probe_continue() releases its associated sound card object at the error path. The card release procedure includes the call of vga_switcheroo_unregister_client(), and this triggers the vgasr_mutex lock again that had been already held by the caller (vga_switcheroo_process_delayed_switch()) -- leading to a deadlock. (Moreover, the card release will cause a potential UAF at the error message in azx_vs_set_state() since the card object is already gone; this was the original report by Sashiko.) For avoiding the unneeded crash, it's better to avoid the card release in this error path, so we make azx_probe_continue() behaving conditionally. In return, set hda->init_failed flag, so that any further (re-)attempts will be filtered after that point. The check of hda->init_failed is dropped from azx_vs_can_switch(). It's because otherwise vga_switcheroo can't be switched to turn off GPU once when a probe error happens at the audio side. Fixes: 39173303c838 ("ALSA: hda: Free card instance properly at probe errors") Reported-by: Sashiko Link: https://sashiko.dev/#/patchset/20261007213728.155092-1-tiwai%40suse.de Link: https://patch.msgid.link/20261007223448.172443-1-tiwai@suse.de Signed-off-by: Takashi Iwai [ sashal: added a free_on_error parameter to azx_probe_continue() and updated azx_firmware_cb() to pass true, since this tree still has that third caller. ] Signed-off-by: Sasha Levin --- sound/pci/hda/hda_intel.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index abef69c82a645..6cf99154e528c 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -1178,7 +1178,7 @@ static const struct dev_pm_ops azx_pm = { #endif /* CONFIG_PM */ -static int azx_probe_continue(struct azx *chip); +static int azx_probe_continue(struct azx *chip, bool free_on_error); #ifdef SUPPORT_VGA_SWITCHEROO static struct pci_dev *get_bound_vga(struct pci_dev *pci); @@ -1205,8 +1205,10 @@ static void azx_vs_set_state(struct pci_dev *pci, if (!disabled) { dev_info(chip->card->dev, "Start delayed initialization\n"); - if (azx_probe_continue(chip) < 0) + if (azx_probe_continue(chip, false) < 0) { + hda->init_failed = 1; dev_err(chip->card->dev, "initialization error\n"); + } } } else { dev_info(chip->card->dev, "%s via vga_switcheroo\n", @@ -1245,8 +1247,6 @@ static bool azx_vs_can_switch(struct pci_dev *pci) struct hda_intel *hda = container_of(chip, struct hda_intel, chip); wait_for_completion(&hda->probe_wait); - if (hda->init_failed) - return false; if (chip->disabled || !hda->probe_continued) return true; if (snd_hda_lock_devices(&chip->bus)) @@ -1740,7 +1740,7 @@ static void azx_check_snoop_available(struct azx *chip) static void azx_probe_work(struct work_struct *work) { struct hda_intel *hda = container_of(work, struct hda_intel, probe_work.work); - azx_probe_continue(&hda->chip); + azx_probe_continue(&hda->chip, true); } static int default_bdl_pos_adj(struct azx *chip) @@ -2059,7 +2059,7 @@ static void azx_firmware_cb(const struct firmware *fw, void *context) dev_err(card->dev, "Cannot load firmware, continue without patching\n"); if (!chip->disabled) { /* continue probing */ - azx_probe_continue(chip); + azx_probe_continue(chip, true); } } #endif @@ -2305,7 +2305,7 @@ static const unsigned int azx_max_codecs[AZX_NUM_DRIVERS] = { [AZX_DRIVER_TERA] = 1, }; -static int azx_probe_continue(struct azx *chip) +static int azx_probe_continue(struct azx *chip, bool free_on_error) { struct hda_intel *hda = container_of(chip, struct hda_intel, chip); struct hdac_bus *bus = azx_bus(chip); @@ -2416,10 +2416,12 @@ static int azx_probe_continue(struct azx *chip) out_free: if (err < 0) { - pci_set_drvdata(pci, NULL); if (hda->vga_switcheroo_registered) dev_warn(&pci->dev, "GPU sound probed, but not operational: please add a quirk to driver_denylist\n"); - snd_card_free(chip->card); + if (free_on_error) { + pci_set_drvdata(pci, NULL); + snd_card_free(chip->card); + } return err; } -- 2.53.0