From patchwork Tue Jul 4 16:36:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 698964 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp2364675wrs; Tue, 4 Jul 2023 09:38:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlGsM6GCI9x9bgbCuZXsBR/fntbMlcHxShZnaYQACV9Kc7Bib8DxehLAZabYJaOMw+b9DGnT X-Received: by 2002:ad4:5947:0:b0:635:fa7b:6c1f with SMTP id eo7-20020ad45947000000b00635fa7b6c1fmr16123002qvb.62.1688488689383; Tue, 04 Jul 2023 09:38:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688488689; cv=none; d=google.com; s=arc-20160816; b=GO+YfpB0kMlF4EJ9uXvnTyxakgyPhmvHKtLZ9oiCAEDnri7condp9uKFHnJqY79w9X ICYATrleXj4Y6r3jqGnxgiAJ2fUFpzAJgm9GWzhskhs3Y9woe/5FRzr3cgNxxazlBjfD l6aPkaXeev+sHuIBPPA0yrY5bIq0+60cEz2jtHXMUEoyBfcNQWJ3crH/kTee5upk4Ls+ azAi/UMWZw+IWVsz5iPdOjy31kInLQUBmyp1bL+UxAtGks7cIrHMiz6iST6RkVksbeDj /VLeBsf8BcHtxyD0WWPT7x3iNH8WdYZBzJ7sK98xtW0VMTaAncPZ5QEEHhz6j/xHXWXV YgNg== 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:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=REQxdvHqMD5dtevjQjK3Wnx/HFYuQ118HppndU5qJ5M=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=Bh+m/Wl314YSG0U8BfyrXEUE9x1B0qhx0tmLwppj0PFGkCv/c0m7rl3OGmKymhInUK l/ELEZsjCwbNVa208VkzhWL20PIzPxfZICZvlqfhVCYWIZiPWcAJNtoiFeR8PAlgulli qLOhI1Kf18mY79GncFunPtc3K3/E8cPQx7VL2Gp9eOtS5o/+IF7pYTF/OBwGkULY/kBc Qka5GZ/AQQYFYepHKlHGQlyIBvITGmLEGAAL/iod5gdXhBTW1zSFpSzO8f2smD8rP7Uh 1xZFzF6aGL3etJLLCKsQUwds1FgPRX2DuxH3zUGa23/dL3uDg+aPLKkONZmuUfAyhuZQ 9ecw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CRa2WQ7k; 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 jf15-20020a0562142a4f00b005ef8c578589si12843749qvb.297.2023.07.04.09.38.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Jul 2023 09:38:09 -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=CRa2WQ7k; 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 1qGj1H-0001MV-7N; Tue, 04 Jul 2023 12:36:51 -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 1qGj1E-0001Jy-9I for qemu-devel@nongnu.org; Tue, 04 Jul 2023 12:36:48 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qGj1B-0001q0-7y for qemu-devel@nongnu.org; Tue, 04 Jul 2023 12:36:48 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3143ccb0f75so1564019f8f.0 for ; Tue, 04 Jul 2023 09:36:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688488600; x=1691080600; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=REQxdvHqMD5dtevjQjK3Wnx/HFYuQ118HppndU5qJ5M=; b=CRa2WQ7kV4gpM/nsg/Kd4DyhiYAfcXKhsZFfcOQa8ILOkYJSdX+GN3PifsLNC+VIlg pn+tRnqo7CY9H4JRmR/Gmtp+HQbNgsrjZBsyVhZoOMpWQ6WH0YELj26jBS5ZiCg6fmn/ /gAfkYfrOIBlxaPdyBzpq58SdZUeKjUxvcufw/2kX9WqeofT06TaIRYJqEktyHMNjED9 LG3l0O5CSm99Nv/aqSnoPWnvyAziI27eCRW5sjDe0Serut7tuMnqRkHDjPcihsb3rUZA E50KKbiS0jw6fZF9nSZfm11xwKlV05Ca9OM4Mmkhs0iNwuZAHpzI+bDeTn5yp2B2M0CU hJ0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688488600; x=1691080600; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=REQxdvHqMD5dtevjQjK3Wnx/HFYuQ118HppndU5qJ5M=; b=JE6KifgbcyvJx3QZmnoLI93h4K/vV0pquAmXvu+0o5JCHvZLTbY9lYEUPfJz4UVRAH Ldbs13hmx6Dlp1IZRUCMNAMj3Vd6cNgcW+Fp5w3EIBw9vxw4bMeaeJC+mtWxjwRXW0KL OufxlH0Y8SkEaiTymchhhE/CGKPX3hYBsYXdyCOvY76MYwBJwS22ywpA5mwFExqpXhPk DyHPEPNhb+MxdWD6G8txU8UQZZV/G+gUyRATaQbn6VAEal6eEf9j9NfqvFC/fKRTP57L rEu9faYD3vuTV08PdLa4N/rfvI4W1R397XSKfokKTA/S7tbPcNeNG24WP5kgbClVk1RV VhqQ== X-Gm-Message-State: ABy/qLbdQN7/DeTrx6bhJtIT+jrALZ7VI8IF1qg6ox3Ups2H+/86gyzo yctXB2eqDl0KNjfosINdOMeNQYjQCnh6zRzYQhg= X-Received: by 2002:a5d:4529:0:b0:314:388b:361b with SMTP id j9-20020a5d4529000000b00314388b361bmr7870389wra.12.1688488600526; Tue, 04 Jul 2023 09:36:40 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r8-20020a056000014800b003143b032b7asm4354258wrx.116.2023.07.04.09.36.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jul 2023 09:36:40 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 11/11] target/xtensa: Assert that interrupt level is within bounds Date: Tue, 4 Jul 2023 17:36:34 +0100 Message-Id: <20230704163634.3188465-12-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230704163634.3188465-1-peter.maydell@linaro.org> References: <20230704163634.3188465-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x436.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 Message-id: 20230623154135.1930261-1-peter.maydell@linaro.org --- 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] =