Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4525906rwb; Tue, 6 Sep 2022 08:42:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR6NdCPWrSLw4/aV9aRtCf8FJCsTD+VzeA0h8YRIP7K/p/esIjT5oSvcRYwmrd9K/IUAdk14 X-Received: by 2002:a17:902:ecca:b0:176:db6b:cb7 with SMTP id a10-20020a170902ecca00b00176db6b0cb7mr1825336plh.33.1662478927706; Tue, 06 Sep 2022 08:42:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662478927; cv=none; d=google.com; s=arc-20160816; b=AXwUEpfrL0QU3+DpFXIgUkeGQ5Vl3501Osg47nI5uUgDjT6Cj8Trq2FxAjejK5l4Sh d/O7j/rgzsEt1XCRTLQ6f/AsRhLRwexojjDJBnuf17llDq7/32qrL2H9U3Fcs9D+6AgI hj1TKrIGQYzKP6y//jM3ej1MRBsSmMDoBIBGVSChoyUv+oR3vV2gW87kJ3XMNfXh7Hsp Dp1wk9WFuXUAsIXW3Htfg8DrhtZbNbU7xbFUgpmvenhKO8BxsYgaDcss50Zq4q9QZA/7 H8X552zWRlB8w/K5GzCx77OgxQxMNIzoJ1+6kXYIOZOXlhjVT++WLwaigCc/LSJwoiJs 4RUA== 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=EZK0f7Kk6A5M2+Go/i3e941/5FNTmtnplwxd1rx2/p4=; b=nwrv6ACDAl9c2oVjEyeIxZ1hWrTwsucQuzlMxyJTglqL07yqiuEmTMsofypGiUqSJL JkVvT1g+0rNnNEyd+jGBe/NvSWXs9WIRSLo+IW0VtD5hqANs4UDJXzocTXJ4Ez3vyCrI IYiotTDQO+vjer2iSzTto9LfBjaZ1leh8Ngxul3pJSZNiVj8BJtnbDh0GYoWTSaD5M40 GVDoqyadLOa2noxer165O39d7RzgXaPo6vH4WmKG8Dm34BuFnN0WPegymvstsT+hBr4a O8CdhxgeF4LiB6VX7xsg9Mi3fMcHMqcCZSMrxGZ90OpCxQv1q0WMrypU6eIxqtSD7eEa 6Nzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SBoLA+xE; 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 c10-20020a170902d48a00b0016ef08bddc9si1430570plg.170.2022.09.06.08.41.56; Tue, 06 Sep 2022 08:42:07 -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=SBoLA+xE; 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 S240594AbiIFOKo (ORCPT + 99 others); Tue, 6 Sep 2022 10:10:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240187AbiIFOIn (ORCPT ); Tue, 6 Sep 2022 10:08:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3F9385FBF; Tue, 6 Sep 2022 06:45:46 -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 4C1C061548; Tue, 6 Sep 2022 13:45:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CBCFC433D7; Tue, 6 Sep 2022 13:45:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662471945; bh=KvyQhflTjblQPyR9dYESvlbdaPju0Rt5R9cprg1dQaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SBoLA+xE9+n0ZD2A8sfpV5w5fg92rxRVk5EG9VjTvjpI1T70jTRFYfPUy2+xp1z8d MPNG0kZEJAg5y6OhULD1p6KeyrSEeqG5FZ5He9DG88A90P5K+Yzx4ec9B6MQOT/0TH Hz63UBj3W3aAjJFLYnX+yJWeDs3fzMJ79yVbFkB4= 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.19 093/155] clk: bcm: rpi: Prevent out-of-bounds access Date: Tue, 6 Sep 2022 15:30:41 +0200 Message-Id: <20220906132833.388960769@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220906132829.417117002@linuxfoundation.org> References: <20220906132829.417117002@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 39d63c983d62c..e495f5f382ab9 100644 --- a/drivers/clk/bcm/clk-raspberrypi.c +++ b/drivers/clk/bcm/clk-raspberrypi.c @@ -344,8 +344,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