|
@@ -133,3 +133,134 @@ static inline void __kprobes load_write_pc(long pcv, struct pt_regs *regs)
|
|
|
}
|
|
|
|
|
|
|
|
|
+#if __LINUX_ARM_ARCH__ >= 7
|
|
|
+
|
|
|
+#define alu_write_pc_interworks true
|
|
|
+#define test_alu_write_pc_interworking()
|
|
|
+
|
|
|
+#elif __LINUX_ARM_ARCH__ <= 5
|
|
|
+
|
|
|
+/* Kernels built for <= ARMv5 should never run on >= ARMv6 hardware, so... */
|
|
|
+#define alu_write_pc_interworks false
|
|
|
+#define test_alu_write_pc_interworking()
|
|
|
+
|
|
|
+#else /* __LINUX_ARM_ARCH__ == 6 */
|
|
|
+
|
|
|
+/* We could be an ARMv6 binary on ARMv7 hardware so we need a run-time check. */
|
|
|
+extern bool alu_write_pc_interworks;
|
|
|
+void __init test_alu_write_pc_interworking(void);
|
|
|
+
|
|
|
+#endif /* __LINUX_ARM_ARCH__ == 6 */
|
|
|
+
|
|
|
+static inline void __kprobes alu_write_pc(long pcv, struct pt_regs *regs)
|
|
|
+{
|
|
|
+ if (alu_write_pc_interworks)
|
|
|
+ bx_write_pc(pcv, regs);
|
|
|
+ else
|
|
|
+ regs->ARM_pc = pcv;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void __kprobes kprobe_simulate_nop(struct kprobe *p, struct pt_regs *regs);
|
|
|
+void __kprobes kprobe_emulate_none(struct kprobe *p, struct pt_regs *regs);
|
|
|
+
|
|
|
+enum kprobe_insn __kprobes
|
|
|
+kprobe_decode_ldmstm(kprobe_opcode_t insn, struct arch_specific_insn *asi);
|
|
|
+
|
|
|
+/*
|
|
|
+ * Test if load/store instructions writeback the address register.
|
|
|
+ * if P (bit 24) == 0 or W (bit 21) == 1
|
|
|
+ */
|
|
|
+#define is_writeback(insn) ((insn ^ 0x01000000) & 0x01200000)
|
|
|
+
|
|
|
+/*
|
|
|
+ * The following definitions and macros are used to build instruction
|
|
|
+ * decoding tables for use by kprobe_decode_insn.
|
|
|
+ *
|
|
|
+ * These tables are a concatenation of entries each of which consist of one of
|
|
|
+ * the decode_* structs. All of the fields in every type of decode structure
|
|
|
+ * are of the union type decode_item, therefore the entire decode table can be
|
|
|
+ * viewed as an array of these and declared like:
|
|
|
+ *
|
|
|
+ * static const union decode_item table_name[] = {};
|
|
|
+ *
|
|
|
+ * In order to construct each entry in the table, macros are used to
|
|
|
+ * initialise a number of sequential decode_item values in a layout which
|
|
|
+ * matches the relevant struct. E.g. DECODE_SIMULATE initialise a struct
|
|
|
+ * decode_simulate by initialising four decode_item objects like this...
|
|
|
+ *
|
|
|
+ * {.bits = _type},
|
|
|
+ * {.bits = _mask},
|
|
|
+ * {.bits = _value},
|
|
|
+ * {.handler = _handler},
|
|
|
+ *
|
|
|
+ * Initialising a specified member of the union means that the compiler
|
|
|
+ * will produce a warning if the argument is of an incorrect type.
|
|
|
+ *
|
|
|
+ * Below is a list of each of the macros used to initialise entries and a
|
|
|
+ * description of the action performed when that entry is matched to an
|
|
|
+ * instruction. A match is found when (instruction & mask) == value.
|
|
|
+ *
|
|
|
+ * DECODE_TABLE(mask, value, table)
|
|
|
+ * Instruction decoding jumps to parsing the new sub-table 'table'.
|
|
|
+ *
|
|
|
+ * DECODE_CUSTOM(mask, value, decoder)
|
|
|
+ * The custom function 'decoder' is called to the complete decoding
|
|
|
+ * of an instruction.
|
|
|
+ *
|
|
|
+ * DECODE_SIMULATE(mask, value, handler)
|
|
|
+ * Set the probes instruction handler to 'handler', this will be used
|
|
|
+ * to simulate the instruction when the probe is hit. Decoding returns
|
|
|
+ * with INSN_GOOD_NO_SLOT.
|
|
|
+ *
|
|
|
+ * DECODE_EMULATE(mask, value, handler)
|
|
|
+ * Set the probes instruction handler to 'handler', this will be used
|
|
|
+ * to emulate the instruction when the probe is hit. The modified
|
|
|
+ * instruction (see below) is placed in the probes instruction slot so it
|
|
|
+ * may be called by the emulation code. Decoding returns with INSN_GOOD.
|
|
|
+ *
|
|
|
+ * DECODE_REJECT(mask, value)
|
|
|
+ * Instruction decoding fails with INSN_REJECTED
|
|
|
+ *
|
|
|
+ * DECODE_OR(mask, value)
|
|
|
+ * This allows the mask/value test of multiple table entries to be
|
|
|
+ * logically ORed. Once an 'or' entry is matched the decoding action to
|
|
|
+ * be performed is that of the next entry which isn't an 'or'. E.g.
|
|
|
+ *
|
|
|
+ * DECODE_OR (mask1, value1)
|
|
|
+ * DECODE_OR (mask2, value2)
|
|
|
+ * DECODE_SIMULATE (mask3, value3, simulation_handler)
|
|
|
+ *
|
|
|
+ * This means that if any of the three mask/value pairs match the
|
|
|
+ * instruction being decoded, then 'simulation_handler' will be used
|
|
|
+ * for it.
|
|
|
+ *
|
|
|
+ * Both the SIMULATE and EMULATE macros have a second form which take an
|
|
|
+ * additional 'regs' argument.
|
|
|
+ *
|
|
|
+ * DECODE_SIMULATEX(mask, value, handler, regs)
|
|
|
+ * DECODE_EMULATEX (mask, value, handler, regs)
|
|
|
+ *
|
|
|
+ * These are used to specify what kind of CPU register is encoded in each of the
|
|
|
+ * least significant 5 nibbles of the instruction being decoded. The regs value
|
|
|
+ * is specified using the REGS macro, this takes any of the REG_TYPE_* values
|
|
|
+ * from enum decode_reg_type as arguments; only the '*' part of the name is
|
|
|
+ * given. E.g.
|
|
|
+ *
|
|
|
+ * REGS(0, ANY, NOPC, 0, ANY)
|
|
|
+ *
|
|
|
+ * This indicates an instruction is encoded like:
|
|
|
+ *
|
|
|
+ * bits 19..16 ignore
|
|
|
+ * bits 15..12 any register allowed here
|
|
|
+ * bits 11.. 8 any register except PC allowed here
|
|
|
+ * bits 7.. 4 ignore
|
|
|
+ * bits 3.. 0 any register allowed here
|
|
|
+ *
|
|
|
+ * This register specification is checked after a decode table entry is found to
|
|
|
+ * match an instruction (through the mask/value test). Any invalid register then
|
|
|
+ * found in the instruction will cause decoding to fail with INSN_REJECTED. In
|
|
|
+ * the above example this would happen if bits 11..8 of the instruction were
|
|
|
+ * 1111, indicating R15 or PC.
|
|
|
+ *
|
|
|
+ * As well as checking for legal combinations of registers, this data is also
|