uprobes/x86: Refuse to attach uprobe to "word-sized" branch insns
PATCH 1/1 uprobes/x86: Refuse to attach uprobe to "word-sized" branch insns
All branch insns on x86 can be prefixed with the operand-size override prefix, 0x66. It was only ever useful for performing jumps to 32-bit offsets in 16-bit code segments.
In 32-bit code, such instructions are useless since they cause IP truncation to 16 bits, and in case of call insns, they save only 16 bits of return address and misalign the stack pointer as a "bonus".
In 64-bit code, such instructions are treated differently by Intel and AMD CPUs: Intel ignores the prefix altogether,
AMD treats them the same as in 32-bit mode.
Before this patch, the emulation code would execute the instructions as if they have no 0x66 prefix.
With this patch, we refuse to attach uprobes to such insns.
--- arch/x86/kernel/uprobes.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
arch/x86/kernel/uprobes.c +12 -0
@@ -582,6 +582,7 @@ static struct uprobe_xol_ops branch_xol_ops = {/* Returns -ENOSYS if branch_xol_ops doesn't handle this insn */ static int branch_setup_xol_ops (struct arch_uprobe *auprobe,struct insn *insn) { +int i;u8 opc1 =OPCODE1 (insn);/* has the side-effect of processing the entire instruction */
@@ -612,6 +613,17 @@ static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn)return -ENOSYS ; } +/* +* 16-bit overrides such as CALLW (66 e8 nn nn) are not supported. +* Intel and AMD behavior differ in 64-bit mode: Intel ignores 66 prefix. +* No one uses these insns. +* Reject any branch insns with such prefix. +*/ +for (i =0 ; i < insn->prefixes.nbytes; i++) { +if (insn->prefixes.bytes[i] ==0x66 ) +return -ENOTSUPP ; + } + auprobe->branch.opc1 = opc1; auprobe->branch.ilen = insn->length; auprobe->branch.offs = insn->immediate.value;
Signature · 1 line
1.8.1.4
Oleg Nesterov
maintainerThanks!
Masami, Jim, any acks?
Quoted 58 lines · Denys Vlasenko
All branch insns on x86 can be prefixed with the operand-size override prefix,
0x66. It was only ever useful for performing jumps to 32-bit offsets in 16-bit code segments.In 32-bit code, such instructions are useless since they cause IP truncation to 16 bits, and in case of call insns, they save only 16 bits of return address and misalign the stack pointer as a "bonus".
In 64-bit code, such instructions are treated differently by Intel and AMD CPUs: Intel ignores the prefix altogether,
AMD treats them the same as in 32-bit mode.Before this patch, the emulation code would execute the instructions as if they have no
0x66prefix.With this patch, we refuse to attach uprobes to such insns.
Signed-off-by Denys Vlasenko <[email protected]>Cc Oleg Nesterov <[email protected]>--- arch/x86/kernel/uprobes.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)arch/x86/kernel/uprobes.c +12
-1@@ -582,6 +582,7 @@ static struct uprobe_xol_ops branch_xol_ops = {/* Returns -ENOSYS if branch_xol_ops doesn't handle this insn */ static int branch_setup_xol_ops (struct arch_uprobe *auprobe,struct insn *insn) { +int i;u8 opc1 =OPCODE1 (insn);/* has the side-effect of processing the entire instruction */ @@ -612,6 +613,17 @@ static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn)return -ENOSYS ; } +/* +* 16-bit overrides such as CALLW (66 e8 nn nn) are not supported. +* Intel and AMD behavior differ in 64-bit mode: Intel ignores 66 prefix. +* No one uses these insns. +* Reject any branch insns with such prefix. +*/ +for (i =0 ; i < insn->prefixes.nbytes; i++) { +if (insn->prefixes.bytes[i] ==0x66 ) +return -ENOTSUPP ; + } + auprobe->branch.opc1 = opc1; auprobe->branch.ilen = insn->length; auprobe->branch.offs = insn->immediate.value; --1.8.1.4
Jim Keniston
Acked-byQuoted 3 lines · Oleg Nesterov
Thanks!
Masami, Jim, any acks?
Quoted 61 lines · Denys Vlasenko
Quoted 58 lines
All branch insns on x86 can be prefixed with the operand-size override prefix,
0x66. It was only ever useful for performing jumps to 32-bit offsets in 16-bit code segments.In 32-bit code, such instructions are useless since they cause IP truncation to 16 bits, and in case of call insns, they save only 16 bits of return address and misalign the stack pointer as a "bonus".
In 64-bit code, such instructions are treated differently by Intel and AMD CPUs: Intel ignores the prefix altogether,
AMD treats them the same as in 32-bit mode.Before this patch, the emulation code would execute the instructions as if they have no
0x66prefix.With this patch, we refuse to attach uprobes to such insns.
Signed-off-by Denys Vlasenko <[email protected]>Cc Oleg Nesterov <[email protected]>--- arch/x86/kernel/uprobes.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)arch/x86/kernel/uprobes.c +12
-1@@ -582,6 +582,7 @@ static struct uprobe_xol_ops branch_xol_ops = {/* Returns -ENOSYS if branch_xol_ops doesn't handle this insn */ static int branch_setup_xol_ops (struct arch_uprobe *auprobe,struct insn *insn) { +int i;u8 opc1 =OPCODE1 (insn);/* has the side-effect of processing the entire instruction */ @@ -612,6 +613,17 @@ static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn)return -ENOSYS ; } +/* +* 16-bit overrides such as CALLW (66 e8 nn nn) are not supported. +* Intel and AMD behavior differ in 64-bit mode: Intel ignores 66 prefix. +* No one uses these insns. +* Reject any branch insns with such prefix. +*/ +for (i =0 ; i < insn->prefixes.nbytes; i++) { +if (insn->prefixes.bytes[i] ==0x66 ) +return -ENOTSUPP ; + } + auprobe->branch.opc1 = opc1; auprobe->branch.ilen = insn->length; auprobe->branch.offs = insn->immediate.value; --1.8.1.4
Masami Hiramatsu
Acked-byQuoted 26 lines · Oleg Nesterov
Thanks!
Masami, Jim, any acks?
Quoted 21 lines · Denys Vlasenko
All branch insns on x86 can be prefixed with the operand-size override prefix,
0x66. It was only ever useful for performing jumps to 32-bit offsets in 16-bit code segments.In 32-bit code, such instructions are useless since they cause IP truncation to 16 bits, and in case of call insns, they save only 16 bits of return address and misalign the stack pointer as a "bonus".
In 64-bit code, such instructions are treated differently by Intel and AMD CPUs: Intel ignores the prefix altogether,
AMD treats them the same as in 32-bit mode.Before this patch, the emulation code would execute the instructions as if they have no
0x66prefix.With this patch, we refuse to attach uprobes to such insns.
Signed-off-by Denys Vlasenko <[email protected]>Cc Oleg Nesterov <[email protected]>
Thank you :)
Quoted 44 lines
Quoted 35 lines
--- arch/x86/kernel/uprobes.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)arch/x86/kernel/uprobes.c +12
-1@@ -582,6 +582,7 @@ static struct uprobe_xol_ops branch_xol_ops = {/* Returns -ENOSYS if branch_xol_ops doesn't handle this insn */ static int branch_setup_xol_ops (struct arch_uprobe *auprobe,struct insn *insn) { +int i;u8 opc1 =OPCODE1 (insn);/* has the side-effect of processing the entire instruction */ @@ -612,6 +613,17 @@ static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn)return -ENOSYS ; } +/* +* 16-bit overrides such as CALLW (66 e8 nn nn) are not supported. +* Intel and AMD behavior differ in 64-bit mode: Intel ignores 66 prefix. +* No one uses these insns. +* Reject any branch insns with such prefix. +*/ +for (i =0 ; i < insn->prefixes.nbytes; i++) { +if (insn->prefixes.bytes[i] ==0x66 ) +return -ENOTSUPP ; + } + auprobe->branch.opc1 = opc1; auprobe->branch.ilen = insn->length; auprobe->branch.offs = insn->immediate.value; --Quoted 2 lines
1.8.1.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 4 lines
Masami HIRAMATSU Software Platform Research Dept. Linux Technology Research Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]