From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 644BF31E831 for ; Thu, 16 Apr 2026 19:08:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776366536; cv=none; b=J8zKCpO2EwLPHPYg2xZZaieTAWsbQBdjNxCRF2DohloSSz/GscHs8lGp5PLQqs+gKCUO3VRHT050H4oCtFPaog5p/I7VN0nyqKBjXfc0RP6vz7lS8zuixuckEPRo3i/+5dgTgQKLNp8WFvxHKCDyKv4Iu1j6U6UEz6XMMGlm9N8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776366536; c=relaxed/simple; bh=YWU4FbfDf7vMVTLH3P6trXk4SPp9pGvljjdWS7yKFlM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hTpOUqJI3i48fbH8lBzlnQrROM4gd+wNOmNn6zOy7/XKw5RmrnFke8YckGZFiOni2YtubbZ2UsDFOiMhNIOp8kZ+hKOCiBB+WQxCfCZY9DVmPFNhwcr3m4ZISXvcAecZV8hITGg6ui2zHQAJC7DPqBwOHY8+aSfqYD2b1j7nuxo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JjU7JcBh; arc=none smtp.client-ip=209.85.215.178 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.b="JjU7JcBh" Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-c76d797b180so5338248a12.2 for ; Thu, 16 Apr 2026 12:08:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776366535; x=1776971335; 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; bh=tTMuhwzBxIhaiyIAasTcZNIFxBe8TdNJyeKGh3etW/M=; b=JjU7JcBhihQv4pgc2ENDt1rqNnbmj1aMClJb+xG6gui7HstVPkG1rPdbptYztfXbFt M4gGpygi3RF7siit//a9qxNp4nwZ4lJoU8+9EcXauhtp+wDopA3cxu719sm/Otc0HLYy UdHv2dR0s9UpDqnncKFEqB9ILR3Dv0c+B+y3fbGUcUaCLy9jouh9sjDI9q4pF15byINp 0vwSqjAbUzweYTa7A7Y2mX9bLLEIeay8xjuXjKw2i6jKx8HRID6qy6AtQfsM67en+Tou FuV0lvNnBKSocQsRvOH8gStWJmyO4cyXR60KJya+PEKFaySDGVo6kRWELBa7Xs7V8lB8 BKJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776366535; x=1776971335; 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; bh=tTMuhwzBxIhaiyIAasTcZNIFxBe8TdNJyeKGh3etW/M=; b=HA8Yir5ubqOHzY1csqsrB+5u8uXahbR2ZJN2DByF38cpHhRRh+nxS0uib086Ljt9nF VYk06bs1bWyDQiMAK1LOeySHTRBO5w+Oyc87WzBbHTWATAQ+b+G1eGKnzKbErZ6kRp75 bEt5PHyclPgTeFNVMYpwrnX3stTG35BadECb7l295VGsZVKxR1UY9xOXho0oPmZZ3saV wjJQ++1fSkUXyP4oM1btbvegNyMCTBWYTXPPEQHoHYd2DVkPXGTn1owfNcs9l4O4uiSk f4EAHRD0/HZgzucGwakbNW0T8aC2aLfNc9dGcMjxZ4lNp6KiPzQZ6U2b3mOBQEGQ8YzO BiVA== X-Forwarded-Encrypted: i=1; AFNElJ/hdqINKVsKrfCyeCq3qriszwWJ4Hv2HsrIs9Htbl9HyiJ7HGf0isgsuzFi3D5oz89Xu2uaHfOAj2HH3NY=@vger.kernel.org X-Gm-Message-State: AOJu0YxzEdHwbWlaYzLS/gse63cLswSMc2upQbmu1GEpCRWbX2AWWAj2 N/gnxlqD6f3SMb76uj3HhoDMZqqxyD1Gn99kiJ+VTK5MA/JLi3Lb3LYP X-Gm-Gg: AeBDietm7KRsVMuxDqloSDAWsrccKpTDxUMozqkB9srlergDrYtrd2kKCO8GSANQPom cqsvr3MypwDAOSWw3Q8pqTRdKXSNNeYWDToHCB9BFzoAwUVEWxT8NJ/RbSR6/qlxFaAnUusfpBm YXA/SCoB9JMQ62QMp8rM8antxq2cGny++uScoOWEBANNQ/rVio0wpnZzyNhLZYACo3+mNTUr5jj fHmbBXCM8V39LBdjIhqaMAALewOjQgEhDAi//9aMC0OiHsS8Ki6DTjuLdLxdgW+U4oDJhM1oQms hzCQhb4f0mrdMl886GPOUo1lsd9Lpk24YivbtdyZ0yyrwHGHgy923zmvSHe2eZrIs4at5po53U2 xIWbEBR78xoWIPslVQbK50pdkCklJ1n/2dEfenK7n7oSotmm2smF/47khkrsH+dIL8K7SBgKlxF 2mMcpcXo5qW1J0uQjvFAyoTDoT5azeeBBNzage5NiH2vtzxQzH30mUV+YCHuzyJqZfd2IkC+AyZ ZJDH97cHbQfbM/Ec+0miGrl1p3pXWpnkVShUkFao9td X-Received: by 2002:a05:6a20:a12c:b0:398:8e5c:4a94 with SMTP id adf61e73a8af0-3a089303797mr213259637.54.1776366534579; Thu, 16 Apr 2026 12:08:54 -0700 (PDT) Received: from visitorckw-work01.c.googlers.com.com (32.237.80.34.bc.googleusercontent.com. [34.80.237.32]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c7957ece99asm4815137a12.4.2026.04.16.12.08.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Apr 2026 12:08:54 -0700 (PDT) From: Kuan-Wei Chiu To: djakov@kernel.org Cc: gregkh@linuxfoundation.org, marscheng@google.com, wllee@google.com, aarontian@google.com, jserv@ccns.ncku.edu.tw, eleanor15x@gmail.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Kuan-Wei Chiu , stable@vger.kernel.org Subject: [PATCH] interconnect: Fix use after free in icc_get() and of_icc_get_by_index() Date: Thu, 16 Apr 2026 19:08:40 +0000 Message-ID: <20260416190840.1753468-1-visitorckw@gmail.com> X-Mailer: git-send-email 2.54.0.rc1.555.g9c883467ad-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In of_icc_get_by_index() and icc_get(), if the dynamic allocation for path->name fails via kasprintf(), the error handling path directly calls kfree(path) to free the path object and returns an error. However, prior to this point, path_find() calls path_init(), which already links the path's requests into the req_list of the respective interconnect nodes via hlist_add_head(). Directly invoking kfree(path) leaves dangling pointers in the hlist. A subsequent call to icc_get() or icc_set_bw() will traverse or modify these corrupted lists, triggering a slab use afterfree. KASAN report showing the vulnerability when reproducing via debugfs: BUG: KASAN: slab-use-after-free in path_find+0x6f8/0xcfc Write of size 8 at addr fff000000d43f748 by task sh/1 ... Call trace: kasan_report+0xac/0xfc path_find+0x6f8/0xcfc icc_get+0x148/0x380 icc_get_set+0xf8/0x2d0 ... Freed by task 1: kfree+0x1a0/0x4a4 icc_get+0x2cc/0x380 icc_get_set+0xf8/0x2d0 Fix this by replacing kfree(path) with the proper teardown function, icc_put(path), which safely removes the requests from the req_list using hlist_del() and drops the provider usage references before freeing the memory. Additionally, in icc_get(), ensure that the icc_lock mutex is released prior to calling icc_put(path) to avoid a deadlock, as icc_put() internally acquires the same lock. Fixes: 3791163602f7 ("interconnect: Handle memory allocation errors") Cc: stable@vger.kernel.org Signed-off-by: Kuan-Wei Chiu --- I discovered this bug while reviewing Krzysztof's patch [1]. To verify my hypothesis, I injected an artificial kasprintf() failure into the source code and wrote a minimal dummy icc provider module. This allowed me to successfully trigger the use after free via the debugfs client and catch it with KASAN, confirming the issue. [1]: https://lore.kernel.org/lkml/20260416130912.375013-2-krzysztof.kozlowski@oss.qualcomm.com/ drivers/interconnect/core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/interconnect/core.c b/drivers/interconnect/core.c index 8569b78a1851..e14280ced381 100644 --- a/drivers/interconnect/core.c +++ b/drivers/interconnect/core.c @@ -528,7 +528,7 @@ struct icc_path *of_icc_get_by_index(struct device *dev, int idx) path->name = kasprintf(GFP_KERNEL, "%s-%s", src_data->node->name, dst_data->node->name); if (!path->name) { - kfree(path); + icc_put(path); path = ERR_PTR(-ENOMEM); } @@ -626,8 +626,9 @@ struct icc_path *icc_get(struct device *dev, const char *src, const char *dst) path->name = kasprintf(GFP_KERNEL, "%s-%s", src_node->name, dst_node->name); if (!path->name) { - kfree(path); - path = ERR_PTR(-ENOMEM); + mutex_unlock(&icc_lock); + icc_put(path); + return ERR_PTR(-ENOMEM); } out: mutex_unlock(&icc_lock); -- 2.54.0.rc1.555.g9c883467ad-goog