Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4515093rwb; Tue, 6 Sep 2022 08:32:56 -0700 (PDT) X-Google-Smtp-Source: AA6agR6qZx+hTwmUhjThHgQON+vvN99fQFGdK7Um9zYnLsqvlH4xM/3a7Et9pJEwExYry4EeoDoP X-Received: by 2002:a17:907:75e8:b0:73d:53dc:661d with SMTP id jz8-20020a17090775e800b0073d53dc661dmr38547467ejc.738.1662478376494; Tue, 06 Sep 2022 08:32:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662478376; cv=none; d=google.com; s=arc-20160816; b=N0AyaafWhRPaJ82mhl38PbetOpzhaaiFZlrns315BVUwC+qMxfhhiBVBX/Tb4LhrL3 rVMXx2h/69hYcwpONiVIQnqMv6DaZSuBkHFI5/FKQ0X6AnSN/D1knMXAD7OZlGcu90M/ 4y1gu4VGmZYFMDTLQGKu7WxvCzxp6AjFmtbao8+DxtgNwBXr55vICoQXYn6Wa48jmpQJ roNyjBhQiKQFJ3cvrvanMNFh/ke+9dSSLv7VikAA0GDEIkpRRXbIX3z2Sm0YiihMVWHH HfQS4C2K231FL1XsHWgb7K00ZJ5Ddi25Q6aPB5onrpX1IUDFWXYkMkJA/PJMInsE2Lgq LiBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=csi0Ygrfd3SWvWRLYvNqeg1DViq44MekzuS9JxP449k=; b=K4h8D1Y1YNC+MsQgn57C/sdSHCAhslRIf0XEnh2w3QCQvL6lKW8VuVFPoHfAOIa37w lcwHagRojEk02UTNhoqeaYajETXktUDZ9MTaaV0rT1nWdCHbR7ex+Xj8B6df9wpr+GDN pmLr2d3//1g1UkZoEwgXQpYx1n/j3MU7CPQGPGWrVpSuQaFXWE1tE6ABEI9gs0Hf5NM5 vHFBZoBFt9E/Uzz7rSCJT+tLZ0sSRBIPQBOTX/Gq6BrRv2xuFpQJGCtxXZ2GKKKadRIn XRI1qjaWT3bFx5tO8qSmNJNeVZWeh6dNfaq9GCLbuWYqIV7Rl5rO6B7LchLG3O00nuQS ibBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vXet3YWk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z14-20020a05640240ce00b0043e1d52fd9fsi11961896edb.594.2022.09.06.08.32.31; Tue, 06 Sep 2022 08:32:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vXet3YWk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240746AbiIFNgE (ORCPT + 99 others); Tue, 6 Sep 2022 09:36:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240680AbiIFNfS (ORCPT ); Tue, 6 Sep 2022 09:35:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38FAD76766; Tue, 6 Sep 2022 06:33:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4CFE761545; Tue, 6 Sep 2022 13:33:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E0B6C433C1; Tue, 6 Sep 2022 13:33:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662471227; bh=zymJlPrCaPCmih25Es7c22qtTFc8tp9e2wy4ZVY4I9g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vXet3YWkeu66aQha9U462Uzp52IDaIbjTMjyueoXN6fFaN3PO+sV7BEfHcqG1m1al lDnxrR3zj8VmDIh4BVRCfgNLDqO0qvRX8YSkZS8mZrbMqqsdPv9uPiouOWCFa77h1I WPde31lrjvyxMLDSyDgCYL/oQ7ZXvfoGB84SDXcQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Phil Elwell , Stefan Wahren , Florian Fainelli , "Ivan T. Ivanov" , Stephen Boyd , Sasha Levin Subject: [PATCH 5.10 40/80] clk: bcm: rpi: Prevent out-of-bounds access Date: Tue, 6 Sep 2022 15:30:37 +0200 Message-Id: <20220906132818.672622344@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220906132816.936069583@linuxfoundation.org> References: <20220906132816.936069583@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stefan Wahren [ Upstream commit bc163555603e4ae9c817675ad80d618a4cdbfa2d ] The while loop in raspberrypi_discover_clocks() relies on the assumption that the id of the last clock element is zero. Because this data comes from the Videocore firmware and it doesn't guarantuee such a behavior this could lead to out-of-bounds access. So fix this by providing a sentinel element. Fixes: 93d2725affd6 ("clk: bcm: rpi: Discover the firmware clocks") Link: https://github.com/raspberrypi/firmware/issues/1688 Suggested-by: Phil Elwell Signed-off-by: Stefan Wahren Link: https://lore.kernel.org/r/20220713154953.3336-2-stefan.wahren@i2se.com Acked-by: Florian Fainelli Reviewed-by: Ivan T. Ivanov Signed-off-by: Stephen Boyd Signed-off-by: Sasha Levin --- drivers/clk/bcm/clk-raspberrypi.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/clk/bcm/clk-raspberrypi.c b/drivers/clk/bcm/clk-raspberrypi.c index ff87305cbe9d9..27ae08c4952e7 100644 --- a/drivers/clk/bcm/clk-raspberrypi.c +++ b/drivers/clk/bcm/clk-raspberrypi.c @@ -251,8 +251,13 @@ static int raspberrypi_discover_clocks(struct raspberrypi_clk *rpi, struct rpi_firmware_get_clocks_response *clks; int ret; + /* + * The firmware doesn't guarantee that the last element of + * RPI_FIRMWARE_GET_CLOCKS is zeroed. So allocate an additional + * zero element as sentinel. + */ clks = devm_kcalloc(rpi->dev, - RPI_FIRMWARE_NUM_CLK_ID, sizeof(*clks), + RPI_FIRMWARE_NUM_CLK_ID + 1, sizeof(*clks), GFP_KERNEL); if (!clks) return -ENOMEM; -- 2.35.1