From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62C684E4305; Wed, 30 Sep 2026 16:50:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790787039; cv=none; b=ZlYIKbj5a/+xxXE+mDJPtECY0VNo4YCeo5wF9qElN/gBV6AbmQHiRIG0oMLCkD6UpUzZ7lRZg69Tnhi3ijs4jkeEg9jOC+i5vbpYZMDxGmqHteEl72QTeTsgKQuO887ZyraP+a5n1slAhAk/znegstBqR+N/j8ZN6uYRqOsjsFA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790787039; c=relaxed/simple; bh=S+leDvBvGWGTnEDCDUzLYtP+1at8U2mcOKJ8QlCBisI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HSRviu14h1lQEUhyJdLIj2k3ZONbB+c8BGNWYdnK/0JxKAlcMHtlmhqs2tfkNVGEGXkOl7GZqwbBopaMiKCCu0NLZ6wJbA7znASd1/Mc9J4GKxJw9WwBPbpyddNKJ/P7MUNzgEyty6C2NF3BigJUn5yIkkOiH1TZ+CJ8Kp45ZJg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=jaoSU9E6; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="jaoSU9E6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B57651F00893; Wed, 30 Sep 2026 16:50:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790787038; bh=2YkUQWp7zlkGXMFoZlBigi0fUEWIK2NvLYYwmMPX5F8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jaoSU9E6xjQY5+IBvnFYqUdQFEdYAQrDvbtTMTMlISfq1Kw+n+6UI+pzHCgLAhNWH kHpJeTlKfE79Y76+t9yxgEfJs5oihb/z7HavrbrRTt+MHDobSg3qreiHbgp+5VlUrh /+poY61jAADsTJ4aDMoLiZQzXZg71qOYqrFsG3og= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Dan Carpenter , Francesco Magazzu , Lyude Paul , Sasha Levin Subject: [PATCH 7.2 089/457] drm/nouveau/clk: fix list cursor use after loop in nvkm_clk_ustate_update Date: Wed, 30 Sep 2026 17:23:14 +0200 Message-ID: <20260930152347.972747847@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930152346.024115587@linuxfoundation.org> References: <20260930152346.024115587@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Carpenter [ Upstream commit aff09d9e37e02dc60bde79035ac15b136d602259 ] If list_for_each_entry() exits without hitting a break then "pstate" is not a valid pstate pointer. Introduce a "found" variable instead. The check is reachable from userspace: nvkm_clk_ustate_update() takes the pstate id straight from the 'pstate' debugfs file, so requesting an id that is not in clk->states - or any id at all when the perf tables are broken and the list is empty - makes the pstate->pstate != req test dereference the list head cast to a struct nvkm_pstate, which is an out-of-bounds read. Fixes: 7c8565220697 ("drm/nouveau/clk: implement power state and engine clock control in core") Signed-off-by: Dan Carpenter [Francesco: rebased on drm-misc-next, expanded the commit message] Signed-off-by: Francesco Magazzu Reviewed-by: Lyude Paul Signed-off-by: Lyude Paul Link: https://patch.msgid.link/20260918131620.405133-2-postadelmaga@gmail.com Signed-off-by: Sasha Levin --- drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c index 572e638463159..5da82db71dde2 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c @@ -473,6 +473,7 @@ static int nvkm_clk_ustate_update(struct nvkm_clk *clk, int req) { struct nvkm_pstate *pstate; + bool found = false; int i = 0; if (!clk->allow_reclock) @@ -480,12 +481,14 @@ nvkm_clk_ustate_update(struct nvkm_clk *clk, int req) if (req != -1 && req != -2) { list_for_each_entry(pstate, &clk->states, head) { - if (pstate->pstate == req) + if (pstate->pstate == req) { + found = true; break; + } i++; } - if (pstate->pstate != req) + if (!found) return -EINVAL; req = i; } -- 2.53.0