1 // SPDX-License-Identifier: GPL-2.0-only 1 2 /* 3 * arch/arm/probes/kprobes/checkers-arm.c 4 * 5 * Copyright (C) 2014 Huawei Inc. 6 */ 7 8 #include <linux/kernel.h> 9 #include "../decode.h" 10 #include "../decode-arm.h" 11 #include "checkers.h" 12 13 static enum probes_insn __kprobes arm_check_st 14 struct arch_probes_insn *asi, 15 const struct decode_header *h) 16 { 17 /* 18 * PROBES_LDRSTRD, PROBES_LDMSTM, PROB 19 * PROBES_STORE_EXTRA may get here. Si 20 * insns as STACK_USE_NONE. 21 */ 22 static const union decode_item table[] 23 /* 24 * 'STR{,D,B,H}, Rt, [Rn, Rm]' 25 * if Rn or Rm is SP. 26 * 27 * STR (register) cccc 0 28 * STRB (register) cccc 0 29 */ 30 DECODE_OR (0x0e10000f, 0 31 DECODE_OR (0x0e1f0000, 0 32 33 /* 34 * 35 * STRD (register) cccc 0 36 * STRH (register) cccc 0 37 */ 38 DECODE_OR (0x0e5000bf, 0 39 DECODE_CUSTOM (0x0e5f00b0, 0 40 41 /* 42 * For PROBES_LDMSTM, only stm 43 * 44 * Bit B/A (bit 24) encodes ar 45 * before, 0 means after. 46 * Bit I/D (bit 23) encodes ar 47 * increment, 0 means decremen 48 * 49 * So: 50 * 51 * 52 * 53 * STMDX SP, [...] cccc 1 54 */ 55 DECODE_CUSTOM (0x0edf0000, 0 56 57 /* 58 /* STR (immediate) cccc 0 59 /* STRB (immediate) cccc 0 60 /* 61 /* STRD (immediate) cccc 0 62 /* STRH (immediate) cccc 0 63 /* 64 * index = (P == '1'); add = ( 65 * Above insns with: 66 * index == 0 (str{,d,h} rx 67 * add == 1 (str{,d,h} rx, 68 * should be STACK_USE_NONE. 69 * Only str{,b,d,h} rx,[sp,#-n 70 * required to be examined. 71 */ 72 /* STR{,B} Rt,[SP,#-n] cccc 0 73 DECODE_CUSTOM (0x0f9f0000, 0 74 75 /* STR{D,H} Rt,[SP,#-n] cccc 0 76 DECODE_CUSTOM (0x0fdf00b0, 0 77 78 /* fall through */ 79 DECODE_CUSTOM (0, 0, STACK_U 80 DECODE_END 81 }; 82 83 return probes_decode_insn(insn, asi, t 84 } 85 86 const struct decode_checker arm_stack_checker[ 87 [PROBES_LDRSTRD] = {.checker = arm_che 88 [PROBES_STORE_EXTRA] = {.checker = arm 89 [PROBES_STORE] = {.checker = arm_check 90 [PROBES_LDMSTM] = {.checker = arm_chec 91 }; 92 93 static enum probes_insn __kprobes arm_check_re 94 struct arch_probes_insn *asi, 95 const struct decode_header *h) 96 { 97 asi->register_usage_flags = 0; 98 return INSN_GOOD; 99 } 100 101 static enum probes_insn arm_check_regs_normal( 102 struct arch_probes_insn *asi, 103 const struct decode_header *h) 104 { 105 u32 regs = h->type_regs.bits >> DECODE 106 int i; 107 108 asi->register_usage_flags = 0; 109 for (i = 0; i < 5; regs >>= 4, insn >> 110 if (regs & 0xf) 111 asi->register_usage_fl 112 113 return INSN_GOOD; 114 } 115 116 117 static enum probes_insn arm_check_regs_ldmstm( 118 struct arch_probes_insn *asi, 119 const struct decode_header *h) 120 { 121 unsigned int reglist = insn & 0xffff; 122 unsigned int rn = (insn >> 16) & 0xf; 123 asi->register_usage_flags = reglist | 124 return INSN_GOOD; 125 } 126 127 static enum probes_insn arm_check_regs_mov_ip_ 128 struct arch_probes_insn *asi, 129 const struct decode_header *h) 130 { 131 /* Instruction is 'mov ip, sp' i.e. 'm 132 asi->register_usage_flags = (1 << 12) 133 return INSN_GOOD; 134 } 135 136 /* 137 * | Rn |Rt 138 * LDRD (register) cccc 000x x0x0 xxxx xx 139 * STRD (register) cccc 000x x0x0 xxxx xx 140 * | Rn |Rt 141 * LDRD (immediate) cccc 000x x1x0 xxxx xx 142 * STRD (immediate) cccc 000x x1x0 xxxx xx 143 * 144 * Such instructions access Rt/d and its next 145 * from others, a specific checker is required 146 * implicit register usage. 147 */ 148 static enum probes_insn arm_check_regs_ldrdstr 149 struct arch_probes_insn *asi, 150 const struct decode_header *h) 151 { 152 int rdt = (insn >> 12) & 0xf; 153 arm_check_regs_normal(insn, asi, h); 154 asi->register_usage_flags |= 1 << (rdt 155 return INSN_GOOD; 156 } 157 158 159 const struct decode_checker arm_regs_checker[N 160 [PROBES_MRS] = {.checker = arm_check_r 161 [PROBES_SATURATING_ARITHMETIC] = {.che 162 [PROBES_MUL1] = {.checker = arm_check_ 163 [PROBES_MUL2] = {.checker = arm_check_ 164 [PROBES_MUL_ADD_LONG] = {.checker = ar 165 [PROBES_MUL_ADD] = {.checker = arm_che 166 [PROBES_LOAD] = {.checker = arm_check_ 167 [PROBES_LOAD_EXTRA] = {.checker = arm_ 168 [PROBES_STORE] = {.checker = arm_check 169 [PROBES_STORE_EXTRA] = {.checker = arm 170 [PROBES_DATA_PROCESSING_REG] = {.check 171 [PROBES_DATA_PROCESSING_IMM] = {.check 172 [PROBES_SEV] = {.checker = arm_check_r 173 [PROBES_WFE] = {.checker = arm_check_r 174 [PROBES_SATURATE] = {.checker = arm_ch 175 [PROBES_REV] = {.checker = arm_check_r 176 [PROBES_MMI] = {.checker = arm_check_r 177 [PROBES_PACK] = {.checker = arm_check_ 178 [PROBES_EXTEND] = {.checker = arm_chec 179 [PROBES_EXTEND_ADD] = {.checker = arm_ 180 [PROBES_BITFIELD] = {.checker = arm_ch 181 [PROBES_LDMSTM] = {.checker = arm_chec 182 [PROBES_MOV_IP_SP] = {.checker = arm_c 183 [PROBES_LDRSTRD] = {.checker = arm_che 184 }; 185
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.