From nobody Tue Nov 26 11:33:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1707990682; cv=none; d=zohomail.com; s=zohoarc; b=MOA/HZhRZX8zbwzPZX4Snl73A5P92836O74rNyZoyt9Xua4TorJdox6mojsZIX5egMhoWZJUT8u+F7U6TgtWyYYbwRSIi7Y+0gBIV3NSjlHlDDLkkoT1XHOZG5OpJGEKFmOmUAQQ4WVCP91JQ+LUnU83bLp2nryE6M5lAX8Gppc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707990682; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tv3PHmgqVfkG8uzr9jgyQ4R6Dv3vpujqMroYjdaFpA4=; b=Iut72qBKewQQpVxkdDLv2a4/WdWujUZDmoOjH3hkp2z1bm9berGzZRm6o8iWy4eLcFmQg/WzyLEgrEnBG6lKR1io+y4q0jR6zT+B4pn1BAmnZipZ4RKOuX09Oxb5YOjuqG2n8LIzIWe7AiGqqx3FMG/81fpkCleDHgEd0bvj91w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1707990682359267.9544882847306; Thu, 15 Feb 2024 01:51:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1raYOI-00074b-Sm; Thu, 15 Feb 2024 04:50:50 -0500 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 1raYOH-00074I-MR; Thu, 15 Feb 2024 04:50:49 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1raYOG-0000hI-6j; Thu, 15 Feb 2024 04:50:49 -0500 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1db562438e0so5292525ad.3; Thu, 15 Feb 2024 01:50:47 -0800 (PST) Received: from station.lan ([155.69.190.63]) by smtp.gmail.com with ESMTPSA id a10-20020a170902b58a00b001db839b9e80sm863966pls.286.2024.02.15.01.50.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 01:50:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707990646; x=1708595446; darn=nongnu.org; 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=tv3PHmgqVfkG8uzr9jgyQ4R6Dv3vpujqMroYjdaFpA4=; b=jSB0eKBZVOI3rjKupGnUdRu18DJXm5GsCbpelVQzEAtLH8vBMZTHmHQk+4cLsKI37A aMIlZifnQusMS8ruShaWYQvMi6f2pXfuoGbPkvsIKZB6uuoAP+cjWHiF2uXM4UzOV5Oj 0yU1y+vowY1CB3xIKURW/Dj7+eGLfK9C8JeObKciquc+CqbiYyKF/tVAzdSLosbd2L4Q x4xofWpfymAHeemeiIwXAXqq4/9Q8/BXEiDttGAXyg/hZfyiGetDIx0wKXc0Nd2DUnJ7 rm38WsR6+GTxzZqQaXYSAoLXcahuCCQ/3C92hgBLnYfJcDPMulAz23SVQjmFAjumpL+y LhDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707990646; x=1708595446; 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=tv3PHmgqVfkG8uzr9jgyQ4R6Dv3vpujqMroYjdaFpA4=; b=pdqd6KNqcLlucm03krtzoTCqb1J+sCEmzVBgt1IE2Nj6dznGUyfRv9Ij0g2L/5nyzf DpeWt3D0Crcb8cQqmNB3A9G0EXxe/jdUelWbQjFT46d0Xl/TEUgGWEZVGQZ9wVFOBfGB EOcOG3doBbSn0+/OUy7EO6d/YAdKLW9vEWrND9VyvfwFdqtRmnWPpzAq9aTW3177/g/m xeYSk1o4G0IbHsYimoA1XdYCE9BCu1Brts41VAf7wnheY+ussh/aIOwKm+6s+QD0t2jG B3IQacRLqMb1uioy9+Z0yUgZlu4LhV8Lb+3g69REk/8g9YNYB9DQNssqHoxbaIjrLCap 8tnQ== X-Forwarded-Encrypted: i=1; AJvYcCUQb0FN6GwB+hV4pTJ1kI20SPrf2OswPzRXXP4P4uL3gBsduSiTswlmvgfLvBHPpRZ0FY0wAJ/BpVhafmSG+WGzjWGazA/Lkw== X-Gm-Message-State: AOJu0YzEDMu3u+XORIUJHX2cMDWK4Vx1+LuLVSKbOQ6aIcerK7GReNTT j2DMGWUh/b4GmcEpFvkOqixL3HYOCVAoHDEeDnxvO5F+FBiWb5C4e0oHMfYrj1A= X-Google-Smtp-Source: AGHT+IGShBYkHjz/BJIIVjoiM2ihjKOrUBsPSfr6Ystge7AwGQlNQ9uUYW/fZnweppLdI9c5jYy65A== X-Received: by 2002:a17:902:76ca:b0:1d9:b739:a5aa with SMTP id j10-20020a17090276ca00b001d9b739a5aamr1137788plt.42.1707990646004; Thu, 15 Feb 2024 01:50:46 -0800 (PST) From: Ziqiao Kong To: qemu-devel@nongnu.org Cc: Ziqiao Kong , qemu-trivial@nongnu.org, Richard Henderson Subject: [PATCH 1/1] target/i386: Generate an illegal opcode exception on cmp instructions with lock prefix Date: Thu, 15 Feb 2024 17:50:17 +0800 Message-Id: <20240215095015.570748-2-ziqiaokong@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240215095015.570748-1-ziqiaokong@gmail.com> References: <20240215095015.570748-1-ziqiaokong@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=ziqiaokong@gmail.com; helo=mail-pl1-x629.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, FREEMAIL_FROM=0.001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1707990683263100001 Content-Type: text/plain; charset="utf-8" target/i386: As specified by Intel Manual Vol2 3-180, cmp instructions are not allowed to have lock prefix and a `UD` should be raised. Without this patch, s1->T0 will be uninitialized and used in the case OP_CMPL. Signed-off-by: Ziqiao Kong --- target/i386/tcg/translate.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 10cba16256..07f642dc9e 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -1507,12 +1507,13 @@ static bool check_iopl(DisasContext *s) /* if d =3D=3D OR_TMP0, it means memory operand (address in A0) */ static void gen_op(DisasContext *s1, int op, MemOp ot, int d) { + /* Invalid lock prefix when destination is not memory or OP_CMPL. */ + if ((d !=3D OR_TMP0 || op =3D=3D OP_CMPL) && s1->prefix & PREFIX_LOCK)= { + gen_illegal_opcode(s1); + return; + } + if (d !=3D OR_TMP0) { - if (s1->prefix & PREFIX_LOCK) { - /* Lock prefix when destination is not memory. */ - gen_illegal_opcode(s1); - return; - } gen_op_mov_v_reg(s1, ot, s1->T0, d); } else if (!(s1->prefix & PREFIX_LOCK)) { gen_op_ld_v(s1, ot, s1->T0, s1->A0); --=20 2.40.1