Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp921656lqc; Fri, 8 Mar 2024 16:36:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXmhVgZWV5/NUM+onP4UpUtiFLGSr3OSRDQusG2Jx/EbQUF5OkeZZO8lnRkWjvUndND+Z9hs2bJJ63JXfMgGf3SO371AnEsRLNa/o78qg== X-Google-Smtp-Source: AGHT+IGTF5lQ8vUlX9XLsbSomwpjSWT0Lp3ZpnOHwWaksGNLN1dvFAOUD7rKdaaAxklpXbFY303N X-Received: by 2002:a05:6402:907:b0:568:3362:cccf with SMTP id g7-20020a056402090700b005683362cccfmr510171edz.7.1709944587636; Fri, 08 Mar 2024 16:36:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709944587; cv=pass; d=google.com; s=arc-20160816; b=HH+XOp2DybrfGTE6T1TkbtgyEuMlkYw9dt87EJsZwdWW/UEshEkjJnlEe22TsVW5Kz +7x97EWAIrFSWb1Qf58dns4Uz4LZJXy8mBU55lZ+uPJv5QlG4JyqOn+5aB+LHYRegvHq jbS4P5zW5OpzziUsvPNfewA8NnzUOPrsIb2tV+PGT38XjBz+yYz6dzSZf8EJolY5dIDw xJ8oWCsuYvlcWBd5uNVy0gzBZUOMc9yJeFv+dkwsp9fWPITOK+e2/km2fnpqZ5m8xqZS xbAwuom5emSSUAT9fk1yxrJD3079Sg90ksaA8Nyjn6TqLGJcTF/G5LDU6Dq1lWzS/yFJ 4N0Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:date:to:cc:from:subject:references:in-reply-to :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:dkim-signature; bh=uo0xaFR0M9l6gfBaFxO775laj3PgIGotcONcr49QI64=; fh=jcUQbVo8oRp0m0Y0rHg3QVUAWq/Wj0sG+S4hj9ZbPxo=; b=Rm/Oe3jtKn3zNSYhPH5s5fKKPptuy3DxbEtIDQKQP78LyY1EPTMg76tEPc6ihvaMTH GPFY8+PrnoiEV1MQ4TZIRC6FnYg15F9L9VyXu4pYtXGqv10m1HWyKDK5y3iJksoHPdXa 8JLFd77JSy0V+KfPQ8/YVYUfF7D2pKYOhM59JRTZHmpEKXszbDkEBV1HkNKom+kDBf8p GZuWXc7H+3Ig0ogL4w1E8ImwVpm0dJdGiQqnyaNaO1UUdRCgVtcHuYTwlttpb5kYh71b 2bfDmnEeD9v23XOYDFC6tVK6cOwpaoBH9w9WCiDhL5ixDxcMkRmRdblE9LnxL58gNyKY kpdw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MVoVrmAE; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-97709-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97709-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id q29-20020a056402249d00b005677a468d00si265077eda.221.2024.03.08.16.36.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 16:36:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97709-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MVoVrmAE; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-97709-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97709-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 5708D1F23330 for ; Sat, 9 Mar 2024 00:36:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E59D915B1; Sat, 9 Mar 2024 00:36:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MVoVrmAE" 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 12DA7627; Sat, 9 Mar 2024 00:36:16 +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=1709944577; cv=none; b=GZtrwdA6N9r0BRCViv8k2tVdvavhZVDHJTMnmXqUTV/waYZWhe0mVvFJBCDaDwe2C+BvLoz/Veu5cXxuddUJ7XAYyJCuiiRwpaHyqtt9CRdAAxgnOWmlMJvmVwH3/M34wQdEJxCZjCwwuR8AmSLUgr7Gyk655DddNyssjjY2qUo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709944577; c=relaxed/simple; bh=Bng1q+YJswEAXf80mAEaFjx8w+gbJ2x3xqqQcut85fo=; h=Message-ID:Content-Type:MIME-Version:In-Reply-To:References: Subject:From:Cc:To:Date; b=fRtrCRHymnWov7S3GKzZhJOR/QVU/8unzo2XNdgbjvoW8KccQllSa0MTyNLc+R3p0VAxe0BPYB3452Cm4jfjNVNVYkdBlDLdPf3FvhZd9+8V5mmZNBLzMhYAa0n4NHXN1NhT3tx8jVzoX13gPVDIJ4fKxQWap+zDYSDFUjT3TRA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MVoVrmAE; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85F13C433F1; Sat, 9 Mar 2024 00:36:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709944576; bh=Bng1q+YJswEAXf80mAEaFjx8w+gbJ2x3xqqQcut85fo=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=MVoVrmAEPP7/qY+yUiy5AAWJhzqgmxORvnh1AbY4b81TvTIW9Jf7UChHZAjPgdJFp Nepch4g0iSfcCGbzM14T4zKl8Qh+DX/ecOyYdfmAl4J2/PHD2AedHKVd6D1kOimSgc Y1s3WVb3WBqh2n37w/F2S1wBP71BCc+dkqslvWGzaNpx2MUfhY1vwHitRJep00VSJ3 jWYsnn6ruJJpDPr9AYukJt13KgZHFvAUdQ0pUbWGD3OtvpDT0FPDG+Do44y7Kyud0k EZ+wLCzKyG4YCiEWT6Ad2k7aTh3WplRNuUOResFTQeu30+8VM2MTo2gvBqKb/SJkE8 iAjDfX8EKDMhQ== Message-ID: Content-Type: text/plain; charset="utf-8" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20240302-linux-next-24-03-01-simple-clock-fixes-v1-1-25f348a5982b@linaro.org> References: <20240302-linux-next-24-03-01-simple-clock-fixes-v1-0-25f348a5982b@linaro.org> <20240302-linux-next-24-03-01-simple-clock-fixes-v1-1-25f348a5982b@linaro.org> Subject: Re: [PATCH 1/2] clk: Fix clk_core_get NULL dereference From: Stephen Boyd Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Bryan O'Donoghue To: Abel Vesa , Bjorn Andersson , Bryan O'Donoghue , Konrad Dybcio , Michael Turquette , Rajendra Nayak Date: Fri, 08 Mar 2024 16:36:13 -0800 User-Agent: alot/0.10 Quoting Bryan O'Donoghue (2024-03-01 16:52:14) > It is possible for clk_core_get to dereference a NULL in the following > sequence: >=20 > clk_core_get() > of_clk_get_hw_from_clkspec() > __of_clk_get_hw_from_provider() > __clk_get_hw() >=20 > __clk_get_hw() can return NULL which is dereferenced by clk_core_get() at > hw->core. >=20 > 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. >=20 > Reading the description of this function it talks about returning NULL but > that cannot be so at the moment. >=20 > Update the function to check for hw before dereferencing it and return NU= LL > if hw is NULL. >=20 > Fixes: dde4eff47c82 ("clk: Look for parents with clkdev based clk_lookups= ") > Signed-off-by: Bryan O'Donoghue > --- I dug through a bunch of old patches and this looks right. I'm not sure why a provider would ever return NULL though. A NULL pointer means that the parent is never going to appear so we shouldn't treat this clk as orphaned in case the clk needs to be clk_get()able and change parents. This was all part of my plan to introduce a clk_parent_hw() clk op that returns a pointer and then implement probe defer through clk_get() when a clk is orphaned. A NULL clk also means a clk is optional and not there. Anyway, I've applied this to clk-next. I hope to send out the clk_parent_hw clk op series soon.