From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796324487; b=g+jfLXZfYs+CkMPOZjnHsTfxYB0a6g3a8Tf4CUfgo+8qREcQ++1v5i2IP4ruuV+y+tvU dIh1PLQfpeGAqljwRfW0SWC1z6KpvhTLhyWd/9jbS0ijOBuZ14e8xLTfnNgK7Xcfb0vB/ e2J3vrNqKyqUxRSLoXmE2WcoS5Rb0p9gDXejqS7NWCSsJQyAw4ZSxun7VGPRf7R8eqg0/ RRML0Ysfjom7nC/PEyPPmYMAynNQFHXRi3XWynAsgWAYIKO64b7oPfMgXLWdefjtbzmsD 9SLsm4Fwi/caM9iiRTtCeAFHrGHA5DYReLB31toFzUz52AUejqsHWbJfaQTNqmKPAFQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796324487; 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=sfKofvP50UUF9ZZpS1UARHR3vRTr4XGPizNZcuET5Fk=; b=wg8ZnmxMx/yS8GUf+jXxysgAGMlDLyTg/L/qnYjIKnt/x/7mK47mcP7p2I1ocboaC/vh UdteepLB7bn3X8FBDnlbKlfhhZgBozri36adYhVsAo/mzOzGZcyc3jtKJ88/T/LMRxNa3 m4Tbz4IYHjcP0WEkaVz4jKTMa2lYpSrTnvZQWSZS6Ix7aBfTSe0YpFoUjqn7GA5DWactx eor0jD9VDO6AnZT9BdMcGoMp4DSonwjhUghqZH1lLygvV6p5DD++56UiY46dBAfnTHj3k PhAD7dc2YW6L/d579MFLfT34TLKUVMd5RrBLjgdj1pLYOhpX7GLQ6L8/tmadupWzH3A== 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=szTiW7o4; arc=none smtp.remote-ip=209.85.216.43 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 A0212606A32D for ; Thu, 3 Dec 2026 19:01:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A0212606A32D 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=szTiW7o4 Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-3b567ae3c66so94596a91.0 for ; Thu, 03 Dec 2026 11:01:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796324486; x=1796929286; 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=sfKofvP50UUF9ZZpS1UARHR3vRTr4XGPizNZcuET5Fk=; b=szTiW7o49EkHBbgbOvNHjyzXDlOYsw4oBIthSO5xRVYbrqMD/A9dlLqSukiS8/8ZrJ tkybqpKy02dZDFDR4lMqyDJyrZ7ph3ZZv6lxTCQIpEG85ZcutNCaNF0ta/BfaboFrf+m EuJq7BVfdg6CJl09UZjWQL0VTy2k8G4nkWsdrBDu8mOzxeTPNSPiRUGMsqa4QehE9T0Y BVOjqT2gmcVnRPDe/gL3KfEJWcSaNEeIFhXQA9oA3lLyHQNjyO/K9MCEUTGziwaheEDT e5gULqJN8RR6SBHcasznyH+38e1CFj9+zqGSkbtwYTLDzf14R/5uA6eMnmKkiyigPRUq uF8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796324486; x=1796929286; 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=sfKofvP50UUF9ZZpS1UARHR3vRTr4XGPizNZcuET5Fk=; b=QMd3gIr1Wum7QygBHsGk4RJVlw4tT2AwIWrNQ4C0Pb3TrhvMUiM/yJxL2oEsk8Ig50 EjfgjaE6pEJlAkTAWGGbby/GQEtsb+ax/z9TKnjunqtW3HvtXVHeGVNVugiJhyxx9AFx 96Q9vUgvwZf6B1zvFebWXSAC9dhCTEwae9XW7mCLfT5exb+HQWMZlpGlHnF722eybNWO 371/IzeSEARd38GaOm3ZSNv+TidJTfvlu4mKOWbNAk5hQF4b8unlF86c31GSG8gotbfY jqMRgycwlySlF1c0E9FATjbTBeu91cesstxKRqEhZtMOOYqRMZLnCQ106KPmjSJEKyJH rGlQ== X-Forwarded-Encrypted: i=1; AL+hErH4aJEa92PkfwwUimFOqxXJLeZJtZZ1i5f+1UcOd/v2h3F+YlVqEdwsOHf9Kwc4pNSYnqdbQeE=@vger.kernel.org X-Gm-Message-State: APuU4Z+3uV0nPUZLaca0+dZVVZpHG5qH4Wv24r3sd13d2j5Z3B6af9Rx oTww6mSX/eKpOotGtburezenOhYIIHI6isdbvy/S8XpPctaZqAf2E/rs X-Gm-Gg: AZFdTZfk1n8aZyHYixTSbL55dn5v+Sf8scbk5AMk2JHQnuawRKjr05aKprpaTaGAsBD 0qgfAto5iJmVFysSqw+Hozs33QVEBHtlohHfGkLKghffayfARE73JiszCiFQH33FXD/XsAPG/Mg r7YpEGkL/SS7gIOmMpEO3ELf1RlJbQS3LCM1FN6C3SRKyX6CJgendKzbc1BwT+Sf296iLUxbFxX OlsR0XTTI0PJeipbORfi1VHGJvr5D3W3na88P8RWp7v8ImscF+l37w8ilZhmbwrN+41FgStR1jt pWbRncIpIZzuJE8o0M7mq7CrfXrqqIeopJ6YN/fEymhF7Ikjld+UqqtL+WPpVzKxSj768saCtrm n84k6S8QkX/wL9LSNM7icRVVd/QsJsQL4AZcRweCo8WbWCI0UbEuV7xTIonrlCpDIaA9Oq56GqD 11BjkbgiuFXvXjwEwA0VCkJ7bWolizcj4bbKg43xqlH2DKLOpI7E8/9X3LlVS9NTBbpXDxVyTTn uNCy211ZJq8GbUWTlTyYfN7/MH3iQKbEdZL8k40COPSqbP4MdaQ14Nj6V8Ca8jbaY+jAy0vxvkC 7CQ9J+CpsXBY430= X-Received: by 2002:a17:90b:384b:b0:3b4:fcba:8c53 with SMTP id 98e67ed59e1d1-3b4fcba9699mr29650995a91.21.1796324485668; Thu, 03 Dec 2026 11:01:25 -0800 (PST) Received: from dell ([58.246.183.50]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b44b7c6513sm34521833a91.4.2026.12.03.11.01.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 11:01:25 -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] ASoC: SOF: Intel: hda-codec: fix double put_device() on registration error Date: Fri, 4 Dec 2026 03:00:51 +0800 Message-ID: <20261203190051.456176-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+0xc6/0xe0 Read of size 1 at addr ffff88800e15803c by task insmod/342 Call Trace: snd_hdac_device_unregister+0xc6/0xe0 hda_codec_probe_bus+0x4d7/0x600 Allocated by task 342: snd_hda_codec_device_init+0x139/0x8e0 hda_codec_probe_bus+0x2c9/0x600 Freed by task 342: kfree+0x154/0x420 device_release+0xd2/0x270 kobject_put+0x1b8/0x340 put_device+0x1f/0x30 hda_codec_probe_bus.cold+0x1c/0xbe followed immediately by: BUG: KASAN: slab-use-after-free in kobject_put+0x81/0x340 Write of size 4 at addr ffff88800e158038 by task insmod/342 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: 9c25af250214 ("ASoC: SOF: Intel: fix page fault at probe if i915 init fails") Cc: stable@vger.kernel.org Signed-off-by: Yuansheng Yang <0xbeac@gmail.com> --- 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; }