Skip to content

Commit cb06ac2

Browse files
mhiramatgregkh
authored andcommitted
x86/kprobes: Fix to check non boostable prefixes correctly
[ Upstream commit 6dd3b8c ] There are 2 bugs in the can_boost() function because of using x86 insn decoder. Since the insn->opcode never has a prefix byte, it can not find CS override prefix in it. And the insn->attr is the attribute of the opcode, thus inat_is_address_size_prefix( insn->attr) always returns false. Fix those by checking each prefix bytes with for_each_insn_prefix loop and getting the correct attribute for each prefix byte. Also, this removes unlikely, because this is a slow path. Fixes: a8d11cd ("kprobes/x86: Consolidate insn decoder users for copying code") Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/161666691162.1120877.2808435205294352583.stgit@devnote2 Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 5d4d068 commit cb06ac2

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

‎arch/x86/kernel/kprobes/core.c‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ NOKPROBE_SYMBOL(skip_prefixes);
159159
int can_boost(struct insn *insn, void *addr)
160160
{
161161
kprobe_opcode_t opcode;
162+
insn_byte_t prefix;
163+
int i;
162164

163165
if (search_exception_tables((unsigned long)addr))
164166
return 0; /* Page fault may occur on this address. */
@@ -171,9 +173,14 @@ int can_boost(struct insn *insn, void *addr)
171173
if (insn->opcode.nbytes != 1)
172174
return 0;
173175

174-
/* Can't boost Address-size override prefix */
175-
if (unlikely(inat_is_address_size_prefix(insn->attr)))
176-
return 0;
176+
for_each_insn_prefix(insn, i, prefix) {
177+
insn_attr_t attr;
178+
179+
attr = inat_get_opcode_attribute(prefix);
180+
/* Can't boost Address-size override prefix and CS override prefix */
181+
if (prefix == 0x2e || inat_is_address_size_prefix(attr))
182+
return 0;
183+
}
177184

178185
opcode = insn->opcode.bytes[0];
179186

@@ -198,8 +205,8 @@ int can_boost(struct insn *insn, void *addr)
198205
/* clear and set flags are boostable */
199206
return (opcode == 0xf5 || (0xf7 < opcode && opcode < 0xfe));
200207
default:
201-
/* CS override prefix and call are not boostable */
202-
return (opcode != 0x2e && opcode != 0x9a);
208+
/* call is not boostable */
209+
return opcode != 0x9a;
203210
}
204211
}
205212

0 commit comments

Comments
 (0)