From nobody Fri Dec 19 07:49:26 2025 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 140DFC6FA82 for ; Tue, 13 Sep 2022 14:18:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233219AbiIMOSF (ORCPT ); Tue, 13 Sep 2022 10:18:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233097AbiIMORR (ORCPT ); Tue, 13 Sep 2022 10:17:17 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E923663F16; Tue, 13 Sep 2022 07:12:26 -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 ams.source.kernel.org (Postfix) with ESMTPS id 77F9AB80EF7; Tue, 13 Sep 2022 14:11:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DDF8CC433C1; Tue, 13 Sep 2022 14:11:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663078270; bh=wHNCixadpIDzH5eeDro/KU1b/z9TVYQ7Rw5nLZwi2CE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LlRbr1jRLtEX777Te4EzImD9MhKGY50drmURWmws+psdfQJIdqV5OCtRDZwDPX2Uz 0GrKd0lxWRwq6bw9Xly9j/NFZoYvOO+Zbh6mNtfr4HpNNp6MQfILq8Mzk/Zz5DV1wO LSCNAzH/xfOz7+90Kw371GKYXm9vfhc64ly58RM0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sergey Matyukevich , Atish Patra , Palmer Dabbelt Subject: [PATCH 5.19 049/192] perf: RISC-V: fix access beyond allocated array Date: Tue, 13 Sep 2022 16:02:35 +0200 Message-Id: <20220913140412.381795215@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140410.043243217@linuxfoundation.org> References: <20220913140410.043243217@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sergey Matyukevich commit 20e0fbab16003ae23a9e86a64bcb93e3121587ca upstream. SBI firmware should report total number of firmware and hardware counters including unused ones or special ones. In this case the kernel doesn't need to make any assumptions about gaps in reported counters, e.g. excluded timer counter. That was fixed in OpenSBI v1.1 by commit 3f66465fb6bf ("lib: pmu: allow to use the highest available counter"). This kernel patch has no effe= ct if SBI firmware behaves correctly. However it eliminates access beyond the allocated pmu_ctr_list if the kernel is used with OpenSBI older than v1.1. Fixes: e9991434596f ("RISC-V: Add perf platform driver based on SBI PMU ext= ension") Signed-off-by: Sergey Matyukevich Reviewed-by: Atish Patra Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20220830155306.301714-2-geomatsi@gmail.com Signed-off-by: Palmer Dabbelt Signed-off-by: Greg Kroah-Hartman --- drivers/perf/riscv_pmu_sbi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -467,7 +467,7 @@ static int pmu_sbi_get_ctrinfo(int nctr) if (!pmu_ctr_list) return -ENOMEM; =20 - for (i =3D 0; i <=3D nctr; i++) { + for (i =3D 0; i < nctr; i++) { ret =3D sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_GET_INFO, i, 0, 0, 0,= 0, 0); if (ret.error) /* The logical counter ids are not expected to be contiguous */