This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] i386: Check vector length for vshufXXX/vinsertXXX/vextractXXX


Since not all vector lengths are supported by vshufXXX, vinsertXXX and
vextractXXX, decode them only with supported vector lengths.

gas/

PR binutils/24691
* testsuite/gas/i386/disassem.s: Add tests for invalid vector
lengths for vshuff32x4.
* testsuite/gas/i386/x86-64-disassem.s: Likewise.
* testsuite/gas/i386/disassem.d: Updated.
* testsuite/gas/i386/x86-64-disassem.d: Likewise.

opcodes/

PR binutils/24691
* i386-dis-evex.h (evex_table): Update EVEX_W_0F3A23_P_2,
EVEX_W_0F3A38_P_2, EVEX_W_0F3A39_P_2, EVEX_W_0F3A3A_P_2,
EVEX_W_0F3A3B_P_2 and EVEX_W_0F3A43_P_2.
(evex_len_table): Add EVEX_LEN_0F3A23_P_2_W_0,
EVEX_LEN_0F3A23_P_2_W_1, EVEX_LEN_0F3A38_P_2_W_0,
EVEX_LEN_0F3A38_P_2_W_1, EVEX_LEN_0F3A39_P_2_W_0,
EVEX_LEN_0F3A39_P_2_W_1, EVEX_LEN_0F3A3A_P_2_W_0,
EVEX_LEN_0F3A3A_P_2_W_1, EVEX_LEN_0F3A3B_P_2_W_0,
EVEX_LEN_0F3A3B_P_2_W_1, EVEX_LEN_0F3A43_P_2_W_0 and
EVEX_LEN_0F3A43_P_2_W_1.
* i386-dis.c (EVEX_LEN_0F3A23_P_2_W_0): New enum.
(EVEX_LEN_0F3A23_P_2_W_1): Likewise.
(EVEX_LEN_0F3A38_P_2_W_0): Likewise.
(EVEX_LEN_0F3A38_P_2_W_1): Likewise.
(EVEX_LEN_0F3A39_P_2_W_0): Likewise.
(EVEX_LEN_0F3A39_P_2_W_1): Likewise.
(EVEX_LEN_0F3A3A_P_2_W_0): Likewise.
(EVEX_LEN_0F3A3A_P_2_W_1): Likewise.
(EVEX_LEN_0F3A3B_P_2_W_0): Likewise.
(EVEX_LEN_0F3A3B_P_2_W_1): Likewise.
(EVEX_LEN_0F3A43_P_2_W_0): Likewise.
(EVEX_LEN_0F3A43_P_2_W_1): Likewise.

-- 
H.J.
From 16577c4ff9dbf85f772c841bd6a79879e83e6f5a Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Mon, 17 Jun 2019 10:03:02 -0700
Subject: [PATCH] i386: Check vector length for vshufXXX/vinsertXXX/vextractXXX

Since not all vector lengths are supported by vshufXXX, vinsertXXX and
vextractXXX, decode them only with supported vector lengths.

gas/

	PR binutils/24691
	* testsuite/gas/i386/disassem.s: Add tests for invalid vector
	lengths for vshuff32x4.
	* testsuite/gas/i386/x86-64-disassem.s: Likewise.
	* testsuite/gas/i386/disassem.d: Updated.
	* testsuite/gas/i386/x86-64-disassem.d: Likewise.

opcodes/

	PR binutils/24691
	* i386-dis-evex.h (evex_table): Update EVEX_W_0F3A23_P_2,
	EVEX_W_0F3A38_P_2, EVEX_W_0F3A39_P_2, EVEX_W_0F3A3A_P_2,
	EVEX_W_0F3A3B_P_2 and EVEX_W_0F3A43_P_2.
	(evex_len_table): Add EVEX_LEN_0F3A23_P_2_W_0,
	EVEX_LEN_0F3A23_P_2_W_1, EVEX_LEN_0F3A38_P_2_W_0,
	EVEX_LEN_0F3A38_P_2_W_1, EVEX_LEN_0F3A39_P_2_W_0,
	EVEX_LEN_0F3A39_P_2_W_1, EVEX_LEN_0F3A3A_P_2_W_0,
	EVEX_LEN_0F3A3A_P_2_W_1, EVEX_LEN_0F3A3B_P_2_W_0,
	EVEX_LEN_0F3A3B_P_2_W_1, EVEX_LEN_0F3A43_P_2_W_0 and
	EVEX_LEN_0F3A43_P_2_W_1.
	* i386-dis.c (EVEX_LEN_0F3A23_P_2_W_0): New enum.
	(EVEX_LEN_0F3A23_P_2_W_1): Likewise.
	(EVEX_LEN_0F3A38_P_2_W_0): Likewise.
	(EVEX_LEN_0F3A38_P_2_W_1): Likewise.
	(EVEX_LEN_0F3A39_P_2_W_0): Likewise.
	(EVEX_LEN_0F3A39_P_2_W_1): Likewise.
	(EVEX_LEN_0F3A3A_P_2_W_0): Likewise.
	(EVEX_LEN_0F3A3A_P_2_W_1): Likewise.
	(EVEX_LEN_0F3A3B_P_2_W_0): Likewise.
	(EVEX_LEN_0F3A3B_P_2_W_1): Likewise.
	(EVEX_LEN_0F3A43_P_2_W_0): Likewise.
	(EVEX_LEN_0F3A43_P_2_W_1): Likewise.
---
 gas/testsuite/gas/i386/disassem.d        |   4 +-
 gas/testsuite/gas/i386/disassem.s        |   2 +
 gas/testsuite/gas/i386/x86-64-disassem.d |   4 +-
 gas/testsuite/gas/i386/x86-64-disassem.s |   2 +
 opcodes/i386-dis-evex.h                  | 108 ++++++++++++++++++++---
 opcodes/i386-dis.c                       |  14 ++-
 6 files changed, 119 insertions(+), 15 deletions(-)

diff --git a/gas/testsuite/gas/i386/disassem.d b/gas/testsuite/gas/i386/disassem.d
index 530e3a17d5..27f37b6e2f 100644
--- a/gas/testsuite/gas/i386/disassem.d
+++ b/gas/testsuite/gas/i386/disassem.d
@@ -347,6 +347,8 @@ Disassembly of section \.text:
 [ 	]*[a-f0-9]+:[ 	]*62 f2 ad 08 1c[ 	]*\(bad\)[ ]*
 [ 	]*[a-f0-9]+:[ 	]*01 01[ 	]*add[ 	]*%eax,\(%ecx\)
 [ 	]*[a-f0-9]+:[ 	]*62 f3 7d 28 1b[ 	]*\(bad\)[ ]*
-[ 	]*[a-f0-9]+:[ 	]*c8[ 	]*.byte[ 	]*0xc8
+[ 	]*[a-f0-9]+:[ 	]*c8 25 62 f3[ 	]*enter[ ]*\$0x6225,\$0xf3
+[ 	]*[a-f0-9]+:[ 	]*62 f3 75 08 23[ 	]*\(bad\)[ ]*
+[ 	]*[a-f0-9]+:[ 	]*c2[ 	]*.byte[ 	]*0xc2
 [ 	]*[a-f0-9]+:[ 	]*25[ 	]*.byte[ 	]*0x25
 #pass
diff --git a/gas/testsuite/gas/i386/disassem.s b/gas/testsuite/gas/i386/disassem.s
index 00eeb396d4..d330018756 100644
--- a/gas/testsuite/gas/i386/disassem.s
+++ b/gas/testsuite/gas/i386/disassem.s
@@ -171,3 +171,5 @@
 .byte 0x62, 0xf2, 0xad, 0x08, 0x1c, 0x01
 .byte 0x1
 .byte 0x62, 0xf3, 0x7d, 0x28, 0x1b, 0xc8, 0x25
+.byte 0x62, 0xf3
+.byte 0x62, 0xf3, 0x75, 0x08, 0x23, 0xc2, 0x25
diff --git a/gas/testsuite/gas/i386/x86-64-disassem.d b/gas/testsuite/gas/i386/x86-64-disassem.d
index a7c2c3ec96..3dcbc104eb 100644
--- a/gas/testsuite/gas/i386/x86-64-disassem.d
+++ b/gas/testsuite/gas/i386/x86-64-disassem.d
@@ -346,6 +346,8 @@ Disassembly of section \.text:
 [ 	]*[a-f0-9]+:[ 	]*62 72 ad 08 1c[ 	]*\(bad\)[ ]*
 [ 	]*[a-f0-9]+:[ 	]*01 01[ 	]*add[ 	]*%eax,\(%rcx\)
 [ 	]*[a-f0-9]+:[ 	]*62 f3 7d 28 1b[ 	]*\(bad\)[ ]*
-[ 	]*[a-f0-9]+:[ 	]*c8[ 	]*.byte[ 	]*0xc8
+[ 	]*[a-f0-9]+:[ 	]*c8 25 62 f3[ 	]*enterq[ ]*\$0x6225,\$0xf3
+[ 	]*[a-f0-9]+:[ 	]*62 f3 75 08 23[ 	]*\(bad\)[ ]*
+[ 	]*[a-f0-9]+:[ 	]*c2[ 	]*.byte[ 	]*0xc2
 [ 	]*[a-f0-9]+:[ 	]*25[ 	]*.byte[ 	]*0x25
 #pass
diff --git a/gas/testsuite/gas/i386/x86-64-disassem.s b/gas/testsuite/gas/i386/x86-64-disassem.s
index ef4e87d14c..7535052760 100644
--- a/gas/testsuite/gas/i386/x86-64-disassem.s
+++ b/gas/testsuite/gas/i386/x86-64-disassem.s
@@ -171,3 +171,5 @@
 .byte 0x62, 0x72, 0xad, 0x08, 0x1c, 0x01
 .byte 0x1
 .byte 0x62, 0xf3, 0x7d, 0x28, 0x1b, 0xc8, 0x25
+.byte 0x62, 0xf3
+.byte 0x62, 0xf3, 0x75, 0x08, 0x23, 0xc2, 0x25
diff --git a/opcodes/i386-dis-evex.h b/opcodes/i386-dis-evex.h
index 0003e7791d..f34f8bc1a1 100644
--- a/opcodes/i386-dis-evex.h
+++ b/opcodes/i386-dis-evex.h
@@ -3940,28 +3940,28 @@ static const struct dis386 evex_table[][256] = {
   },
   /* EVEX_W_0F3A23_P_2 */
   {
-    { "vshuff32x4",	{ XM, Vex, EXx, Ib }, 0 },
-    { "vshuff64x2",	{ XM, Vex, EXx, Ib }, 0 },
+    { EVEX_LEN_TABLE (EVEX_LEN_0F3A23_P_2_W_0) },
+    { EVEX_LEN_TABLE (EVEX_LEN_0F3A23_P_2_W_1) },
   },
   /* EVEX_W_0F3A38_P_2 */
   {
-    { "vinserti32x4",	{ XM, Vex, EXxmm, Ib }, 0 },
-    { "vinserti64x2",	{ XM, Vex, EXxmm, Ib }, 0 },
+    { EVEX_LEN_TABLE (EVEX_LEN_0F3A38_P_2_W_0) },
+    { EVEX_LEN_TABLE (EVEX_LEN_0F3A38_P_2_W_1) },
   },
   /* EVEX_W_0F3A39_P_2 */
   {
-    { "vextracti32x4",	{ EXxmm, XM, Ib }, 0 },
-    { "vextracti64x2",	{ EXxmm, XM, Ib }, 0 },
+    { EVEX_LEN_TABLE (EVEX_LEN_0F3A39_P_2_W_0) },
+    { EVEX_LEN_TABLE (EVEX_LEN_0F3A39_P_2_W_1) },
   },
   /* EVEX_W_0F3A3A_P_2 */
   {
-    { "vinserti32x8",	{ XM, Vex, EXxmmq, Ib }, 0 },
-    { "vinserti64x4",	{ XM, Vex, EXxmmq, Ib }, 0 },
+    { EVEX_LEN_TABLE (EVEX_LEN_0F3A3A_P_2_W_0) },
+    { EVEX_LEN_TABLE (EVEX_LEN_0F3A3A_P_2_W_1) },
   },
   /* EVEX_W_0F3A3B_P_2 */
   {
-    { "vextracti32x8",	{ EXxmmq, XM, Ib }, 0 },
-    { "vextracti64x4",	{ EXxmmq, XM, Ib }, 0 },
+    { EVEX_LEN_TABLE (EVEX_LEN_0F3A3B_P_2_W_0) },
+    { EVEX_LEN_TABLE (EVEX_LEN_0F3A3B_P_2_W_1) },
   },
   /* EVEX_W_0F3A3E_P_2 */
   {
@@ -3979,8 +3979,8 @@ static const struct dis386 evex_table[][256] = {
   },
   /* EVEX_W_0F3A43_P_2 */
   {
-    { "vshufi32x4",	{ XM, Vex, EXx, Ib }, 0 },
-    { "vshufi64x2",	{ XM, Vex, EXx, Ib }, 0 },
+    { EVEX_LEN_TABLE (EVEX_LEN_0F3A43_P_2_W_0) },
+    { EVEX_LEN_TABLE (EVEX_LEN_0F3A43_P_2_W_1) },
   },
   /* EVEX_W_0F3A50_P_2 */
   {
@@ -4185,4 +4185,88 @@ static const struct dis386 evex_table[][256] = {
     { "vextractf64x4",	{ EXxmmq, XM, Ib }, 0 },
   },
 
+  /* EVEX_LEN_0F3A23_P_2_W_0 */
+  {
+    { Bad_Opcode },
+    { "vshuff32x4",	{ XM, Vex, EXx, Ib }, 0 },
+    { "vshuff32x4",	{ XM, Vex, EXx, Ib }, 0 },
+  },
+
+  /* EVEX_LEN_0F3A23_P_2_W_1 */
+  {
+    { Bad_Opcode },
+    { "vshuff64x2",	{ XM, Vex, EXx, Ib }, 0 },
+    { "vshuff64x2",	{ XM, Vex, EXx, Ib }, 0 },
+  },
+
+  /* EVEX_LEN_0F3A38_P_2_W_0 */
+  {
+    { Bad_Opcode },
+    { "vinserti32x4",	{ XM, Vex, EXxmm, Ib }, 0 },
+    { "vinserti32x4",	{ XM, Vex, EXxmm, Ib }, 0 },
+  },
+
+  /* EVEX_LEN_0F3A38_P_2_W_1 */
+  {
+    { Bad_Opcode },
+    { "vinserti64x2",	{ XM, Vex, EXxmm, Ib }, 0 },
+    { "vinserti64x2",	{ XM, Vex, EXxmm, Ib }, 0 },
+  },
+
+  /* EVEX_LEN_0F3A39_P_2_W_0 */
+  {
+    { Bad_Opcode },
+    { "vextracti32x4",	{ EXxmm, XM, Ib }, 0 },
+    { "vextracti32x4",	{ EXxmm, XM, Ib }, 0 },
+  },
+
+  /* EVEX_LEN_0F3A39_P_2_W_1 */
+  {
+    { Bad_Opcode },
+    { "vextracti64x2",	{ EXxmm, XM, Ib }, 0 },
+    { "vextracti64x2",	{ EXxmm, XM, Ib }, 0 },
+  },
+
+  /* EVEX_LEN_0F3A3A_P_2_W_0 */
+  {
+    { Bad_Opcode },
+    { "vinserti32x8",	{ XM, Vex, EXxmmq, Ib }, 0 },
+    { "vinserti32x8",	{ XM, Vex, EXxmmq, Ib }, 0 },
+  },
+
+  /* EVEX_LEN_0F3A3A_P_2_W_1 */
+  {
+    { Bad_Opcode },
+    { "vinserti64x4",	{ XM, Vex, EXxmmq, Ib }, 0 },
+    { "vinserti64x4",	{ XM, Vex, EXxmmq, Ib }, 0 },
+  },
+
+  /* EVEX_LEN_0F3A3B_P_2_W_0 */
+  {
+    { Bad_Opcode },
+    { "vextracti32x8",	{ EXxmmq, XM, Ib }, 0 },
+    { "vextracti32x8",	{ EXxmmq, XM, Ib }, 0 },
+  },
+
+  /* EVEX_LEN_0F3A3B_P_2_W_1 */
+  {
+    { Bad_Opcode },
+    { "vextracti64x4",	{ EXxmmq, XM, Ib }, 0 },
+    { "vextracti64x4",	{ EXxmmq, XM, Ib }, 0 },
+  },
+
+  /* EVEX_LEN_0F3A43_P_2_W_0 */
+  {
+    { Bad_Opcode },
+    { "vshufi32x4",	{ XM, Vex, EXx, Ib }, 0 },
+    { "vshufi32x4",	{ XM, Vex, EXx, Ib }, 0 },
+  },
+
+  /* EVEX_LEN_0F3A43_P_2_W_1 */
+  {
+    { Bad_Opcode },
+    { "vshufi64x2",	{ XM, Vex, EXx, Ib }, 0 },
+    { "vshufi64x2",	{ XM, Vex, EXx, Ib }, 0 },
+  },
+
 #endif /* NEED_EVEX_LEN_TABLE */
diff --git a/opcodes/i386-dis.c b/opcodes/i386-dis.c
index 5d1bd6b030..496b8f26a8 100644
--- a/opcodes/i386-dis.c
+++ b/opcodes/i386-dis.c
@@ -1945,7 +1945,19 @@ enum
   EVEX_LEN_0F3A1A_P_2_W_0,
   EVEX_LEN_0F3A1A_P_2_W_1,
   EVEX_LEN_0F3A1B_P_2_W_0,
-  EVEX_LEN_0F3A1B_P_2_W_1
+  EVEX_LEN_0F3A1B_P_2_W_1,
+  EVEX_LEN_0F3A23_P_2_W_0,
+  EVEX_LEN_0F3A23_P_2_W_1,
+  EVEX_LEN_0F3A38_P_2_W_0,
+  EVEX_LEN_0F3A38_P_2_W_1,
+  EVEX_LEN_0F3A39_P_2_W_0,
+  EVEX_LEN_0F3A39_P_2_W_1,
+  EVEX_LEN_0F3A3A_P_2_W_0,
+  EVEX_LEN_0F3A3A_P_2_W_1,
+  EVEX_LEN_0F3A3B_P_2_W_0,
+  EVEX_LEN_0F3A3B_P_2_W_1,
+  EVEX_LEN_0F3A43_P_2_W_0,
+  EVEX_LEN_0F3A43_P_2_W_1
 };
 
 enum
-- 
2.20.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]