From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 D750933065C for ; Mon, 8 Jun 2026 17:02:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780938174; cv=none; b=T05eq7hoQggI4Hoq/29pjoJcmjLGpRUoVyr5BYpDACYzCTZAta/2/1dyT66FNNgWsMPc+5deCHE3seg1dDPI5QzUMg7aNQujT/OIYtKvwGkZNuKIjMbg7It20MDsyOyfitLy9T1vPrD/aJauKITNbyhNrbTlDPL2tiT6dGo83X0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780938174; c=relaxed/simple; bh=TeGUevqJjKKdHILxWcVaQKAnxXmxLmDs6VfY4SGfpoE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=a3iysy0nsvKtQrHToK3YVIRsgG2JuJuuDqd/7j4/YBaTYZBzHElwVvZqEJKvME/hQ/0f+cBAfdNC0Z/H8GmgApxLhGJupOCeQ9KdcdmA27R7XVTMgYEE1rZK+WkXcKsNn2E9JyLPBR2CsQD3IjDIALEugQKPB4YPlLYjQHzYCmI= 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=JvCB2X5d; arc=none smtp.client-ip=209.85.210.175 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="JvCB2X5d" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-842273a2c4dso3069344b3a.3 for ; Mon, 08 Jun 2026 10:02:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780938172; x=1781542972; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=IVjaYMlS8AytKKUy6WaMPwOlFtLwcyoaO4rV2Eiq+9U=; b=JvCB2X5dTOa3Nvr99o9JynwvR/EvPlMw6DKZ9Uxiu2FOq1yE3p220Oau7WPNhJzyFv FyP56qxQatasAXgHeNlh76D7NfkrDz4vSgtrUwbzzXbOsdCp0YehabQwqiV052VO7FXP N63a3fTkQj4z3l1FDBrio29wYsNWQLQMJKIM1jJGGzCBqq0yDXrfK41l39juX9EgFD5A qqqPiX9Qm+/4Cmm8drUONklQEW3g12KZ/QlB1MltoJcrErB26nTMaNzuP1P/QQdBg2jO mtFIxb/qVOv2VlFYNPybchqnjd4G1rcUSOEr5oLsWnGcNhEHo+iAi4f36wTI4lJh7qPb t46Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780938172; x=1781542972; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IVjaYMlS8AytKKUy6WaMPwOlFtLwcyoaO4rV2Eiq+9U=; b=WTixDwheTrg21ESJJnLHT+o7oyiu1bZsG8KLMPPUhAA0OJd2tXaALOZAfNFix5tlbn YRvgoiIx02Qm9hoDBbQpq/kKa5h2RyycXy+6A4VmceBQmb718tdH9R5AAXd+bSl84EqP 32MYTamuvVWA/ecZ4zMixRDiA5kjJQ3m/OMOAR+cx7SKmHYMesPRFaGi6DiJJCoNrNdp 6tbw0IUybj/BcHaVY/PheS/0IkwobUf848SazyCDJCOoifJA+4tYOmXcHliR42fE2zPy 36FwXIHuHwGqGugPNuv0tB5jYGBalDD5uL8ysWrscCiYriZcuVuTXX60A0IOr8h9KDXo DzJA== X-Forwarded-Encrypted: i=1; AFNElJ/B+AqhTjHFWdNyirXTvEsNUJ8Catxx76fAiJfLPqy5t7665rfRin564QPJe/mTrAKd6AlZwAYOF4M3Nbo=@vger.kernel.org X-Gm-Message-State: AOJu0YwjHiZoDkSDHOaY7ko2w5Y9kUH4QRT+w5qg9jwkUbegAbphVxm2 Ns+AVsHTWCEOKN0yGMu39hFwvIVCXgc+IBLz/wuNHFKPT/dQhQH81pbI X-Gm-Gg: Acq92OELjkKOVLeyuZS5Or48qZojGs1z6o30VDe2y/xat54myenTpCTpfCO5yVEHesY z0UC7iU7yULrqg9bjiR2Q3ldbnNNlbYp2nJ9eHRcoZoLbU03ugI4gzd9FaOPZwnTzIFRa6fnMOe 9dLeWzHfUOc9cCqBYLWp0h180j5eSFw03iPpP7sUVNKW7yuf+7UWuXltcjVkyNfGwYGfI4WY952 gb2jVfqJdEtyG0shp5RkLvzC+RjxBDhhQJ6hhnPecA9hg4x5fTqDBoogvA95XVYlzATU+7vFJXg G8pQdQbostcFgJkRWaUwYSp8Zt81azMRxFX5f0wKQEYvrIjlA3GiWCXu2wraLWUsN9mijmU1/1j UW/ebUojN2si5n5B8ujnKcis//xL8s8HEInD2nXW1Zqq7WjZ6mQF7bmbAZGMx2Gs9mVJnlS0IRz QMnq69b43C+myPAUoHIfJGSWsz/d4chHF2d4+I X-Received: by 2002:a05:6a00:94d8:b0:832:e65:ddcd with SMTP id d2e1a72fcca58-842b0f4278cmr16028206b3a.45.1780938172116; Mon, 08 Jun 2026 10:02:52 -0700 (PDT) Received: from google.com ([2402:7500:498:d80a:6ed1:11c1:50ff:fc30]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-842820e8e6asm18289053b3a.0.2026.06.08.10.02.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jun 2026 10:02:51 -0700 (PDT) Date: Tue, 9 Jun 2026 01:02:47 +0800 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, stable@vger.kernel.org Subject: Re: [PATCH] interconnect: Fix use after free in icc_get() and of_icc_get_by_index() Message-ID: References: <20260416190840.1753468-1-visitorckw@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260416190840.1753468-1-visitorckw@gmail.com> Hi Georgi, On Thu, Apr 16, 2026 at 07:08:40PM +0000, Kuan-Wei Chiu wrote: > 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 haven't seen this patch show up in linux-next yet. Since the merge window is approaching, I was wondering if you had any comments on this? Regards, Kuan-Wei > --- > 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 >