From patchwork Thu Mar 7 18:56:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 159920 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp7813181jad; Thu, 7 Mar 2019 11:28:09 -0800 (PST) X-Google-Smtp-Source: APXvYqxBm9O5twih91TQVt11Xyni6PCO3jlIPUofLfFQRYwIG8frLzL9zGvz/Yk5BmS4Ga013tUC X-Received: by 2002:a81:3347:: with SMTP id z68mr11353897ywz.11.1551986889790; Thu, 07 Mar 2019 11:28:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551986889; cv=none; d=google.com; s=arc-20160816; b=X/25YUSqHZ4MmXz9c1qrHNEbWuMO8Bx2Hl9uigNESukvbBHRIt+juKMaOXU89K2NY4 OI3aRq4xIxVX+Y9gbCMVjKZz6cpxgKzEEOZvK7fsyvMFkLwse4Hq4rCSqO5Bhx0VWcOm ydKvhWimWhAr+iWVDpNKQnrgbBR/VmQ0cTjx7Fdb+6mnUpYs+SEzbwcudtBphZJ1RqWt O+nLzsQgViOPlsJyFPF7cBTR4En7Rh8B0OSmxg3y2WL4e7d0Joht6W5TfBdlI0C2rkQs FwqxNBGwmcuUQtqaxEX+Q9JmcBEKevxEADqt+MO7QMN72NJ4eODSmX5/GDcOMrXAUwb6 R+/A== 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:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=nW8JphH6Qh+JwrnKEHPQE427juS/l8m1uTk3laZENPE=; b=LWDqhDiGMQBHhdDlA7J6TWQCFsTvmcbvZQ0eIiRKol8T2pdvPSKaDx9Ui30YKn8Fcs RUCjgc8egsOuIu9DLwi7/OV0N2xvSOGkR4QEaLm1+FlQSJwLt3ilwCxoWV34gKyeXXzD Rq79NBcIXr6Ar5Yq0i7L8oZo9ymGuLn0Fy52rtCCUOnNdUdjTghQO7KgWJNMPYIMWI7a FllrXfNtvjCuPo6CQISj2LItnqnZaufnCbwsnENFW4lyl4GPMq9fQVO5Y913/tVVfw2X SjYBJ1CkYPnSWRl4pXo6r4nWuzuZReHLL9FOKNkh5qmheAg3BJe6/cDadmnahgz+J4PH 74sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="rS/BGypu"; 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=fail (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 a4si3302236ybp.426.2019.03.07.11.28.09 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Mar 2019 11:28:09 -0800 (PST) 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=fail header.i=@linaro.org header.s=google header.b="rS/BGypu"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:58129 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1ygb-000311-7F for patch@linaro.org; Thu, 07 Mar 2019 14:28:09 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36933) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1yC9-0001Qv-Ow for qemu-devel@nongnu.org; Thu, 07 Mar 2019 13:56:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1yC8-0002ZP-N5 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 13:56:41 -0500 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]:33904) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1yC8-0002Xz-EA for qemu-devel@nongnu.org; Thu, 07 Mar 2019 13:56:40 -0500 Received: by mail-pf1-x432.google.com with SMTP id u9so12138361pfn.1 for ; Thu, 07 Mar 2019 10:56:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=nW8JphH6Qh+JwrnKEHPQE427juS/l8m1uTk3laZENPE=; b=rS/BGypu/qEfjzfSehSc224dhT/p4UOaZRercF5tbrLIsz6PzMA4LwA+WLCyNh++8V +jkJeC8kvdEewwuX82aYoEXS2NCO2Ol1BbWc+TRvijXqXs3WfkVvZ6Xhyp7zHB1AAVW/ 3yr+pI3zi6Iq1s1K1DqOSR11+B7VsFeIWJ1zXbbIDMBxntUatdvnGehTLW7KdBWeYYup obTxWz65rwZUwt4JWlA4j5bdlHaBmh8SuzZlvZaNdRzd2jnSIAW/XIKmoRNBmv3xtj4m WzjDBVvrqY2axl5bagc9lUshTUSvfe1uMsMflqJB+Eg768T4In08QCwcIcshWRNmpbTU TrCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=nW8JphH6Qh+JwrnKEHPQE427juS/l8m1uTk3laZENPE=; b=S5gMvMi4y3gOHutFu8fEZHPFsxRfi7fXnCacTf9xQRfg7pLgKc2Yi8uhuAPfSWJY5f AL7jPnVGzSrAddD4zaVauS/yX14Kiiyuw5jSYYE/3bMzRr/oZ9mw8+kuTT0nw6wcK1os XEONxoPpyVRYsolLWtNygvQ0C7uLK3oPfiDUK8f2V57xCbiuHMgLLSTNNeHW+rjhnMeW OMJR7qcM273jcJU/2V7YgTKBsgSxB0ieDOm1UiH+ZayWQXwATvdMcLO/51q55xjxLmCR cMy099uK/JCdrnOBUxIW2PrlnI2mABOxVW9VLt592aXC7wqcUQL/bBCSDKl8+dP59vsz jLKg== X-Gm-Message-State: APjAAAX8zX9L4kmmuXikFpACmQii5q2JGQJX1lZif4cvfyyMXhVBQIOz rtPpYhCD62kK5fIb+0142rBYSEYBWNM= X-Received: by 2002:a63:d542:: with SMTP id v2mr12828091pgi.52.1551984998961; Thu, 07 Mar 2019 10:56:38 -0800 (PST) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id g12sm8801973pgr.76.2019.03.07.10.56.37 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Mar 2019 10:56:38 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 10:56:22 -0800 Message-Id: <20190307185622.29026-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190307185622.29026-1-richard.henderson@linaro.org> References: <20190307185622.29026-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::432 Subject: [Qemu-devel] [PATCH v3 12/12] decodetree: Properly diagnose fields overflowing an insn X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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" Previously this would result in an exception for shifting the field mask by a negative number. Signed-off-by: Richard Henderson --- scripts/decodetree.py | 2 ++ tests/decode/err_width1.decode | 5 +++++ tests/decode/err_width2.decode | 5 +++++ tests/decode/err_width3.decode | 5 +++++ tests/decode/err_width4.decode | 5 +++++ 5 files changed, 22 insertions(+) create mode 100644 tests/decode/err_width1.decode create mode 100644 tests/decode/err_width2.decode create mode 100644 tests/decode/err_width3.decode create mode 100644 tests/decode/err_width4.decode -- 2.17.2 diff --git a/scripts/decodetree.py b/scripts/decodetree.py index f8df89e072..7e890ecf1a 100755 --- a/scripts/decodetree.py +++ b/scripts/decodetree.py @@ -622,6 +622,8 @@ def parse_generic(lineno, is_format, name, toks): sign = True flen = flen[1:] shift = int(flen, 10) + if shift + width > insnwidth: + error(lineno, 'field {0} exceeds insnwidth'.format(fname)) f = Field(sign, insnwidth - width - shift, shift) flds = add_field(lineno, flds, fname, f) fixedbits <<= shift diff --git a/tests/decode/err_width1.decode b/tests/decode/err_width1.decode new file mode 100644 index 0000000000..0c14f6d73b --- /dev/null +++ b/tests/decode/err_width1.decode @@ -0,0 +1,5 @@ +# This work is licensed under the terms of the GNU LGPL, version 2 or later. +# See the COPYING.LIB file in the top-level directory. + +# Diagnose too many bits (33 of 32) +one 000000000000000000000000000000000 diff --git a/tests/decode/err_width2.decode b/tests/decode/err_width2.decode new file mode 100644 index 0000000000..47f0acf322 --- /dev/null +++ b/tests/decode/err_width2.decode @@ -0,0 +1,5 @@ +# This work is licensed under the terms of the GNU LGPL, version 2 or later. +# See the COPYING.LIB file in the top-level directory. + +# Diagnose too few bits (31 of 32) +one 0000000000000000000000000000000 diff --git a/tests/decode/err_width3.decode b/tests/decode/err_width3.decode new file mode 100644 index 0000000000..c5fb6b3699 --- /dev/null +++ b/tests/decode/err_width3.decode @@ -0,0 +1,5 @@ +# This work is licensed under the terms of the GNU LGPL, version 2 or later. +# See the COPYING.LIB file in the top-level directory. + +# Diagnose too many bits (33 of 32) +one 0 s:32 diff --git a/tests/decode/err_width4.decode b/tests/decode/err_width4.decode new file mode 100644 index 0000000000..1588a63698 --- /dev/null +++ b/tests/decode/err_width4.decode @@ -0,0 +1,5 @@ +# This work is licensed under the terms of the GNU LGPL, version 2 or later. +# See the COPYING.LIB file in the top-level directory. + +# Diagnose too few bits (31 of 32) +one 0 s:30