Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2394830lqp; Sun, 24 Mar 2024 17:35:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWuL0ZcD93ZKua23GlhD5q92AtgtX5zWO16tTdLKADCo+I6mfKurSSHNjGGk3MZ4dnq9GzyE/XJxWA0kr2YHWJZYToI2LVzU+zJmQ90oQ== X-Google-Smtp-Source: AGHT+IHgcpReBAFQESmM0d3Qu9hbnoTWBxS1ad9+sPwsMH3IEnXF22HFp7BdeH/tbqQ9+2qKCLZf X-Received: by 2002:a05:6a20:3d06:b0:1a3:c4c2:b016 with SMTP id y6-20020a056a203d0600b001a3c4c2b016mr2930224pzi.45.1711326900513; Sun, 24 Mar 2024 17:35:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711326900; cv=pass; d=google.com; s=arc-20160816; b=gK8iaTU4tssHKn4gjwINHUCYU8v1mxqxOeFqTs1JutVn2Xf+NaobYmLP1kM8v56Si3 OCQnI6KxocUfM2pHamPU+C2CZ2kmL2QAgE4BVJb+EoF2xe/mN6hEimWbNQZQpUz2BuBs xau52ZTvjUYdeiF2951HwZa6Yt5023jbUNCbwzwafeXOwntzTd9UQOX4X1nxYdJxB4A8 1nloGs133HTAyN0l4pbP8izAhzoFmPCku2KvdWXJhINXPju4z5r5o9DMwF1s7eNl5bZR RHu9xxNaflNNRTgwag1Zb/3976HI0N+ID1k+YY3FLKhOF6eS5C/9JiH2E8k+56g1mg2q 8Mtw== 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=FI7zAHrZta6qVFbpK3ANJn28YzTPYvVOP44UQnzTGDY=; fh=OgC2DrKlKpxdJcZCmYXyBXmuGa/AuBL2Def/P48z+6w=; b=hC3zDhkkJtK/6KETKvTwLuYTpm8deiC5qB4FPphN0z4sGE6RPqrIFn44m0zYTVdpLZ DZ/alAJ3/oQJzb+UEH39WJAXu6aZBwkVXy6J06XZLX+Jth0mtdqJ0TMudlaOA52+cZmo sODrPqIFUAaCEWcMUYcomb3LmET5rKON7Yq/ikz37gSdh0JQGhRlITdzmEzGgIyl5VVF d9BEQqKulp6QE1D9R6vPUey0nI+SACQAmk7GzrPX70FphsoBgPbPB11E8tBzMbI1Oz9Q IwrMhAL/X4N6xo+xSbibQLGu5IYvx2odHCKjtfQoqHvSB1PKTr59LWwTihkgdvvy4Aiy m89g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RpbaADs5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113425-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113425-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id c1-20020a170903234100b001dbeb96c48bsi4129489plh.346.2024.03.24.17.35.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 17:35:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113425-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RpbaADs5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113425-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113425-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 D5963283CB1 for ; Mon, 25 Mar 2024 00:33:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4210D1A9299; Sun, 24 Mar 2024 22:43:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RpbaADs5" 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 5D58A1A9280; Sun, 24 Mar 2024 22:43:47 +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=1711320227; cv=none; b=U8e788cCiAMMtNzYNA5v/Rt70R4uANwydluNputnkyafV+vUZvWrlNRp5tPHLvKoFmLpiLnvzpVT4o0sPMFiy8j0QeRCfAyBzItTPLuRSw6bFtnEegqXx37xVjvAzpK+IQa/vJVnFOd4FzV9uXT+7hyvazgsliwtE/ZJxiSC+WI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320227; c=relaxed/simple; bh=lMDwXgjBgx1W6oFjiAwsW9y0JAZStVheK4KXw9VyuEQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GkY4B8ZGcDnI2BErSS49NGvAxwRMaAn5f4AazTMWJtoNge1D/UYrnejbIL5NmVNZHtM5r3fqetXm6kY3ekrsNqND+IjaLF90EYWtrCgjrE6AjmQ5WDGigUlkCiYlOSvORq1Gz+e5sSzm6AGRicrUyb22mRdR/H+QsJ+DeI1ewtA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RpbaADs5; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E880C43390; Sun, 24 Mar 2024 22:43:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320227; bh=lMDwXgjBgx1W6oFjiAwsW9y0JAZStVheK4KXw9VyuEQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RpbaADs53AwIPksvhfmA0Q3EGq2ZO1mRFMxhuPwp7FFcZPkbNmBjzA2yXLEdEErIw 42ftwfg5O4K5RgI+1nHruVNy0+w0YiIhveKC54ZM1A90adI2z9IkuJYWTRIxFNh2Tf 89hoqf2QPlQHyxdVDl0AND6FLIRJvI2ELagyNtTxiy5JQODOVZpWnmlFxquC5E1FnL LTEDvy1Xh10wAP4nn0uurWmqxxNpoG+t0Me8iUZKlhYTQOgRkSYj/R08wZo//bUE+3 9sHJIzCQyjj9g74qwRwrpEHnv7vdoFbFhuSnary/k8Cs3LwujGu6D9/JIINCZY1seR brVi0pWPspkEg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Bryan O'Donoghue , Stephen Boyd , Sasha Levin Subject: [PATCH 6.8 534/715] clk: Fix clk_core_get NULL dereference Date: Sun, 24 Mar 2024 18:31:53 -0400 Message-ID: <20240324223455.1342824-535-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-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 2253c154a8248..20c4b28fed061 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -418,6 +418,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