Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2490746lqp; Sun, 24 Mar 2024 23:20:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUzDzazOvysiGz9JjMtJzoBQpK4jgUs1HyLUL43KSsZNnVhKLSHb5/8X2WlfZfRLUCfxxyh6IRvnvjD6A8m+xpdzrVxZ7GFeVX1x0UhKg== X-Google-Smtp-Source: AGHT+IFfEt59eErqcogH0wGlZ3o5cDJbX7D0W8efub3lQmCUmMgcjWyq003KqAhoiddOGRJfnX1W X-Received: by 2002:a05:6a20:4926:b0:1a3:69f8:b6eb with SMTP id ft38-20020a056a20492600b001a369f8b6ebmr4441508pzb.14.1711347618285; Sun, 24 Mar 2024 23:20:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711347618; cv=pass; d=google.com; s=arc-20160816; b=ywAURPx2k1qsYmKHV3Zs/0/Sw3p+gBIG1k2XoE7s4mKzfp+tjoRYOpDZdKg3nCi02r XrCmr0QrBuDMxEVvs2h5hmSoMMrwNLgKfxq+tKMX4OHZwKc7aOUjiQkIgt3cakwdZWui +72Gd4pz0nteBTyMxmP1ceyeSyVLqCqYPrGbngt1EPLz9X65puvRUJCQ0mcG2O1TyoH9 JGFc0RkuiraEC2Niu8nXTkXiEmKImYAIUo3kUzCXrLjmcpmYJj7szWXqvb5u+fCMa4pc ndGA60jOne8YEVIh8jNdggZnPCgs7nowpQ3n9tHL6aun58nEEqSmMxk80jVCZf9zuGLf YpQQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ZtVHs3mA6QA8LP9AK40/R7Q89QTkGxVA/tShwgwv7Js=; fh=OgC2DrKlKpxdJcZCmYXyBXmuGa/AuBL2Def/P48z+6w=; b=UB54cNhr7Y0zkfYKOv00oKu2WEN6aGLG6gXTrrViTjVhjgMCBc+yLYzXi3AjcFKAsB nEFG2bUlDcu2wQ7PkrmZ+ZxcDqhhlrjhguNVf62P0DN6DfloIp24RXEEEgBV5VMPuKZO CI1o3HzE03kRgHVXnsf+URTrNgeGZfxKPTP0IIim65Bs10+exXg5nky30TwQvu1FVYAM 21uhomKz+IV4xSgASojrdOoXYZHWSvpKo1Z7z7rWjoWnAhPukw+ZHtO29DuRdILxPB0/ HB17ZQU1szHODwuo3c/WrFlHiFZ5t3/cgwF7CBbyfyOjYSxcRRvjKgsBeiRz4OduzwGd Tlww==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZsxNZpUZ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-114606-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-114606-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id c5-20020a170902848500b001dd4f7ca26bsi4270535plo.629.2024.03.24.23.20.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 23:20:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-114606-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZsxNZpUZ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-114606-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-114606-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D6C4D291D04 for ; Mon, 25 Mar 2024 06:20:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D78F3187675; Sun, 24 Mar 2024 23:55:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZsxNZpUZ" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 CE83515E201; Sun, 24 Mar 2024 23:17:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322263; cv=none; b=CwCU7H6O1UpTe/HDJG925yQ1uKrVr4zicfCJkWjAgpuO1SWLUbRFTvohFStMybedUatmz/JjusOqhcvc2+okqgIeGytKF9hST7oxtQfSBJE8Nq0wGE5Y4XQobv81NbzZYqVUDdFCbdTIqYI2WxCKWQhR44gmwF2a5Y8jEOOYWP8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322263; c=relaxed/simple; bh=WmDERopOBJ/AkiQn5WK9ud8tPBDWlJkX5I8iDlIKvOY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZBlZynfoLtJGIygqsT9Wef3n6onwJHIdMDQlNe0iotTE+YPkAffzLlsPtq4ui5cTzu+XFMZcDx+quRcE5pG/7+Br+oYZ8+0L659E+RqRU5GWG9wny930zbxAqQpEijgQGYF469MeVrYG8gS7HHHseoZMKobRtvd5HieEVEE5NeU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZsxNZpUZ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 167BBC433F1; Sun, 24 Mar 2024 23:17:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711322262; bh=WmDERopOBJ/AkiQn5WK9ud8tPBDWlJkX5I8iDlIKvOY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZsxNZpUZ5mOO/VDQnnE3Vg2CrQsv7R1h2zo3bb8QcPyXf+dG2zuuIe9pB5/9cSF/D tktb4js108Qr1DEyHQOVG4SxuXK0b29gP3tsO6qS+23JiBQW4vH9ySbgXLzlHzIj/D PUNHMd8I3VNxTb0QIP3YenFdbiNMEx8QdodD2xg2qPyiEXDs/fn7Hv6zqpjwfpd1pj h8c1amZJl32aN42xF6uUr0ngTefXesZveF4h5BhTS9XWQslm5RW7gT1buItDXSE3+U 4qSWuKjMHlJ02pfajBWOK2dDVWJabDBA4c9okuYAT3ZWso9uOFn36y+6mrocJg+mjI z4zVYg7ucc+/Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Bryan O'Donoghue , Stephen Boyd , Sasha Levin Subject: [PATCH 6.1 345/451] clk: Fix clk_core_get NULL dereference Date: Sun, 24 Mar 2024 19:10:21 -0400 Message-ID: <20240324231207.1351418-346-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324231207.1351418-1-sashal@kernel.org> References: <20240324231207.1351418-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Bryan O'Donoghue [ Upstream commit e97fe4901e0f59a0bfd524578fe3768f8ca42428 ] It is possible for clk_core_get to dereference a NULL in the following sequence: clk_core_get() of_clk_get_hw_from_clkspec() __of_clk_get_hw_from_provider() __clk_get_hw() __clk_get_hw() can return NULL which is dereferenced by clk_core_get() at hw->core. Prior to commit dde4eff47c82 ("clk: Look for parents with clkdev based clk_lookups") the check IS_ERR_OR_NULL() was performed which would have caught the NULL. Reading the description of this function it talks about returning NULL but that cannot be so at the moment. Update the function to check for hw before dereferencing it and return NULL if hw is NULL. Fixes: dde4eff47c82 ("clk: Look for parents with clkdev based clk_lookups") Signed-off-by: Bryan O'Donoghue Link: https://lore.kernel.org/r/20240302-linux-next-24-03-01-simple-clock-fixes-v1-1-25f348a5982b@linaro.org Signed-off-by: Stephen Boyd Signed-off-by: Sasha Levin --- drivers/clk/clk.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 33fedbd096f33..9004e07182259 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -407,6 +407,9 @@ static struct clk_core *clk_core_get(struct clk_core *core, u8 p_index) if (IS_ERR(hw)) return ERR_CAST(hw); + if (!hw) + return NULL; + return hw->core; } -- 2.43.0