From patchwork Fri Jun 23 15:41:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 695285 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp2022278wrm; Fri, 23 Jun 2023 08:42:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6pK6a80oz63+3NsZOrnYt428LQEVbq/bJMpRI/JmH2+WIlMyuoyLQOUkhqmShFtrMSJQSx X-Received: by 2002:a67:ee56:0:b0:441:79b3:81b8 with SMTP id g22-20020a67ee56000000b0044179b381b8mr2954786vsp.3.1687534962336; Fri, 23 Jun 2023 08:42:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687534962; cv=none; d=google.com; s=arc-20160816; b=Ul3fCrFkoLHh/fV2B/Un390ydFWxCMNksuxeV1WvZ1zdtNs24Qe+W/bN14FjBxcA6m frL+Sa2LNbZOjlJuDep0Ss89eSKxdNIc0QhzpZutAZLAoStOTU8f7HzyTi21d/mFi4e3 7CsECUT2rIunvlzJXNQiTqLPwgV12CLWP71WZnp7MR5P+3yI+qzrq+8wsellrqhRpZgi egzx2s4kaknvwV2SN9iD2q/6VDx4t1WPh6cylAUdwdM07DW2MvzVYJr37v5T/h86SnZc BPbrOwQbubkT6gWK7/2RzI5KhF8ej1s2RPhnJ2WVRSSEkZL8qKt5JtaNcqHGFrwdJQ3l nwFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=0ehBAGjrrkyk5SNhyBclcjFfgNXByJfqpK/F+XSrmwI=; b=iDV4sTvdz5Ka8NgWOkBCy2aVMlSMsuoRjYU0//mclOcL28LUYU52Pci8m05v/y+6Lq 6Ce+oY73TjtRs66HtZ/+G6Y/zbwVMAsR3yPlRCdqEubiy/3BUU8+MNPvETdGvo7JjwfP lUcHZLr0GjZRuI+Ig4Acb8fUGZIM/KzgWXAkKgO28UfV8slbzTM8Y3V1DhtIIFEnvQDf VEP13Z3agkmMSuz6nwer3qhdL27shN3/M90/LlgmR5vbqzhvn5EZCLoRvNOr/tC3N5wE QcYDkGX1SN39uJ48UwPYBwjcCWkQhKkS25TvnBHiCZaH/6X7DGwM8prIwqupVlGFAxVq FMrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GPto7RGW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e7-20020a0562141d0700b00621308d5be5si3787189qvd.503.2023.06.23.08.42.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 23 Jun 2023 08:42:42 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GPto7RGW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCiv0-0001do-76; Fri, 23 Jun 2023 11:41:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qCiuq-0001dL-Q0 for qemu-devel@nongnu.org; Fri, 23 Jun 2023 11:41:43 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qCiuo-0008MV-TZ for qemu-devel@nongnu.org; Fri, 23 Jun 2023 11:41:40 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-307d58b3efbso795568f8f.0 for ; Fri, 23 Jun 2023 08:41:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687534897; x=1690126897; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=0ehBAGjrrkyk5SNhyBclcjFfgNXByJfqpK/F+XSrmwI=; b=GPto7RGWPkV2F0nHpTBpmoAIFkh+/5bdWAm+/Eegd9zearUXAqhxWdlk1U1o91j0AV 8tjw3srkfxZIf9xNZn6Fawz65I3l+Vj+RyQF8I3w2U9/u8YH6KppHs4s6lOqEvf0SCol jvEjf+1iGdstqs7TUKLw8q9SHKZdJ8zQ7y6vGexgzHq3VoWwfe2BD+cZTPd/ZvXYFhph 7oxPApnYWI7nMAlEhOeqeGWI24CV/x/HaImeWFBeknrFh5RW5jNWyaqW5S7+0kBrWHZR DhuvMCyyV9qGcgXcMYGB/ZLTs4/yV3bYDJpaP1o3pmLcD5JetcJZ8Jm578mIu63AHsdk ZvWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687534897; x=1690126897; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0ehBAGjrrkyk5SNhyBclcjFfgNXByJfqpK/F+XSrmwI=; b=AZwT4cR7ltkMdNKIz1GnfgcveKlFu1LPVX1er9zwxWy/37W83HhAPog+aX9k5MFMi7 TyjBdlPUpN6xsQgmG73HXumASIJGcl+CA3jsemywFZlxlfQPs7XNJi8Qv/NDx4ttBwim eS5bizykLfyAhhYMMFEtuaSIE+/PI4po1scV4mgWS839v/RjDL5zu8fxYdcLM2LRqhKu cTLVjhkZjnEnY88Ihk3Shh2MvwuTo1/iVCXvzA2MLdUlZZUIJfz9cdQ2dtdYQDldABYT FQ9o07iRf/xxZGhtu806RsMha2CHDiYyLFXAvbmM7I/4RkUuoSHIejDCPSmHk2GvSbsL KLWA== X-Gm-Message-State: AC+VfDwTmnxZiH+HSaTHvABE2IBE923NH8Rpk1oVhfN2BqGkR7KcVDkU yV/3JaYonIciy93uUqpNvIpBiJuFLOn4x20/RHg= X-Received: by 2002:adf:e8c1:0:b0:30f:bcf3:9a30 with SMTP id k1-20020adfe8c1000000b0030fbcf39a30mr4372110wrn.17.1687534897464; Fri, 23 Jun 2023 08:41:37 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id b14-20020a5d45ce000000b0031118d80246sm9830070wrs.29.2023.06.23.08.41.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 08:41:37 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Max Filippov Subject: [PATCH] target/xtensa: Assert that interrupt level is within bounds Date: Fri, 23 Jun 2023 16:41:35 +0100 Message-Id: <20230623154135.1930261-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org In handle_interrupt() we use level as an index into the interrupt_vector[] array. This is safe because we have checked it against env->config->nlevel, but Coverity can't see that (and it is only true because each CPU config sets its XCHAL_NUM_INTLEVELS to something less than MAX_NLEVELS), so it complains about a possible array overrun (CID 1507131) Add an assert() which will make Coverity happy and catch the unlikely case of a mis-set XCHAL_NUM_INTLEVELS in future. Signed-off-by: Peter Maydell Acked-by: Max Filippov --- NB: only tested with 'make check-avocado'. You could argue that we should mark the coverity issue as false-positive instead if you like. --- target/xtensa/exc_helper.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/xtensa/exc_helper.c b/target/xtensa/exc_helper.c index d4823a65cda..43f6a862de2 100644 --- a/target/xtensa/exc_helper.c +++ b/target/xtensa/exc_helper.c @@ -169,6 +169,9 @@ static void handle_interrupt(CPUXtensaState *env) CPUState *cs = env_cpu(env); if (level > 1) { + /* env->config->nlevel check should have ensured this */ + assert(level < sizeof(env->config->interrupt_vector)); + env->sregs[EPC1 + level - 1] = env->pc; env->sregs[EPS2 + level - 2] = env->sregs[PS]; env->sregs[PS] =