Skip to content

Commit 12cb908

Browse files
mhiramatsuryasaimadhu
authored andcommitted
x86/insn-eval: Use new for_each_insn_prefix() macro to loop over prefixes bytes
Since insn.prefixes.nbytes can be bigger than the size of insn.prefixes.bytes[] when a prefix is repeated, the proper check must be insn.prefixes.bytes[i] != 0 and i < 4 instead of using insn.prefixes.nbytes. Use the new for_each_insn_prefix() macro which does it correctly. Debugged by Kees Cook <[email protected]>. [ bp: Massage commit message. ] Fixes: 32d0b95 ("x86/insn-eval: Add utility functions to get segment selector") Reported-by: [email protected] Signed-off-by: Masami Hiramatsu <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/160697104969.3146288.16329307586428270032.stgit@devnote2
1 parent 4e9a5ae commit 12cb908

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

arch/x86/lib/insn-eval.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,12 @@ static bool is_string_insn(struct insn *insn)
6363
*/
6464
bool insn_has_rep_prefix(struct insn *insn)
6565
{
66+
insn_byte_t p;
6667
int i;
6768

6869
insn_get_prefixes(insn);
6970

70-
for (i = 0; i < insn->prefixes.nbytes; i++) {
71-
insn_byte_t p = insn->prefixes.bytes[i];
72-
71+
for_each_insn_prefix(insn, i, p) {
7372
if (p == 0xf2 || p == 0xf3)
7473
return true;
7574
}
@@ -95,14 +94,15 @@ static int get_seg_reg_override_idx(struct insn *insn)
9594
{
9695
int idx = INAT_SEG_REG_DEFAULT;
9796
int num_overrides = 0, i;
97+
insn_byte_t p;
9898

9999
insn_get_prefixes(insn);
100100

101101
/* Look for any segment override prefixes. */
102-
for (i = 0; i < insn->prefixes.nbytes; i++) {
102+
for_each_insn_prefix(insn, i, p) {
103103
insn_attr_t attr;
104104

105-
attr = inat_get_opcode_attribute(insn->prefixes.bytes[i]);
105+
attr = inat_get_opcode_attribute(p);
106106
switch (attr) {
107107
case INAT_MAKE_PREFIX(INAT_PFX_CS):
108108
idx = INAT_SEG_REG_CS;

0 commit comments

Comments
 (0)