From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796366854; b=1PvIsnLlHwyOZV9JXsaeXDbRd/ZO8KHl61fk3H0QeV0djTauzsxmdF9hH6XwOUcIf4qL fW+bzMfJDv8wmfRWQpBjpVN3q/jkBlGyAb3eCg1l+HU3bce94yKMOIMa23LKKSJT1J9HK KfTAGYrbdrv9fyvuLoNnSVYE2wcN2p26wnwp3Dvm7HpLXHIx2sfocmQQcAqrtiPdZn635 RZ1pLrezfyAGz7s25Ppc/ak/ZpE8RPHG8Z+aauwkJlQCM3pHOzAkSF8Q0srFbhBN21+ki 2EQe8/3MwHSsp0h5y7e39r4MO42YpVpOj5d15u2zUP3H42IPy/5Ix3bbEuSiUDonUuQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796366854; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=7v6lrVb9q8Y4IRLG92sfoTZjz2AQiXvErjF8UcL2j18=; b=PezzgU5HTiXquZYq0ajINkIZoVTzHGgmFJ55b6az4/BMliUQ7OKPCAZ8fELOh882b43q 5KZ0tEEljUNo1C5XOEPyTa6PdQKmcyBzAL4DOhnuoE2g1xn+j87Una63ov2FZXxYqwENI WubX8vBy1wC12jjXbuhivM7Y1biui4drcmeovQ3dJuvTTtfFVs5OOK+xDEinhPCXiVpxs kKKlhV4yME6PPwySZc6+8nMnAbccAR/Z/wL4SofwJXVekqr//pmjQiB0GBGnb/IM/5HNK x1To/UXakdzWIwYDExos+dBNm3tNIegyQo/eaCoEZc/xJJtpDK8GcWV8yXCACWGtGaw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ZHeI1cMh; arc=none smtp.remote-ip=209.85.214.179 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2901C606A32D for ; Fri, 4 Dec 2026 06:47:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2901C606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ZHeI1cMh Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2f041f88577so4236415ad.1 for ; Thu, 03 Dec 2026 22:47:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796366853; x=1796971653; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=7v6lrVb9q8Y4IRLG92sfoTZjz2AQiXvErjF8UcL2j18=; b=ZHeI1cMhMtYfrysfaprR3wxWMdAfcIux6yoDVDwrcEpRqgRFIGjloYT74ePc2soCiB Nhb+rmSXW2bFj8lvMBxg+z7VoHjbSxE5JLuNN84B3EMu+sD4SGsTWxroPgwBHLRX8hmY uJ6TICNEqlSvXqhwljvGoLz54ZqEXFw29mjMzG4Y0cm999Nyy+wMPGSGCzWPidMtPAiq 6VIrDeA8oLWgucYMRwMc5TRBvRmMZC1askCjfb24OFt9OMnH+ULa08pgLtXNWkwqbAdG Ur0K1rj6VKoYM1kqUqNrZ4ixVcADISHLfxv3+xfqXtr5mN/q22dr2dDObd42ZyLPaojZ gpNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796366853; x=1796971653; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=7v6lrVb9q8Y4IRLG92sfoTZjz2AQiXvErjF8UcL2j18=; b=lE+mxs6DXuOpwz0LPoPjqlcUCmVUirImSy9pzgmzaWyQCCwTY8AREGiNSxGictJpVa bnKMYy8l4+x82wReHI1+azh6kXp9moO2z/yp8NO8VKZNs+qtFzrrsq43dTRIIUUNK4zA IKU8AswE/UFuJmgOGphZboMVPcGn+ZeYL5vGSpSsbm+Rh3O1TABDxziM1mjrLN3XDNYb WaRCHnxAyTdfMNMxXmqOkwph4QkRmRStSNpiv2icvpXPJ9997FHfVxyXvzkSvZpFlzu7 s8YOoyICS9NiP6861WLs3NpIfXk+A8jKhrNUyUm0XcM5VXcOXsLTznB7Ju+K3mSMMmQC wA7w== X-Forwarded-Encrypted: i=1; AL+hErHIUAdHH/jFCBoBv92QcC3/kY7UGX1Pew+r3ITPbLg8zzy2vQLISnAUR2cL5gslXDPC1u0Aae0=@vger.kernel.org X-Gm-Message-State: APuU4Z/9qJED04IETGA0uMCPQmfKtMwcxWgGndAfyikYhx+nsH0lQ7aY TXl61cwpPch/p3Ep6orc7YMCeGyYTE9oPq7omWHf8nP6yfmfx8jF6deT X-Gm-Gg: AZFdTZcjOq7DVyOFd8yA0q32HRlwjrlGtkzgbUNPCHY0/RM957gHLflB9UW6MlRlgNh YGspWBYuqcSrxl9U4QSeJPs7ooxFvngh2dwf2CekHPpZOlNizkOgF1mARvgIQ3bT4Vdm868iI+K ypKtk7suBkz3QT/ilZFU5YviX8bWA+wOUBIZPSSWqfNYxsimVntGMEgLQb5hlmj+G4exftd/eSu /6+fGByGUl7WC7FuPMUgXdfkEKdO0TBNLC9P8i0bcyuqzmBNn8ge2uJ7d1phx9XJM+17j1mJuPl ydiLberMDiOpprruQmNCMft196hSKu+IblSS7yeJlaobD0Ksf1EtYQtwK6+Jet45DHYFWIgFUbH gNLwpaR5nydbXpPyDoOxX3oQDgy3KZi1H5VOoVXdqRNZ1DUqn/ZBf1ehgWlm4CyGKQTEkX1Y3GE OPCCI/fvyXvUmkUMHSF0IW6+9ba0anvqpj2+t1hNkNW/THOI5udtnWvg9TclhMeVjFN2go6pXa9 6Eriib/hXVNr+HStn+KxZI29yKTPvEmqgWq2R/CFJuwKlbz5wRGYBNoskjZEHkKt2Iol89UjjS8 FGt2lHAUiJsNHd4= X-Received: by 2002:a17:903:1904:b0:2f0:3c38:9133 with SMTP id d9443c01a7336-2f1ba1ca3c9mr8970895ad.43.1796366853235; Thu, 03 Dec 2026 22:47:33 -0800 (PST) Received: from dell ([58.246.183.50]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f1b78faa54sm5893565ad.24.2026.12.03.22.47.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 22:47:32 -0800 (PST) From: Yuansheng Yang <0xbeac@gmail.com> To: Liam Girdwood , Peter Ujfalusi , Bard Liao , Daniel Baluta , Mark Brown Cc: Kai Vehmanen , Pierre-Louis Bossart , Vijendar Mukunda , Jaroslav Kysela , Takashi Iwai , sound-open-firmware@alsa-project.org, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2] ASoC: SOF: Intel: hda-codec: fix double put_device() on registration error Date: Fri, 4 Dec 2026 14:47:17 +0800 Message-ID: <20261204064717.851431-1-0xbeac@gmail.com> X-Mailer: git-send-email 2.53.0 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 When probing an HD-audio codec, hda_codec_probe() allocates the codec via hda_codec_device_init() -> snd_hda_codec_device_init() -> snd_hdac_device_init(), which initializes the embedded device reference count (kref == 1) and inserts the codec into bus->codec_list and bus->caddr_tbl[] without taking an additional device reference. hda_codec_probe() then calls hda_codec_load_module(), which calls snd_hdac_device_register(&codec->core). If snd_hdac_device_register() fails (either device_add() fails or hda_widget_sysfs_init() fails and rolls back via device_del()), hda_codec_load_module() calls put_device(&codec->core.dev) and returns the negative error code. That put_device() drops the sole reference and frees codec via snd_hda_codec_dev_release(). Back in hda_codec_probe() -- the sole caller of hda_codec_load_module() -- any negative return value enters the `out:` error path, which calls snd_hdac_device_unregister(&codec->core) and put_device(&codec->core.dev) a second time on the already-freed codec structure. Exercising hda_codec_probe_bus() in an x86_64 KASAN QEMU guest when snd_hdac_device_register() fails with -EEXIST reproduces the use-after-free and refcount underflow: hdaudio ehdaudio0D0: failed to register hdac device BUG: KASAN: slab-use-after-free in snd_hdac_device_unregister Call Trace: snd_hdac_device_unregister hda_codec_probe_bus followed immediately by: BUG: KASAN: slab-use-after-free in kobject_put refcount_t: underflow; use-after-free. Remove the redundant put_device(&codec->core.dev) call from hda_codec_load_module() so hda_codec_probe()'s `out:` handler owns device unregistration and the final put_device() uniformly across all error paths, matching how snd_hda_codec_configure() handles snd_hdac_device_register() failures. Fixes: c344ef36dbc2 ("ASoC: SOF: Intel: hda-codec: Delay the codec device registration") Cc: stable@vger.kernel.org Signed-off-by: Yuansheng Yang <0xbeac@gmail.com> --- Changes in v2: - Update Fixes tag from 9c25af250214 to c344ef36dbc2 ("ASoC: SOF: Intel: hda-codec: Delay the codec device registration"), which moved snd_hdac_device_register() and put_device() into hda_codec_load_module(). - Trim the KASAN backtrace in the commit message (drop hex offsets, addresses, PIDs, and Allocated/Freed sections). Testing: - Compiled sound/soc/sof/intel/hda-codec.o with W=1 on x86_64 (CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC=y, CONFIG_KASAN=y) with 0 warnings and 0 errors. - Verified in an x86_64 KASAN QEMU guest using a reproducer module that triggers hda_codec_probe_bus() when snd_hdac_device_register() fails with -EEXIST: before this fix it reliably triggered KASAN slab-use-after-free and refcount_t underflow; with this fix, 10 consecutive iterations returned -EEXIST cleanly with 0 KASAN, BUG, or WARNING messages and clean bus teardown on unload. sound/soc/sof/intel/hda-codec.c | 1 - 1 file changed, 1 deletion(-) diff --git a/sound/soc/sof/intel/hda-codec.c b/sound/soc/sof/intel/hda-codec.c index a2b2ecf1e..a0d97f4d5 100644 --- a/sound/soc/sof/intel/hda-codec.c +++ b/sound/soc/sof/intel/hda-codec.c @@ -57,7 +57,6 @@ static int hda_codec_load_module(struct hda_codec *codec) ret = snd_hdac_device_register(&codec->core); if (ret) { dev_err(&codec->core.dev, "failed to register hdac device\n"); - put_device(&codec->core.dev); return ret; }