From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796324487; b=RQ1D22HaZUhX1KAilLA7W+KgceuUd/o/d3y5ra9prCNNwI/7djhRZCw7Q7cecZmwmkFG JzSYGQd+Q/Ee26HVAM30jZeUEt0frlPUoJc7LURo7/p+oAreD0Zvk+cz16I8+NsNnUBLn diWcWydlGtug9fh/LIdGFNanhFZulRYTMCW+gawK5qUmksCAyvapfzhXrBln9hC92aXv4 bg56yDIcoG5hK8DiICAmIqq47ciEiaf4s7BKxTI8CaOF189MUmKaWZoDrMJ0YZKYj833x GBYW01w3gYzyVz5U+joVrVNvzPJFh/Gse3GVp07tISc7xk6P/GmMMJwpZ5N6K/KuH/Q== 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=rnbhlp74ABxrsjVGgdJsnWF5lZbs/p1t5ZBzixczQKCDM5dOai/grRwHEUgrboSHaC7j npRVR2L8DBm6XRxcYQbQOwNwDozf2L/lf6kRleTo+s+PnBPC5pd2fv2ejIU7l+DpGcL4U lRm7BJthAQt5Gs14H82IWeOM9+LofaQdKIT+XC7ZwKaQY3U4fTY5lweF6lfE5hTemmd34 InKBSgMjwojyqqyuOqeyQ9rpj6A+xIYAfXYAbkrHMCgkWdnXacqqkY5SfrrcyFC2cmqVe wYmWrgkj3NuUFR8UbBrMT+VZvwmUz02xrrvsGX/8bLDCyqaWlMXfYMkMk8KhTJLBR/w== 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.45 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (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 99030606A32C for ; Thu, 3 Dec 2026 19:01:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 99030606A32C 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-f45.google.com with SMTP id 98e67ed59e1d1-3b43d30822fso94289a91.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=XE9Yt+azkkXfkRCNAo8Cl6E3KP+7c+yzrDvnHC/VOMlKIMhjYEuqMQ+EaAzPZ6Mi+d WGu2nzV3UnBMpK8yIQzbBPmEcHsaFK5g2mO67NGd7Ev40JhXC9Z6/Z2YyTL+D0PUS01I M3dqqyXz2ryjFr+vImivkO9VNYM2OYSnj31Iln+yZW7WKgTRKCiCyRMHg62tL0hhv+Wm lv7bjc9xUimZfokscXLqlpoKPsqivsxcxzQq/vqFbcnz7TB9ZfNdCFfi1xBhsSyVx6ik PlIq1M756tV1SaTR5zSPP7UdfV1QAp0JIXkXUn6FOTyA2l5sOzDObybTM22e0c+fUKDi Wp3g== X-Forwarded-Encrypted: i=1; AL+hErGGpT/Op8LKqL42K+vriWxGZ/i7tTyyrec0mInri19mTn9+R7qwmXyhhpJroo85JBJIXFVFXAuwc2XZ778=@vger.kernel.org X-Gm-Message-State: APuU4Z/eH6u0attjCZhZqxSDpMX9fKsRevdCl1XCqd8gj+wu58iq//Vi FXUuDrU8mcUWowoZPglRkZSK5LD9SKmXNLlpJzIKsMEhr/zV1Xa5x37o X-Gm-Gg: AZFdTZcsxLCgGDrGLDUPKjNRwDHU/HTUq3+T5dyJVLc0/gGczxi/Vws+GN0xwVOk2NV /v8quwUpADax5gKb03zl7bWm2T6dKCqzvS89o462UImHUbnGyAB3nPGBfLIZgX946c81mWAiT+X 8kJKhNFLZcK2hBMt1vk3jxeyvVVgFV1Ej1dDc/nmGlxOsEXEVgO0zgUZfAZS0PCoirmPmX2jsRh m17NrDFbywlgpHhdKQvvgpi4JzL10mpWvzRybaTwf4tyfXXt+r1sWjVy5RwO6F+pyt1tXZ0pKiF 4V+TUyE95YfOgJLe5cxp4UANVeXPvqnrxTCuXxKdyeL+1knevobT4i/WL7cbxBdooHHvpNaQ/l0 0W3LCBkJzcpCGY4eA+2owp4mtfoTTXaR8mDC1qKJlc0YDgv+h2A2Q5nFg/yJ/FFllczkWHbEX0A 72wUNfy72DiQd0G6TiK49ad4n+RmxoE4UOdp6xZ2i/yikru4k7Z9B7XRMJwtNQ5AQQoQlypRSHQ 31uJV7I/URc1eeivw0boFu39fdREoQ4BDdH5ZU+v4ZR5hNsQ2uWpjVMxaG5QIDrKlaaldz8QWCe btkgmCpR7owOXqE= 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-kernel@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; }