Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2622166lqp; Mon, 25 Mar 2024 04:52:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVQY+qbmHEX+p+fxiZjXdbOvr0Q9D2gpky7Y/dFAR3veF/L3ubJzM3Qr9H4MDdqvwhRb+0mjikbqYnq6N1b/xvR2v+rePwjG+Np2ShDLw== X-Google-Smtp-Source: AGHT+IGrI9FRKROzPbV+jPjXt5Ge7Jvry/cf7LvegJrbar3iNvg+W/po0kuAWNOYsh+M05oK5zd8 X-Received: by 2002:a05:6830:4785:b0:6e6:715d:a63f with SMTP id df5-20020a056830478500b006e6715da63fmr7398596otb.30.1711367576999; Mon, 25 Mar 2024 04:52:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711367576; cv=pass; d=google.com; s=arc-20160816; b=BBUuCLM5ci9XgbRNO0M5rSK12PZfUyl+YVPX6mVQR9Rx32qe1fH1EnMNO8uqchyZlX T8PpuWQfaBo+S5hycNvHKeOYNLI4R6oS1L7lSQSkd/ob2X5nKVpP9A0fcrteZFHPe/TX rg41oRSXoxqDTNiYz7sDPBBaqylHoduxvs7tAt/R8sG9M8LCx/Od7oL+U88M4lQPhL0c knZgTT/fJUqeGUt+imWFL/SN4CAHkbpKwot+uLn/3N9LhYokbBmfjWMxJ4Q5REvhotwU 4QO6ZydsxzeRUH7JC+qbAcBszE8I7MzMGfHSGWv89XEY2Jy3iS0SV46jlVQM0KYjh7N9 a8Vg== 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=xZusBiz6A+lk3Jc0ZZuIcKG/Uh6GyR9L22WkfrqcL5Y=; fh=OgC2DrKlKpxdJcZCmYXyBXmuGa/AuBL2Def/P48z+6w=; b=tvF/djglMprHZQwCr8M1uyWCkLosXWnI7EFpeK6agQ1Qknegq+KDwc3m0LzH5Wpcs2 AdHvAOi8IKlyN6ofjTxtNrdMcfqXGoM2ly+ezg8MHpA7BMigxwDJyBRvDk/jTrfioL22 CO7NsBX+Fd6B+n5+yuVAih/Pto26pu23HfMgT7DBn0k+yYHMydh9uLYE34liy4N4fXm4 /fqY72CFcOnDf0O3fqdjIfCKWmS5FUJ9eWDvJI2GAw3OK1g/gZOz2bzVARHlgqxnRkZd nnfQP0cmmtnexe7F2c3LFJNmed5uxIfgZqt5/AUr5NrNeLRtpk1Evpax09v7ViG5AE8l paZA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ahdN6Q4i; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-116201-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116201-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 138-20020a630290000000b005d8bf42e02dsi7430251pgc.544.2024.03.25.04.52.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 04:52:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116201-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=ahdN6Q4i; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-116201-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116201-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 4CFC82A1AE5 for ; Mon, 25 Mar 2024 11:44:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9EAAF290BAC; Mon, 25 Mar 2024 03:33:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ahdN6Q4i" 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 EB2E417CF62; Sun, 24 Mar 2024 23:43:31 +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=1711323812; cv=none; b=oZlGZmxjAyOk5T3R5ZLOKVntxYKrQxbPffZyuZnCHCJnF2oNCASZNG1ZUw7RbX/UkOIx2cRjGBOmklCmWrnedQeV23s5WAKF7HwSwzkzxUBxvXfkPn1wj6e/efVjubrAJkBj6GRNCRdEBOAZLvQPBDMQ4qdTNnFfrNRSrQME3u0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711323812; c=relaxed/simple; bh=c11w0jzUesCGbhTP5ywTHIqFThlwXA1KhgSKdpQ7Dq8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l5MpuEv2Z19H3yZSXTaIgluoeASk9ELXyOpfku5aNgt5bQ4wEVAOkrO1pYVLueRjedFq0Wm29SryGEZCqsgLfd1yFw44rX84F7iKIi1JBUwWeJXtW6E6NTp9wAQh8WHLnD/cDeovO9xw66xd0xdYNyYRkWxsxqxWOdYQNYn8bsg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ahdN6Q4i; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34203C433C7; Sun, 24 Mar 2024 23:43:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711323811; bh=c11w0jzUesCGbhTP5ywTHIqFThlwXA1KhgSKdpQ7Dq8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ahdN6Q4itJe8ZqizwOqIxSJ1aa8MLBflVzQRIz2oXOzCVfFFWumJlnYPSf/BFIk68 fDxlT8CqX6LVU/5F1wRCTkYZG/DNAAS8TsQPzyjcf8Fh7D9xSe/nybQnGGBWMbh+sd ahaQ3wlapafgS62nJpCeF9NEiOJsP8QlXulR+gD3jIk/SqmfMbOMViG9AFE0bLch1w 9XWzDWZdw5JAimqeY8WnXOSkWFwPtW52MOAi9KDJOPjqhmOAam582uMUe1fCuJgro3 2L2tV7VrYUXSkmiSUIxZr7selLRCiLXmYa+9/5d+GSYfvHacrl4NvP0ndCuETIFZEd wG6vduBCI3GAw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Bryan O'Donoghue , Stephen Boyd , Sasha Levin Subject: [PATCH 5.10 190/238] clk: Fix clk_core_get NULL dereference Date: Sun, 24 Mar 2024 19:39:38 -0400 Message-ID: <20240324234027.1354210-191-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324234027.1354210-1-sashal@kernel.org> References: <20240324234027.1354210-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 62572d59e7e38..aa2f1f8aa2994 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -425,6 +425,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