From nobody Wed Apr 8 12:16:01 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 477B0C433FE for ; Sat, 8 Oct 2022 14:29:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229769AbiJHO3q (ORCPT ); Sat, 8 Oct 2022 10:29:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbiJHO3m (ORCPT ); Sat, 8 Oct 2022 10:29:42 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D539B1114; Sat, 8 Oct 2022 07:29:38 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.169]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Ml6vb2YfczKG84; Sat, 8 Oct 2022 22:27:23 +0800 (CST) Received: from k01.huawei.com (unknown [10.67.174.197]) by APP1 (Coremail) with SMTP id cCh0CgDXWy9PiUFjwdKvBw--.2626S2; Sat, 08 Oct 2022 22:29:36 +0800 (CST) From: Xu Kuohai To: linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org Cc: Michael Turquette , Stephen Boyd , Florian Fainelli , Broadcom internal kernel review list , Maxime Ripard , Christophe JAILLET , Xu Kuohai Subject: [PATCH] clk: bcm: rpi: Fix an out-of-bound access to raspberrypi_clk_variants Date: Sat, 8 Oct 2022 10:45:44 -0400 Message-Id: <20221008144544.283945-1-xukuohai@huaweicloud.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: cCh0C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-SenderInfo: 50xn30hkdlqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Xu Kuohai KASAN reports an out-of-bound access to raspberrypi_clk_variants[]: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D BUG: KASAN: global-out-of-bounds in raspberrypi_clk_probe+0x1dc/0x690 Read of size 1 at addr ffffcc7116d615a0 by task kworker/u8:0/8 CPU: 1 PID: 8 Comm: kworker/u8:0 Not tainted 6.0.0-rc3-00900-g08f4df4a3c53 = raspberrypi#10 Hardware name: Raspberry Pi 4 Model B Rev 1.4 (DT) Workqueue: events_unbound deferred_probe_work_func Call trace: dump_backtrace.part.0+0xd4/0xf4 show_stack+0x24/0x7c dump_stack_lvl+0x68/0x84 print_report+0x130/0x620 kasan_report+0x94/0x160 __asan_load1+0x68/0x74 raspberrypi_clk_probe+0x1dc/0x690 platform_probe+0x98/0x12c really_probe+0x118/0x42c __driver_probe_device+0xc0/0x150 driver_probe_device+0x64/0x1c0 __device_attach_driver+0x128/0x1ac bus_for_each_drv+0xf8/0x17c __device_attach+0x128/0x294 device_initial_probe+0x20/0x40 bus_probe_device+0xf8/0x120 deferred_probe_work_func+0xf4/0x150 process_one_work+0x3c4/0x800 worker_thread+0x3dc/0x6b4 kthread+0x194/0x1b0 ret_from_fork+0x10/0x20 The buggy address belongs to the variable: raspberrypi_clk_variants+0x1e0/0xaa0 The buggy address belongs to the virtual mapping at [ffffcc7116a00000, ffffcc7117061000) created by: paging_init+0x2b8/0x7a8 The buggy address belongs to the physical page: page:(____ptrval____) refcount:1 mapcount:0 mapping:0000000000000000 index:= 0x0 pfn:0x2961 flags: 0x3fffc0000001000(reserved|node=3D0|zone=3D0|lastcpupid=3D0xffff) raw: 03fffc0000001000 fffffcb2ee0a5848 fffffcb2ee0a5848 0000000000000000 raw: 0000000000000000 0000000000000000 00000001ffffffff 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffffcc7116d61480: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ffffcc7116d61500: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >ffffcc7116d61580: 00 00 00 00 f9 f9 f9 f9 00 00 00 00 00 00 00 00 ^ ffffcc7116d61600: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ffffcc7116d61680: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Since raspberrypi_clk_variants[] size is RPI_FIRMWARE_NUM_CLK_ID, fix it by making the access index clks->id less than RPI_FIRMWARE_NUM_CLK_ID and setting clks[RPI_FIRMWARE_NUM_CLK_ID - 1].id to 0. Fixes: 12c90f3f27bb ("clk: bcm: rpi: Add variant structure") Signed-off-by: Xu Kuohai --- drivers/clk/bcm/clk-raspberrypi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/clk/bcm/clk-raspberrypi.c b/drivers/clk/bcm/clk-raspbe= rrypi.c index 73518009a0f2..3ad0d2d2e3b6 100644 --- a/drivers/clk/bcm/clk-raspberrypi.c +++ b/drivers/clk/bcm/clk-raspberrypi.c @@ -356,10 +356,12 @@ static int raspberrypi_discover_clocks(struct raspber= rypi_clk *rpi, if (ret) return ret; =20 + clks[RPI_FIRMWARE_NUM_CLK_ID - 1].id =3D 0; + while (clks->id) { struct raspberrypi_clk_variant *variant; =20 - if (clks->id > RPI_FIRMWARE_NUM_CLK_ID) { + if (clks->id >=3D RPI_FIRMWARE_NUM_CLK_ID) { dev_err(rpi->dev, "Unknown clock id: %u", clks->id); return -EINVAL; } --=20 2.30.2