提交 3a488a41 编写于 作者: M Masami Hiramatsu 提交者: Yang Yingliang

x86/kprobes: Fix to check non boostable prefixes correctly

stable inclusion
from linux-4.19.191
commit 609a2d6557e8a6d5dbb6bfcfc5b42185526a0c0b

--------------------------------

[ Upstream commit 6dd3b8c9 ]

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: a8d11cd0 ("kprobes/x86: Consolidate insn decoder users for copying code")
Signed-off-by: NMasami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: NIngo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/161666691162.1120877.2808435205294352583.stgit@devnote2Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 901ee46b
...@@ -170,6 +170,8 @@ NOKPROBE_SYMBOL(skip_prefixes); ...@@ -170,6 +170,8 @@ NOKPROBE_SYMBOL(skip_prefixes);
int can_boost(struct insn *insn, void *addr) int can_boost(struct insn *insn, void *addr)
{ {
kprobe_opcode_t opcode; kprobe_opcode_t opcode;
insn_byte_t prefix;
int i;
if (search_exception_tables((unsigned long)addr)) if (search_exception_tables((unsigned long)addr))
return 0; /* Page fault may occur on this address. */ return 0; /* Page fault may occur on this address. */
...@@ -182,9 +184,14 @@ int can_boost(struct insn *insn, void *addr) ...@@ -182,9 +184,14 @@ int can_boost(struct insn *insn, void *addr)
if (insn->opcode.nbytes != 1) if (insn->opcode.nbytes != 1)
return 0; return 0;
/* Can't boost Address-size override prefix */ for_each_insn_prefix(insn, i, prefix) {
if (unlikely(inat_is_address_size_prefix(insn->attr))) insn_attr_t attr;
return 0;
attr = inat_get_opcode_attribute(prefix);
/* Can't boost Address-size override prefix and CS override prefix */
if (prefix == 0x2e || inat_is_address_size_prefix(attr))
return 0;
}
opcode = insn->opcode.bytes[0]; opcode = insn->opcode.bytes[0];
...@@ -209,8 +216,8 @@ int can_boost(struct insn *insn, void *addr) ...@@ -209,8 +216,8 @@ int can_boost(struct insn *insn, void *addr)
/* clear and set flags are boostable */ /* clear and set flags are boostable */
return (opcode == 0xf5 || (0xf7 < opcode && opcode < 0xfe)); return (opcode == 0xf5 || (0xf7 < opcode && opcode < 0xfe));
default: default:
/* CS override prefix and call are not boostable */ /* call is not boostable */
return (opcode != 0x2e && opcode != 0x9a); return opcode != 0x9a;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册