From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796324487; b=rhK/UjvzrTlTVSEXqWip1R5oJT+3/CL2xwi9cm7M9R1Q0MgDXanpIwLp5qp3iIzwub2u nrYnWVT2gfWzhUUucMLhzPUGymNtFdlLCG45wZML4fu9k8MQvHcEIUfqNRDYPCRbM56OA 3WfPQFVkCD+0p5huFDXPU2GyzXkeanZRcjWpKRmtkycJlt+gqgL3oTNL79Z1LoYIeTZ9Y Vzu6DDu/etpG5kNBpZsc/HjitjoLECV3GiRCZs6Kwg1FT/UTHu/VNngYX2QbGZhowyPmc IhUqQd/rCIiHKID2VhYX/7VxjsEOeHcADnaEp8H282z00MR8EQAG5kvD3PnSgNvtCFQ== 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=OD5tm+RuNMIhIIHoU8pEqjITI6WtTsFtJamMHwhZnNSh+PPUWDpU10PmSTMR4G2lLUh/ Ruu7eW3ryFuoR+Ixbmt1ZI1zslouIDsbhiFe9Mhbd+ZwSs6+lEGyEEu8fqvTGi5kwx0H5 jcV+2hFKQMqtQCjn0+NDf7+mkz8SRg3joui03Jeckk8p7WDGyB2j3nnGAlnzZOWnWplTG iLhcgeJMNvfsZKcRl3BiZ3QwSQ/NI8uY2wjnIP9NzX4im1KEgJLtwv/oTUTlXXACJM5UN 61M/Ewf3LIckmfmJawhzhXQL2Cq0stwVof0wYM5AbiSxlgFPKs1xZ4nz2kR+AMEo3cw== 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.46 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (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 A5DDF606A32F for ; Thu, 3 Dec 2026 19:01:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A5DDF606A32F 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-f46.google.com with SMTP id 98e67ed59e1d1-3b43d30822fso94292a91.3 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=qgDDemWOGCTzm+NH8LJ6pMW8k5yXHkkeBV9xlErrdXw0BPNKlGBuB60BzJN2H2bkbX f+5ipgHV3PXKsUZM2GZsZobZ+uA/BPZwvVYPhhqan1Zc2TD9J+A/jIow/G2LznO/cI/o vPSjTzBSCpcug7/ep2+VEnXPtOoyrVpTdrjaRJ98iFKByFYt0BXuY3CufP5ggAXR8kg0 xFSH9ostuDIfF7NTmAsaWXjN0z4dTh1KAv9asWxgKHhmdw+UaOyJgeelDB1hskpregSb RnycpAz79Fe0HjC+e/5YmVSM+jKEe/KDa+2X9abqoq6Hz1vt1nyX+o/MVgTSCMG21D5U KkJQ== X-Forwarded-Encrypted: i=1; AL+hErE9HdjsDYc8DqxfJBcIPc5L0V1INTMquXN/+g9wRJ4eOs/imxnyqwxCEV4RW2b39YXbIuL7H5GkXpm8kw==@vger.kernel.org X-Gm-Message-State: APuU4Z9HuKEji+Cl972LBDraWqaBMrBS92GDIQzUgb87I+iiyeQHDx5v u1CQpKLDRIPEdc5cnYTqaZIlp2oXJyHu/umiM4uQeOGFuyIJ6MEWJC+Q X-Gm-Gg: AZFdTZe1y6O5zWizkZUxe/TuzemTdCtZPGYRSm1v6rTYEaZHPvJng32DLtAXNXVr4T1 JGleeDBEQVWD7X5uJtJqMoFAwtG+W+LuE31DQHNldPKYsjyX2yn5Rva0f74LVEGC/tzQjMnenKL ikwmmdoiO5IpFE6/gUOJfgQFS+fM17qYk7S71jgEuRwtoxb6bQzLZu1idrxPZRuYESkxBJX3m6h vPPzgJBMTbmdO0hflohYFZExTCJrsAhkYkqpm26AJiNRQMkgHD0xKsNdNTUr/9DO73dJp7ykR/+ nYa3sN8Mzjnd90oPOBfZA4oy6hJDlfOPhsj54JYPRAuWKMz4VcbhpoookJpHkFTJZ/0ZxuEkt20 xO/oAuXyfniCDdL+9uRzyEF7UzmWQMU1UOVxG8IX4dBQoAuF3wotIX04PFRCNC2/v2iMdthMkfF x4gF9UT10fM+dpQFaCVIfIIdzVo4anWqtjz1eL6gAyzu2y0qqxHXPeDJ2x4ZqTuM8LWF1JUXSx6 nriUItslOn7y/NM9gcFbLBfBoC8nc5LJTudRW7S6z1qtIsOQw1mBTXDbGbhGu2pz+xGRbzMNnM2 Cz9y7B7GA7nebBQ= 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: linux-sound@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; }