From patchwork Wed Jul 12 06:08:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 701852 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp6090285wrs; Tue, 11 Jul 2023 23:09:16 -0700 (PDT) X-Google-Smtp-Source: APBJJlGVrhoI0HnbmO+umjayphzrnRS3Cy27gzRsuxlFPVM71d1w8Mgdz7HX0JtEEeCqTc54kcu3 X-Received: by 2002:a05:620a:1213:b0:767:1152:aca7 with SMTP id u19-20020a05620a121300b007671152aca7mr15308929qkj.36.1689142155812; Tue, 11 Jul 2023 23:09:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689142155; cv=none; d=google.com; s=arc-20160816; b=mENRTIP5rwgJ1tKo0u56IMJyVYsez0o4a1RY05pc7Z+fwUGRGhlz0PEi2VHdl1bEiq mbnBZqxRMrgoetziJYpKn8zyA8SllCXsG4K0LQuJ+tFAClaPRa8piAnXlkjyt2/ysJlg WzOOvKKFKdNxtShG5TRFstsmTRYf7+h1qathnZz6tpdhmdArZGOpYf4OjxIH6bOM2/6D WqqGTdREO0VczuELIF3ZBjyku2yv8HgBJaZ1G7Q2fT5OV7Gk0Pd40uiuGETjTraE5pav HePy3rJ66zw4ew+0yRBIgfrUdWkwsRiP9py27Gj+NjogSo3WVz4sUikPj5BVrk1GmBDP x3aw== 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:cc:to :from:dkim-signature; bh=GS0NAFoYmodsd+bnZXz/vhH/Pb85MlJHayRsbvu1zWo=; fh=gncb2ZEkLwRFJnutws/sJQnEgWLhbcvWiAGqvuCkWus=; b=Ac3fBFF2kqIwNURUMaQA8msvk383JMwx6YVnypxbC2FMN7DyRH5dnqAWOg9obaBPc/ GDCP1nIP1YK5WSEhMricRpw/z93/PWRDpXgLcKLk2wiVI5GrM1CxWs6a73oymsBAGNpD EL/PBOR/HuskIaH+xN0isYixsK8ECPztszO8P4ZbfF9unU8tcxuscv4PBvJuUGPu9m5D evLZaREf0QWNJYpwrS5nH+mndBU98MCFNkZBdJBzg76zOhk4X0KqLJ8eL+Bf8i433utX r3MGVUg8RwqhApAXqqQStQBLAd+CbTIi5R59OQQwF1nICHb9zJbiT+52kjpJSiUZHeay 7Xiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=johqK0Bg; 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 bs35-20020a05620a472300b00767dd2a1dc1si1427512qkb.146.2023.07.11.23.09.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Jul 2023 23:09:15 -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=johqK0Bg; 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 1qJT1T-0000Z1-QW; Wed, 12 Jul 2023 02:08:23 -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 1qJT1N-0000YO-LI for qemu-devel@nongnu.org; Wed, 12 Jul 2023 02:08:19 -0400 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qJT1M-0007Ad-67 for qemu-devel@nongnu.org; Wed, 12 Jul 2023 02:08:17 -0400 Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-51cff235226so847340a12.0 for ; Tue, 11 Jul 2023 23:08:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689142094; x=1691734094; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GS0NAFoYmodsd+bnZXz/vhH/Pb85MlJHayRsbvu1zWo=; b=johqK0BgGk1RALTvmpHMWxHHDmwvH51EXfVsu7J72qvNUINYJIca1/FNFYpouGjuCg LlcmcanRY/dAp3pCZC+y9rx4gluC9dmkGFRdL4o2z0wjnlXLsSMEn4mff5dF/Xx2Z9XT xHOvFC9ZwGyEkb12SD4gE6YHHc9a6W2RllLIpckkQynZr8XOvKN/IDbjT6QWmVrFKHWG QtZDJECh2//pjWmeYHTNGtjYnO7jO6+cnD2kZlo8BxCZj7zyZOvKuhOmyIHZqQuXaN4T OAwuGPoCbBTgzV810RTzAjR0ntO5DzjaplfcdPjzJ/yDiS2fU0L5C2f50+ktw9YQQH2f x80Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689142094; x=1691734094; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GS0NAFoYmodsd+bnZXz/vhH/Pb85MlJHayRsbvu1zWo=; b=dleZ4+lvXoEfpeWNIGUmAY5RvAUamY30kOFszKT7xiVPqUKaTDmDOtLgJF1D6Aftlx 2KuvvZuy3DtCxHSmPq88apGphl6xAP5kWKj3kbuAdK4nelcfrNhS13USenZfHsch/7v2 IKrMBRgeXaPy92OI1gTpcMZLIKLsL3U0XO55SQT0hWOnkuX8RPf9L7S2SRBRsYyoLhyI GPl7/th/B8g/FusHLy4+BLZahentKtHLWHkveaET6zu1EjggHSQv4ZH+Ln3UFzjW2489 qRF1XOfz351KPXN168ERSOkQ9O7vU6ggzWyA6y4eNw94fvoZqARJyj03ZILVNunRsL3G ty6w== X-Gm-Message-State: ABy/qLaFAOW5MZ2BfvzUs7WDEfUHT8dDsMyX0kgA/fyDPHsAxWvdZKXC cc5H5li4b/NWksOvB0cF4nn/tMbHrC27D8JSiLs= X-Received: by 2002:aa7:c98a:0:b0:51e:227c:9492 with SMTP id c10-20020aa7c98a000000b0051e227c9492mr1045019edt.20.1689142094464; Tue, 11 Jul 2023 23:08:14 -0700 (PDT) Received: from m1x-phil.lan ([176.187.194.156]) by smtp.gmail.com with ESMTPSA id k2-20020aa7d8c2000000b0051e2809395bsm2216138eds.63.2023.07.11.23.08.13 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 11 Jul 2023 23:08:14 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Aurelien Jarno , Aleksandar Rikalo , Jiaxun Yang , Siarhei Volkau , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Craig Janeczek Subject: [PATCH-for-8.1 1/3] target/mips/mxu: Replace magic array size by its definition Date: Wed, 12 Jul 2023 08:08:04 +0200 Message-Id: <20230712060806.82323-2-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230712060806.82323-1-philmd@linaro.org> References: <20230712060806.82323-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::535; envelope-from=philmd@linaro.org; helo=mail-ed1-x535.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 Signed-off-by: Philippe Mathieu-Daudé --- target/mips/tcg/mxu_translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/mips/tcg/mxu_translate.c b/target/mips/tcg/mxu_translate.c index deb8060a17..b007948a73 100644 --- a/target/mips/tcg/mxu_translate.c +++ b/target/mips/tcg/mxu_translate.c @@ -609,7 +609,7 @@ enum { static TCGv mxu_gpr[NUMBER_OF_MXU_REGISTERS - 1]; static TCGv mxu_CR; -static const char mxuregnames[][4] = { +static const char mxuregnames[NUMBER_OF_MXU_REGISTERS][4] = { "XR1", "XR2", "XR3", "XR4", "XR5", "XR6", "XR7", "XR8", "XR9", "XR10", "XR11", "XR12", "XR13", "XR14", "XR15", "XCR", }; From patchwork Wed Jul 12 06:08:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 701850 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp6090240wrs; Tue, 11 Jul 2023 23:09:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlG+7QxGnKjL2HQKkyGf7V3ojkWabfOr4UtSXrc7JGUa/3tFYwQupozSUofEoXXV68yQ6FTL X-Received: by 2002:a05:620a:d8b:b0:765:3c4a:6237 with SMTP id q11-20020a05620a0d8b00b007653c4a6237mr843690qkl.16.1689142146816; Tue, 11 Jul 2023 23:09:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689142146; cv=none; d=google.com; s=arc-20160816; b=ZLtL2sz5U4neqdBiBwAY7D4xnEoy9N4xWTRw6GgdCF6du6JoJKV5tnSkNWcRbmzaEY b/7yVHAZy6xnoUAH7ckvtWdIoO3EaW53sIOPF8LEzqEpFGxzCdSGgRrpjRPU55uFMf1Q BkBPjdEF2xyBP7pIvFqUrKSMHpwgdfa/EDTqz9YoKo8iODUzRLofrMOZJ4I5pdLms5wZ dMLOs1zUJA6U24DLUoan4Z7DJMfyD2W6UO2Pah5o763ZMtahjJ1aUUedG+izjy9koGTl 7g8ASPDPh1HynE6N5weipiUQ6MzIWrmyCxKkd3RSs6spWRFuVbXN/n+8BexS40z+tXXa ZUlA== 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:cc:to :from:dkim-signature; bh=23kT9O/dEUBttMJdXxI9Sf+c95dROPXelirqaPaxH6I=; fh=gncb2ZEkLwRFJnutws/sJQnEgWLhbcvWiAGqvuCkWus=; b=lonFX43puMYu9F6E0XD9+7xKtLlunHmHHg5Ref9204PXZD9/EPmsymGVDNw2EeVcNb 4aCVq7mo42Vkjk4YG7Wa9d/9v7r2b+9HzJ/2uxSwIeSeaGXk7Qnkald5zSb/Y/0Jc/Tp v5j4zqXwzpmpRrdzcFcvXq+4McSRZVjnb++6liEKY51QhRuQdavmYmDuuEVu4MIc7oe0 Fh9rJ81Jj5XY6JFz0dPexafE8AmVMIuyTA/b/c17sF1mHFAJXmG2GKumVa7y1t3fL2yG OcWq0bbEvRCKtSSvp+FcdFYI6Mi8StpykHsA0jv1tkIovUIA8qhI/+NRihfGqjaXg2bm fQhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OU4N2bYI; 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 ay10-20020a05620a178a00b00767e7fb7bdbsi801014qkb.171.2023.07.11.23.09.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Jul 2023 23:09:06 -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=OU4N2bYI; 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 1qJT1f-0000cu-9L; Wed, 12 Jul 2023 02:08:37 -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 1qJT1W-0000ZM-B7 for qemu-devel@nongnu.org; Wed, 12 Jul 2023 02:08:27 -0400 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qJT1T-0007UD-46 for qemu-devel@nongnu.org; Wed, 12 Jul 2023 02:08:25 -0400 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-99364ae9596so828508766b.1 for ; Tue, 11 Jul 2023 23:08:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689142100; x=1691734100; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=23kT9O/dEUBttMJdXxI9Sf+c95dROPXelirqaPaxH6I=; b=OU4N2bYIe4wYQngzhBzLF7fkqJ68gGY0NLQUTNLija0WDiTqZgL9SUzQ0aiZzJ3riO JDbFw07t7mIYE4BTdKCJlsZ6uSAoOiPsxoxBnz4kuejNxedOHJyWwu+fxacncAByRBAr PjlzgGRWo9WX1Dl2X9eyxUHWwHppyI/al3Usb6C8oYsh7QX14UoQC/IPacB6az6tXYH/ YzvfyUDT5DjXHLn7z8qKjLXoGe3Y1+TXMZgAiQD4jQQcvaDnwM+0O+iXluy2yoqeE1pI A+iwf2N/dssSlGL3zUa9RaCux79U9Ar71XvT6Pu3rqEH9Lb/qTfc1Gn+3IOk2BxszF0J mezA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689142100; x=1691734100; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=23kT9O/dEUBttMJdXxI9Sf+c95dROPXelirqaPaxH6I=; b=SfwM6PmgspUDeZqTh1NHGEEv5lD+jK7HsQ5VkPNsOiX/+LL8pSAGgCiPVbFAziORNL 8HKFNIRF+I4pubWCG42l2jaqjcf9Bj5TMSfcw6AmtWBJk8d/c/7kPQZK63/A4XA8DsHv I9kPc6kB3FvG5Cwlk4Rb13ZoQJ/hQ4ouIfiatMbGpI+vZ9Zs2ixRjG9nJWNVGkwXW/9C NGdUYhJIzjwq5y5QDGkbWcsYdt+6StEDDuzI0+B/pnu9YB5qLA2VWLihEVjbcAfHe4sC HCqkJHemMhgx55wKxSsdBzUfanT2ZkTAzNpOjw0W44StaGSTauyd9ijIn5Za/jiglqEM ZPNA== X-Gm-Message-State: ABy/qLYHSgul/OMZnd6FGwolbjQ2nJBFCXkMzFfc65gktj0ktU1Zm4ec 6dftC0UaeQdYw15/5SU51wdd6BoVGzUIX4s/Znw= X-Received: by 2002:a17:906:1114:b0:988:a578:4d65 with SMTP id h20-20020a170906111400b00988a5784d65mr15939574eja.32.1689142100088; Tue, 11 Jul 2023 23:08:20 -0700 (PDT) Received: from m1x-phil.lan ([176.187.194.156]) by smtp.gmail.com with ESMTPSA id dc21-20020a170906c7d500b00988b86d6c7csm2041132ejb.132.2023.07.11.23.08.18 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 11 Jul 2023 23:08:19 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Aurelien Jarno , Aleksandar Rikalo , Jiaxun Yang , Siarhei Volkau , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Craig Janeczek Subject: [PATCH-for-8.1 2/3] target/mips/mxu: Avoid overrun in gen_mxu_S32SLT() Date: Wed, 12 Jul 2023 08:08:05 +0200 Message-Id: <20230712060806.82323-3-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230712060806.82323-1-philmd@linaro.org> References: <20230712060806.82323-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62a; envelope-from=philmd@linaro.org; helo=mail-ej1-x62a.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 Coverity reports a potential overrun (CID 1517769): Overrunning array "mxu_gpr" of 15 8-byte elements at element index 4294967295 (byte offset 34359738367) using index "XRb - 1U" (which evaluates to 4294967295). Use gen_load_mxu_gpr() to safely load MXU registers. Fixes: ff7936f009 ("target/mips/mxu: Add S32SLT ... insns") Signed-off-by: Philippe Mathieu-Daudé --- target/mips/tcg/mxu_translate.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/target/mips/tcg/mxu_translate.c b/target/mips/tcg/mxu_translate.c index b007948a73..520747a597 100644 --- a/target/mips/tcg/mxu_translate.c +++ b/target/mips/tcg/mxu_translate.c @@ -2434,8 +2434,12 @@ static void gen_mxu_S32SLT(DisasContext *ctx) tcg_gen_movi_tl(mxu_gpr[XRa - 1], 0); } else { /* the most general case */ - tcg_gen_setcond_tl(TCG_COND_LT, mxu_gpr[XRa - 1], - mxu_gpr[XRb - 1], mxu_gpr[XRc - 1]); + TCGv t0 = tcg_temp_new(); + TCGv t1 = tcg_temp_new(); + + gen_load_mxu_gpr(t0, XRb); + gen_load_mxu_gpr(t1, XRc); + tcg_gen_setcond_tl(TCG_COND_LT, mxu_gpr[XRa - 1], t0, t1); } } From patchwork Wed Jul 12 06:08:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 701853 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp6090380wrs; Tue, 11 Jul 2023 23:09:38 -0700 (PDT) X-Google-Smtp-Source: APBJJlGllJuslX2U2NHX8BR4vWyLfHhngHCsj/zYokAn7XINoPTY/VhEEy5avtNccLGQ22Hc1MBJ X-Received: by 2002:ac8:5782:0:b0:400:a5e5:35fb with SMTP id v2-20020ac85782000000b00400a5e535fbmr19657683qta.51.1689142178470; Tue, 11 Jul 2023 23:09:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689142178; cv=none; d=google.com; s=arc-20160816; b=isBVwYpX5JA+T5ctMf4Pw5QdyRJTnlSbzwAj/txHyqe8RSz2qjJdFJzMmL7nUStb2t 8qojmzPiUokvjlj7PDX715GLrSO7vL1ss77iyKurR2kvXWbmiZZ1qou4hlEQa4QvFb4L JwLwV9z6YgmjUY3V73tlEyh7JluNzcYymBOF9mKapR1LohhokEF4Jgu7m4U8/+RPtKI7 H3p5b8r/CFCj7tbV8+J7L9ViHYzs6WRqpPmVNjvKAR2y0wLfw2ufhyPmoO35/36Q5qHr ahxL2zXY1leVO8KNYlpA2ArDVAQ4CCpkIAnABcu03oURAlnMP8hQZ5EnYdCCJ7H71qwm arHg== 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:cc:to :from:dkim-signature; bh=fQLSaBAsWK+XKeQRc/Qvxp+d8zerTRXpd0IZR5vliPg=; fh=gncb2ZEkLwRFJnutws/sJQnEgWLhbcvWiAGqvuCkWus=; b=qZ9x/V4fDbxwGp+L6grV14hiM8e1C3b/ABhdH2P6bpJR72rbNOni4N20P5CvWpEIMo NGzM9zC/pTJlDjRJzkb0A9n/Zl9kHvyQpP6GR3CSKPq7S9qMzt4PrZgYj3k/vwYtriGx bN5sBKpHEDgrd/b2hVZrcpqNanX32jOpHfI6Moy8iG7+8L4YyX6zge601pQI4jQOqG67 qfMJGcrO9ZqBDupy35NjI7vbxJ+rsrb1AyhuOgOc41xK0G6fXiKcvTuFFq82dYLEIohd k1tlseRaxFt1Xx3WzUghzE1v0uLz/F23omC65U4b9ByEg1p/kUsdkOXyVKooHjMKX+Qm KU3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IRkLaBZo; 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 e6-20020ac85dc6000000b003f89320f586si1486654qtx.514.2023.07.11.23.09.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Jul 2023 23:09:38 -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=IRkLaBZo; 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 1qJT1t-0000ea-Hm; Wed, 12 Jul 2023 02:08:53 -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 1qJT1c-0000cd-47 for qemu-devel@nongnu.org; Wed, 12 Jul 2023 02:08:32 -0400 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qJT1Y-0007bv-RS for qemu-devel@nongnu.org; Wed, 12 Jul 2023 02:08:31 -0400 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-4fb761efa7aso10318849e87.0 for ; Tue, 11 Jul 2023 23:08:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689142105; x=1691734105; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fQLSaBAsWK+XKeQRc/Qvxp+d8zerTRXpd0IZR5vliPg=; b=IRkLaBZoU/D/qMYeJVPCMXME+EpdQCqcRivPMLnXtedCqePdlpKJssK9/eXBVruD+x af8Sli1er/+oxZqwlVGRQa0lVBWTwu4yXk7l6Dz8HikpMC2OFFV3PFxcK6iH3EcKSL+f hMK7F8llfhKHxl0MpZyuQv5Z+UbxtQv37fh8pnAw2XxapHE7ZvXMG9Fl6Yv0ERrzAT/m CLicv0L33V+begVNZfy+VaZGvxXq/6cuEPsU7EEn2bCVBDkPIFK1WGUFHNBRR6wfsGJW c4Nip1i/AanLdJeD7YSCPFe3zyg6GSbeWSoE5F4QFrXEyqnxvR8ABSamJhIroB9cmLFU gKPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689142105; x=1691734105; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fQLSaBAsWK+XKeQRc/Qvxp+d8zerTRXpd0IZR5vliPg=; b=cjFK4P/SDwL62dAnxhJuBtZyx6qvh+3vZciQJyIEqXlev3feWk43YluPVFEsOJITkE B5iKUY9A5uVb7BaYOUva4kbr1QD2S6zGtrFqjsZwP5QdqdiWnB+hUKE0mPTns5Rq1SS2 19BIQblD4ILtXyYcDjMzniZgogjRM0+CoG6gpJ3/PJI/eKbYLLnQ9ixRskhoehRydYHq QimJ6pXM7+mnL3X5aNuXzHGYYfP5EncxMT2NAZCOLdU3WW6EJlSLB2hOKfNzjrNE/Yy2 gd6wqo41lP7nsUE0UiSd9ba6ycEfhR1/5x+B8slLxCBfbGD5JxvHNWhti6YTfZHKVw25 HV+w== X-Gm-Message-State: ABy/qLa8XX6E41EeIsL/9sES+I7zKVyTajW3LHf7Kzuodz7WyV4xvdlC SQitteXvHngNsLdhoFfB0GFU8/oiEGvUo5yEhVk= X-Received: by 2002:a05:6512:33ce:b0:4f8:5600:9e5e with SMTP id d14-20020a05651233ce00b004f856009e5emr17757744lfg.47.1689142105559; Tue, 11 Jul 2023 23:08:25 -0700 (PDT) Received: from m1x-phil.lan ([176.187.194.156]) by smtp.gmail.com with ESMTPSA id l22-20020a7bc456000000b003fbb5142c4bsm14585383wmi.18.2023.07.11.23.08.24 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 11 Jul 2023 23:08:25 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Aurelien Jarno , Aleksandar Rikalo , Jiaxun Yang , Siarhei Volkau , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Craig Janeczek Subject: [PATCH-for-8.1 3/3] target/mips/mxu: Avoid overrun in gen_mxu_q8adde() Date: Wed, 12 Jul 2023 08:08:06 +0200 Message-Id: <20230712060806.82323-4-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230712060806.82323-1-philmd@linaro.org> References: <20230712060806.82323-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::136; envelope-from=philmd@linaro.org; helo=mail-lf1-x136.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 Coverity reports a potential overruns (CID 1517770): Overrunning array "mxu_gpr" of 15 8-byte elements at element index 4294967295 (byte offset 34359738367) using index "XRb - 1U" (which evaluates to 4294967295). Add a gen_extract_mxu_gpr() helper similar to gen_load_mxu_gpr() to safely extract MXU registers. Fixes: eb79951ab6 ("target/mips/mxu: Add Q8ADDE ... insns") Signed-off-by: Philippe Mathieu-Daudé --- target/mips/tcg/mxu_translate.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/target/mips/tcg/mxu_translate.c b/target/mips/tcg/mxu_translate.c index 520747a597..e662acd5df 100644 --- a/target/mips/tcg/mxu_translate.c +++ b/target/mips/tcg/mxu_translate.c @@ -644,6 +644,16 @@ static inline void gen_store_mxu_gpr(TCGv t, unsigned int reg) } } +static inline void gen_extract_mxu_gpr(TCGv t, unsigned int reg, + unsigned int ofs, unsigned int len) +{ + if (reg == 0) { + tcg_gen_movi_tl(t, 0); + } else if (reg <= 15) { + tcg_gen_extract_tl(t, mxu_gpr[reg - 1], ofs, len); + } +} + /* MXU control register moves. */ static inline void gen_load_mxu_cr(TCGv t) { @@ -3004,10 +3014,10 @@ static void gen_mxu_q8adde(DisasContext *ctx, bool accumulate) TCGv t5 = tcg_temp_new(); if (XRa != 0) { - tcg_gen_extract_tl(t0, mxu_gpr[XRb - 1], 16, 8); - tcg_gen_extract_tl(t1, mxu_gpr[XRc - 1], 16, 8); - tcg_gen_extract_tl(t2, mxu_gpr[XRb - 1], 24, 8); - tcg_gen_extract_tl(t3, mxu_gpr[XRc - 1], 24, 8); + gen_extract_mxu_gpr(t0, XRb, 16, 8); + gen_extract_mxu_gpr(t1, XRc, 16, 8); + gen_extract_mxu_gpr(t2, XRb, 24, 8); + gen_extract_mxu_gpr(t3, XRc, 24, 8); if (aptn2 & 2) { tcg_gen_sub_tl(t0, t0, t1); tcg_gen_sub_tl(t2, t2, t3); @@ -3027,10 +3037,10 @@ static void gen_mxu_q8adde(DisasContext *ctx, bool accumulate) tcg_gen_or_tl(t4, t2, t0); } if (XRd != 0) { - tcg_gen_extract_tl(t0, mxu_gpr[XRb - 1], 0, 8); - tcg_gen_extract_tl(t1, mxu_gpr[XRc - 1], 0, 8); - tcg_gen_extract_tl(t2, mxu_gpr[XRb - 1], 8, 8); - tcg_gen_extract_tl(t3, mxu_gpr[XRc - 1], 8, 8); + gen_extract_mxu_gpr(t0, XRb, 0, 8); + gen_extract_mxu_gpr(t1, XRc, 0, 8); + gen_extract_mxu_gpr(t2, XRb, 8, 8); + gen_extract_mxu_gpr(t3, XRc, 8, 8); if (aptn2 & 1) { tcg_gen_sub_tl(t0, t0, t1); tcg_gen_sub_tl(t2, t2, t3);