core.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  1. /*
  2. * Kernel Probes (KProbes)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. *
  18. * Copyright (C) IBM Corporation, 2002, 2004
  19. *
  20. * 2002-Oct Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel
  21. * Probes initial implementation ( includes contributions from
  22. * Rusty Russell).
  23. * 2004-July Suparna Bhattacharya <suparna@in.ibm.com> added jumper probes
  24. * interface to access function arguments.
  25. * 2004-Oct Jim Keniston <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
  26. * <prasanna@in.ibm.com> adapted for x86_64 from i386.
  27. * 2005-Mar Roland McGrath <roland@redhat.com>
  28. * Fixed to handle %rip-relative addressing mode correctly.
  29. * 2005-May Hien Nguyen <hien@us.ibm.com>, Jim Keniston
  30. * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
  31. * <prasanna@in.ibm.com> added function-return probes.
  32. * 2005-May Rusty Lynch <rusty.lynch@intel.com>
  33. * Added function return probes functionality
  34. * 2006-Feb Masami Hiramatsu <hiramatu@sdl.hitachi.co.jp> added
  35. * kprobe-booster and kretprobe-booster for i386.
  36. * 2007-Dec Masami Hiramatsu <mhiramat@redhat.com> added kprobe-booster
  37. * and kretprobe-booster for x86-64
  38. * 2007-Dec Masami Hiramatsu <mhiramat@redhat.com>, Arjan van de Ven
  39. * <arjan@infradead.org> and Jim Keniston <jkenisto@us.ibm.com>
  40. * unified x86 kprobes code.
  41. */
  42. #include <linux/kprobes.h>
  43. #include <linux/ptrace.h>
  44. #include <linux/string.h>
  45. #include <linux/slab.h>
  46. #include <linux/hardirq.h>
  47. #include <linux/preempt.h>
  48. #include <linux/extable.h>
  49. #include <linux/kdebug.h>
  50. #include <linux/kallsyms.h>
  51. #include <linux/ftrace.h>
  52. #include <linux/frame.h>
  53. #include <linux/kasan.h>
  54. #include <linux/moduleloader.h>
  55. #include <asm/text-patching.h>
  56. #include <asm/cacheflush.h>
  57. #include <asm/desc.h>
  58. #include <asm/pgtable.h>
  59. #include <asm/uaccess.h>
  60. #include <asm/alternative.h>
  61. #include <asm/insn.h>
  62. #include <asm/debugreg.h>
  63. #include "common.h"
  64. void jprobe_return_end(void);
  65. DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
  66. DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
  67. #define stack_addr(regs) ((unsigned long *)kernel_stack_pointer(regs))
  68. #define W(row, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, ba, bb, bc, bd, be, bf)\
  69. (((b0##UL << 0x0)|(b1##UL << 0x1)|(b2##UL << 0x2)|(b3##UL << 0x3) | \
  70. (b4##UL << 0x4)|(b5##UL << 0x5)|(b6##UL << 0x6)|(b7##UL << 0x7) | \
  71. (b8##UL << 0x8)|(b9##UL << 0x9)|(ba##UL << 0xa)|(bb##UL << 0xb) | \
  72. (bc##UL << 0xc)|(bd##UL << 0xd)|(be##UL << 0xe)|(bf##UL << 0xf)) \
  73. << (row % 32))
  74. /*
  75. * Undefined/reserved opcodes, conditional jump, Opcode Extension
  76. * Groups, and some special opcodes can not boost.
  77. * This is non-const and volatile to keep gcc from statically
  78. * optimizing it out, as variable_test_bit makes gcc think only
  79. * *(unsigned long*) is used.
  80. */
  81. static volatile u32 twobyte_is_boostable[256 / 32] = {
  82. /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
  83. /* ---------------------------------------------- */
  84. W(0x00, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0) | /* 00 */
  85. W(0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1) , /* 10 */
  86. W(0x20, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) | /* 20 */
  87. W(0x30, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) , /* 30 */
  88. W(0x40, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) | /* 40 */
  89. W(0x50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) , /* 50 */
  90. W(0x60, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1) | /* 60 */
  91. W(0x70, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1) , /* 70 */
  92. W(0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) | /* 80 */
  93. W(0x90, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) , /* 90 */
  94. W(0xa0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1) | /* a0 */
  95. W(0xb0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1) , /* b0 */
  96. W(0xc0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1) | /* c0 */
  97. W(0xd0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1) , /* d0 */
  98. W(0xe0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1) | /* e0 */
  99. W(0xf0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0) /* f0 */
  100. /* ----------------------------------------------- */
  101. /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
  102. };
  103. #undef W
  104. struct kretprobe_blackpoint kretprobe_blacklist[] = {
  105. {"__switch_to", }, /* This function switches only current task, but
  106. doesn't switch kernel stack.*/
  107. {NULL, NULL} /* Terminator */
  108. };
  109. const int kretprobe_blacklist_size = ARRAY_SIZE(kretprobe_blacklist);
  110. static nokprobe_inline void
  111. __synthesize_relative_insn(void *from, void *to, u8 op)
  112. {
  113. struct __arch_relative_insn {
  114. u8 op;
  115. s32 raddr;
  116. } __packed *insn;
  117. insn = (struct __arch_relative_insn *)from;
  118. insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
  119. insn->op = op;
  120. }
  121. /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
  122. void synthesize_reljump(void *from, void *to)
  123. {
  124. __synthesize_relative_insn(from, to, RELATIVEJUMP_OPCODE);
  125. }
  126. NOKPROBE_SYMBOL(synthesize_reljump);
  127. /* Insert a call instruction at address 'from', which calls address 'to'.*/
  128. void synthesize_relcall(void *from, void *to)
  129. {
  130. __synthesize_relative_insn(from, to, RELATIVECALL_OPCODE);
  131. }
  132. NOKPROBE_SYMBOL(synthesize_relcall);
  133. /*
  134. * Skip the prefixes of the instruction.
  135. */
  136. static kprobe_opcode_t *skip_prefixes(kprobe_opcode_t *insn)
  137. {
  138. insn_attr_t attr;
  139. attr = inat_get_opcode_attribute((insn_byte_t)*insn);
  140. while (inat_is_legacy_prefix(attr)) {
  141. insn++;
  142. attr = inat_get_opcode_attribute((insn_byte_t)*insn);
  143. }
  144. #ifdef CONFIG_X86_64
  145. if (inat_is_rex_prefix(attr))
  146. insn++;
  147. #endif
  148. return insn;
  149. }
  150. NOKPROBE_SYMBOL(skip_prefixes);
  151. /*
  152. * Returns non-zero if opcode is boostable.
  153. * RIP relative instructions are adjusted at copying time in 64 bits mode
  154. */
  155. int can_boost(kprobe_opcode_t *opcodes, void *addr)
  156. {
  157. kprobe_opcode_t opcode;
  158. kprobe_opcode_t *orig_opcodes = opcodes;
  159. if (search_exception_tables((unsigned long)addr))
  160. return 0; /* Page fault may occur on this address. */
  161. retry:
  162. if (opcodes - orig_opcodes > MAX_INSN_SIZE - 1)
  163. return 0;
  164. opcode = *(opcodes++);
  165. /* 2nd-byte opcode */
  166. if (opcode == 0x0f) {
  167. if (opcodes - orig_opcodes > MAX_INSN_SIZE - 1)
  168. return 0;
  169. return test_bit(*opcodes,
  170. (unsigned long *)twobyte_is_boostable);
  171. }
  172. switch (opcode & 0xf0) {
  173. #ifdef CONFIG_X86_64
  174. case 0x40:
  175. goto retry; /* REX prefix is boostable */
  176. #endif
  177. case 0x60:
  178. if (0x63 < opcode && opcode < 0x67)
  179. goto retry; /* prefixes */
  180. /* can't boost Address-size override and bound */
  181. return (opcode != 0x62 && opcode != 0x67);
  182. case 0x70:
  183. return 0; /* can't boost conditional jump */
  184. case 0x90:
  185. return opcode != 0x9a; /* can't boost call far */
  186. case 0xc0:
  187. /* can't boost software-interruptions */
  188. return (0xc1 < opcode && opcode < 0xcc) || opcode == 0xcf;
  189. case 0xd0:
  190. /* can boost AA* and XLAT */
  191. return (opcode == 0xd4 || opcode == 0xd5 || opcode == 0xd7);
  192. case 0xe0:
  193. /* can boost in/out and absolute jmps */
  194. return ((opcode & 0x04) || opcode == 0xea);
  195. case 0xf0:
  196. if ((opcode & 0x0c) == 0 && opcode != 0xf1)
  197. goto retry; /* lock/rep(ne) prefix */
  198. /* clear and set flags are boostable */
  199. return (opcode == 0xf5 || (0xf7 < opcode && opcode < 0xfe));
  200. default:
  201. /* segment override prefixes are boostable */
  202. if (opcode == 0x26 || opcode == 0x36 || opcode == 0x3e)
  203. goto retry; /* prefixes */
  204. /* CS override prefix and call are not boostable */
  205. return (opcode != 0x2e && opcode != 0x9a);
  206. }
  207. }
  208. static unsigned long
  209. __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
  210. {
  211. struct kprobe *kp;
  212. unsigned long faddr;
  213. kp = get_kprobe((void *)addr);
  214. faddr = ftrace_location(addr);
  215. /*
  216. * Addresses inside the ftrace location are refused by
  217. * arch_check_ftrace_location(). Something went terribly wrong
  218. * if such an address is checked here.
  219. */
  220. if (WARN_ON(faddr && faddr != addr))
  221. return 0UL;
  222. /*
  223. * Use the current code if it is not modified by Kprobe
  224. * and it cannot be modified by ftrace.
  225. */
  226. if (!kp && !faddr)
  227. return addr;
  228. /*
  229. * Basically, kp->ainsn.insn has an original instruction.
  230. * However, RIP-relative instruction can not do single-stepping
  231. * at different place, __copy_instruction() tweaks the displacement of
  232. * that instruction. In that case, we can't recover the instruction
  233. * from the kp->ainsn.insn.
  234. *
  235. * On the other hand, in case on normal Kprobe, kp->opcode has a copy
  236. * of the first byte of the probed instruction, which is overwritten
  237. * by int3. And the instruction at kp->addr is not modified by kprobes
  238. * except for the first byte, we can recover the original instruction
  239. * from it and kp->opcode.
  240. *
  241. * In case of Kprobes using ftrace, we do not have a copy of
  242. * the original instruction. In fact, the ftrace location might
  243. * be modified at anytime and even could be in an inconsistent state.
  244. * Fortunately, we know that the original code is the ideal 5-byte
  245. * long NOP.
  246. */
  247. memcpy(buf, (void *)addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
  248. if (faddr)
  249. memcpy(buf, ideal_nops[NOP_ATOMIC5], 5);
  250. else
  251. buf[0] = kp->opcode;
  252. return (unsigned long)buf;
  253. }
  254. /*
  255. * Recover the probed instruction at addr for further analysis.
  256. * Caller must lock kprobes by kprobe_mutex, or disable preemption
  257. * for preventing to release referencing kprobes.
  258. * Returns zero if the instruction can not get recovered.
  259. */
  260. unsigned long recover_probed_instruction(kprobe_opcode_t *buf, unsigned long addr)
  261. {
  262. unsigned long __addr;
  263. __addr = __recover_optprobed_insn(buf, addr);
  264. if (__addr != addr)
  265. return __addr;
  266. return __recover_probed_insn(buf, addr);
  267. }
  268. /* Check if paddr is at an instruction boundary */
  269. static int can_probe(unsigned long paddr)
  270. {
  271. unsigned long addr, __addr, offset = 0;
  272. struct insn insn;
  273. kprobe_opcode_t buf[MAX_INSN_SIZE];
  274. if (!kallsyms_lookup_size_offset(paddr, NULL, &offset))
  275. return 0;
  276. /* Decode instructions */
  277. addr = paddr - offset;
  278. while (addr < paddr) {
  279. /*
  280. * Check if the instruction has been modified by another
  281. * kprobe, in which case we replace the breakpoint by the
  282. * original instruction in our buffer.
  283. * Also, jump optimization will change the breakpoint to
  284. * relative-jump. Since the relative-jump itself is
  285. * normally used, we just go through if there is no kprobe.
  286. */
  287. __addr = recover_probed_instruction(buf, addr);
  288. if (!__addr)
  289. return 0;
  290. kernel_insn_init(&insn, (void *)__addr, MAX_INSN_SIZE);
  291. insn_get_length(&insn);
  292. /*
  293. * Another debugging subsystem might insert this breakpoint.
  294. * In that case, we can't recover it.
  295. */
  296. if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
  297. return 0;
  298. addr += insn.length;
  299. }
  300. return (addr == paddr);
  301. }
  302. /*
  303. * Returns non-zero if opcode modifies the interrupt flag.
  304. */
  305. static int is_IF_modifier(kprobe_opcode_t *insn)
  306. {
  307. /* Skip prefixes */
  308. insn = skip_prefixes(insn);
  309. switch (*insn) {
  310. case 0xfa: /* cli */
  311. case 0xfb: /* sti */
  312. case 0xcf: /* iret/iretd */
  313. case 0x9d: /* popf/popfd */
  314. return 1;
  315. }
  316. return 0;
  317. }
  318. /*
  319. * Copy an instruction and adjust the displacement if the instruction
  320. * uses the %rip-relative addressing mode.
  321. * If it does, Return the address of the 32-bit displacement word.
  322. * If not, return null.
  323. * Only applicable to 64-bit x86.
  324. */
  325. int __copy_instruction(u8 *dest, u8 *src)
  326. {
  327. struct insn insn;
  328. kprobe_opcode_t buf[MAX_INSN_SIZE];
  329. int length;
  330. unsigned long recovered_insn =
  331. recover_probed_instruction(buf, (unsigned long)src);
  332. if (!recovered_insn)
  333. return 0;
  334. kernel_insn_init(&insn, (void *)recovered_insn, MAX_INSN_SIZE);
  335. insn_get_length(&insn);
  336. length = insn.length;
  337. /* Another subsystem puts a breakpoint, failed to recover */
  338. if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
  339. return 0;
  340. memcpy(dest, insn.kaddr, length);
  341. #ifdef CONFIG_X86_64
  342. if (insn_rip_relative(&insn)) {
  343. s64 newdisp;
  344. u8 *disp;
  345. kernel_insn_init(&insn, dest, length);
  346. insn_get_displacement(&insn);
  347. /*
  348. * The copied instruction uses the %rip-relative addressing
  349. * mode. Adjust the displacement for the difference between
  350. * the original location of this instruction and the location
  351. * of the copy that will actually be run. The tricky bit here
  352. * is making sure that the sign extension happens correctly in
  353. * this calculation, since we need a signed 32-bit result to
  354. * be sign-extended to 64 bits when it's added to the %rip
  355. * value and yield the same 64-bit result that the sign-
  356. * extension of the original signed 32-bit displacement would
  357. * have given.
  358. */
  359. newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
  360. if ((s64) (s32) newdisp != newdisp) {
  361. pr_err("Kprobes error: new displacement does not fit into s32 (%llx)\n", newdisp);
  362. pr_err("\tSrc: %p, Dest: %p, old disp: %x\n", src, dest, insn.displacement.value);
  363. return 0;
  364. }
  365. disp = (u8 *) dest + insn_offset_displacement(&insn);
  366. *(s32 *) disp = (s32) newdisp;
  367. }
  368. #endif
  369. return length;
  370. }
  371. /* Recover page to RW mode before releasing it */
  372. void free_insn_page(void *page)
  373. {
  374. set_memory_nx((unsigned long)page & PAGE_MASK, 1);
  375. set_memory_rw((unsigned long)page & PAGE_MASK, 1);
  376. module_memfree(page);
  377. }
  378. /* Prepare reljump right after instruction to boost */
  379. static void prepare_boost(struct kprobe *p, int length)
  380. {
  381. if (can_boost(p->ainsn.insn, p->addr) &&
  382. MAX_INSN_SIZE - length >= RELATIVEJUMP_SIZE) {
  383. /*
  384. * These instructions can be executed directly if it
  385. * jumps back to correct address.
  386. */
  387. synthesize_reljump(p->ainsn.insn + length, p->addr + length);
  388. p->ainsn.boostable = 1;
  389. } else {
  390. p->ainsn.boostable = -1;
  391. }
  392. }
  393. static int arch_copy_kprobe(struct kprobe *p)
  394. {
  395. int len;
  396. set_memory_rw((unsigned long)p->ainsn.insn & PAGE_MASK, 1);
  397. /* Copy an instruction with recovering if other optprobe modifies it.*/
  398. len = __copy_instruction(p->ainsn.insn, p->addr);
  399. if (!len)
  400. return -EINVAL;
  401. /*
  402. * __copy_instruction can modify the displacement of the instruction,
  403. * but it doesn't affect boostable check.
  404. */
  405. prepare_boost(p, len);
  406. set_memory_ro((unsigned long)p->ainsn.insn & PAGE_MASK, 1);
  407. /* Check whether the instruction modifies Interrupt Flag or not */
  408. p->ainsn.if_modifier = is_IF_modifier(p->ainsn.insn);
  409. /* Also, displacement change doesn't affect the first byte */
  410. p->opcode = p->ainsn.insn[0];
  411. return 0;
  412. }
  413. int arch_prepare_kprobe(struct kprobe *p)
  414. {
  415. if (alternatives_text_reserved(p->addr, p->addr))
  416. return -EINVAL;
  417. if (!can_probe((unsigned long)p->addr))
  418. return -EILSEQ;
  419. /* insn: must be on special executable page on x86. */
  420. p->ainsn.insn = get_insn_slot();
  421. if (!p->ainsn.insn)
  422. return -ENOMEM;
  423. return arch_copy_kprobe(p);
  424. }
  425. void arch_arm_kprobe(struct kprobe *p)
  426. {
  427. text_poke(p->addr, ((unsigned char []){BREAKPOINT_INSTRUCTION}), 1);
  428. }
  429. void arch_disarm_kprobe(struct kprobe *p)
  430. {
  431. text_poke(p->addr, &p->opcode, 1);
  432. }
  433. void arch_remove_kprobe(struct kprobe *p)
  434. {
  435. if (p->ainsn.insn) {
  436. free_insn_slot(p->ainsn.insn, (p->ainsn.boostable == 1));
  437. p->ainsn.insn = NULL;
  438. }
  439. }
  440. static nokprobe_inline void
  441. save_previous_kprobe(struct kprobe_ctlblk *kcb)
  442. {
  443. kcb->prev_kprobe.kp = kprobe_running();
  444. kcb->prev_kprobe.status = kcb->kprobe_status;
  445. kcb->prev_kprobe.old_flags = kcb->kprobe_old_flags;
  446. kcb->prev_kprobe.saved_flags = kcb->kprobe_saved_flags;
  447. }
  448. static nokprobe_inline void
  449. restore_previous_kprobe(struct kprobe_ctlblk *kcb)
  450. {
  451. __this_cpu_write(current_kprobe, kcb->prev_kprobe.kp);
  452. kcb->kprobe_status = kcb->prev_kprobe.status;
  453. kcb->kprobe_old_flags = kcb->prev_kprobe.old_flags;
  454. kcb->kprobe_saved_flags = kcb->prev_kprobe.saved_flags;
  455. }
  456. static nokprobe_inline void
  457. set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
  458. struct kprobe_ctlblk *kcb)
  459. {
  460. __this_cpu_write(current_kprobe, p);
  461. kcb->kprobe_saved_flags = kcb->kprobe_old_flags
  462. = (regs->flags & (X86_EFLAGS_TF | X86_EFLAGS_IF));
  463. if (p->ainsn.if_modifier)
  464. kcb->kprobe_saved_flags &= ~X86_EFLAGS_IF;
  465. }
  466. static nokprobe_inline void clear_btf(void)
  467. {
  468. if (test_thread_flag(TIF_BLOCKSTEP)) {
  469. unsigned long debugctl = get_debugctlmsr();
  470. debugctl &= ~DEBUGCTLMSR_BTF;
  471. update_debugctlmsr(debugctl);
  472. }
  473. }
  474. static nokprobe_inline void restore_btf(void)
  475. {
  476. if (test_thread_flag(TIF_BLOCKSTEP)) {
  477. unsigned long debugctl = get_debugctlmsr();
  478. debugctl |= DEBUGCTLMSR_BTF;
  479. update_debugctlmsr(debugctl);
  480. }
  481. }
  482. void arch_prepare_kretprobe(struct kretprobe_instance *ri, struct pt_regs *regs)
  483. {
  484. unsigned long *sara = stack_addr(regs);
  485. ri->ret_addr = (kprobe_opcode_t *) *sara;
  486. /* Replace the return addr with trampoline addr */
  487. *sara = (unsigned long) &kretprobe_trampoline;
  488. }
  489. NOKPROBE_SYMBOL(arch_prepare_kretprobe);
  490. static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
  491. struct kprobe_ctlblk *kcb, int reenter)
  492. {
  493. if (setup_detour_execution(p, regs, reenter))
  494. return;
  495. #if !defined(CONFIG_PREEMPT)
  496. if (p->ainsn.boostable == 1 && !p->post_handler) {
  497. /* Boost up -- we can execute copied instructions directly */
  498. if (!reenter)
  499. reset_current_kprobe();
  500. /*
  501. * Reentering boosted probe doesn't reset current_kprobe,
  502. * nor set current_kprobe, because it doesn't use single
  503. * stepping.
  504. */
  505. regs->ip = (unsigned long)p->ainsn.insn;
  506. preempt_enable_no_resched();
  507. return;
  508. }
  509. #endif
  510. if (reenter) {
  511. save_previous_kprobe(kcb);
  512. set_current_kprobe(p, regs, kcb);
  513. kcb->kprobe_status = KPROBE_REENTER;
  514. } else
  515. kcb->kprobe_status = KPROBE_HIT_SS;
  516. /* Prepare real single stepping */
  517. clear_btf();
  518. regs->flags |= X86_EFLAGS_TF;
  519. regs->flags &= ~X86_EFLAGS_IF;
  520. /* single step inline if the instruction is an int3 */
  521. if (p->opcode == BREAKPOINT_INSTRUCTION)
  522. regs->ip = (unsigned long)p->addr;
  523. else
  524. regs->ip = (unsigned long)p->ainsn.insn;
  525. }
  526. NOKPROBE_SYMBOL(setup_singlestep);
  527. /*
  528. * We have reentered the kprobe_handler(), since another probe was hit while
  529. * within the handler. We save the original kprobes variables and just single
  530. * step on the instruction of the new probe without calling any user handlers.
  531. */
  532. static int reenter_kprobe(struct kprobe *p, struct pt_regs *regs,
  533. struct kprobe_ctlblk *kcb)
  534. {
  535. switch (kcb->kprobe_status) {
  536. case KPROBE_HIT_SSDONE:
  537. case KPROBE_HIT_ACTIVE:
  538. case KPROBE_HIT_SS:
  539. kprobes_inc_nmissed_count(p);
  540. setup_singlestep(p, regs, kcb, 1);
  541. break;
  542. case KPROBE_REENTER:
  543. /* A probe has been hit in the codepath leading up to, or just
  544. * after, single-stepping of a probed instruction. This entire
  545. * codepath should strictly reside in .kprobes.text section.
  546. * Raise a BUG or we'll continue in an endless reentering loop
  547. * and eventually a stack overflow.
  548. */
  549. printk(KERN_WARNING "Unrecoverable kprobe detected at %p.\n",
  550. p->addr);
  551. dump_kprobe(p);
  552. BUG();
  553. default:
  554. /* impossible cases */
  555. WARN_ON(1);
  556. return 0;
  557. }
  558. return 1;
  559. }
  560. NOKPROBE_SYMBOL(reenter_kprobe);
  561. /*
  562. * Interrupts are disabled on entry as trap3 is an interrupt gate and they
  563. * remain disabled throughout this function.
  564. */
  565. int kprobe_int3_handler(struct pt_regs *regs)
  566. {
  567. kprobe_opcode_t *addr;
  568. struct kprobe *p;
  569. struct kprobe_ctlblk *kcb;
  570. if (user_mode(regs))
  571. return 0;
  572. addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
  573. /*
  574. * We don't want to be preempted for the entire
  575. * duration of kprobe processing. We conditionally
  576. * re-enable preemption at the end of this function,
  577. * and also in reenter_kprobe() and setup_singlestep().
  578. */
  579. preempt_disable();
  580. kcb = get_kprobe_ctlblk();
  581. p = get_kprobe(addr);
  582. if (p) {
  583. if (kprobe_running()) {
  584. if (reenter_kprobe(p, regs, kcb))
  585. return 1;
  586. } else {
  587. set_current_kprobe(p, regs, kcb);
  588. kcb->kprobe_status = KPROBE_HIT_ACTIVE;
  589. /*
  590. * If we have no pre-handler or it returned 0, we
  591. * continue with normal processing. If we have a
  592. * pre-handler and it returned non-zero, it prepped
  593. * for calling the break_handler below on re-entry
  594. * for jprobe processing, so get out doing nothing
  595. * more here.
  596. */
  597. if (!p->pre_handler || !p->pre_handler(p, regs))
  598. setup_singlestep(p, regs, kcb, 0);
  599. return 1;
  600. }
  601. } else if (*addr != BREAKPOINT_INSTRUCTION) {
  602. /*
  603. * The breakpoint instruction was removed right
  604. * after we hit it. Another cpu has removed
  605. * either a probepoint or a debugger breakpoint
  606. * at this address. In either case, no further
  607. * handling of this interrupt is appropriate.
  608. * Back up over the (now missing) int3 and run
  609. * the original instruction.
  610. */
  611. regs->ip = (unsigned long)addr;
  612. preempt_enable_no_resched();
  613. return 1;
  614. } else if (kprobe_running()) {
  615. p = __this_cpu_read(current_kprobe);
  616. if (p->break_handler && p->break_handler(p, regs)) {
  617. if (!skip_singlestep(p, regs, kcb))
  618. setup_singlestep(p, regs, kcb, 0);
  619. return 1;
  620. }
  621. } /* else: not a kprobe fault; let the kernel handle it */
  622. preempt_enable_no_resched();
  623. return 0;
  624. }
  625. NOKPROBE_SYMBOL(kprobe_int3_handler);
  626. /*
  627. * When a retprobed function returns, this code saves registers and
  628. * calls trampoline_handler() runs, which calls the kretprobe's handler.
  629. */
  630. asm(
  631. ".global kretprobe_trampoline\n"
  632. ".type kretprobe_trampoline, @function\n"
  633. "kretprobe_trampoline:\n"
  634. #ifdef CONFIG_X86_64
  635. /* We don't bother saving the ss register */
  636. " pushq %rsp\n"
  637. " pushfq\n"
  638. SAVE_REGS_STRING
  639. " movq %rsp, %rdi\n"
  640. " call trampoline_handler\n"
  641. /* Replace saved sp with true return address. */
  642. " movq %rax, 152(%rsp)\n"
  643. RESTORE_REGS_STRING
  644. " popfq\n"
  645. #else
  646. " pushf\n"
  647. SAVE_REGS_STRING
  648. " movl %esp, %eax\n"
  649. " call trampoline_handler\n"
  650. /* Move flags to cs */
  651. " movl 56(%esp), %edx\n"
  652. " movl %edx, 52(%esp)\n"
  653. /* Replace saved flags with true return address. */
  654. " movl %eax, 56(%esp)\n"
  655. RESTORE_REGS_STRING
  656. " popf\n"
  657. #endif
  658. " ret\n"
  659. ".size kretprobe_trampoline, .-kretprobe_trampoline\n"
  660. );
  661. NOKPROBE_SYMBOL(kretprobe_trampoline);
  662. STACK_FRAME_NON_STANDARD(kretprobe_trampoline);
  663. /*
  664. * Called from kretprobe_trampoline
  665. */
  666. __visible __used void *trampoline_handler(struct pt_regs *regs)
  667. {
  668. struct kretprobe_instance *ri = NULL;
  669. struct hlist_head *head, empty_rp;
  670. struct hlist_node *tmp;
  671. unsigned long flags, orig_ret_address = 0;
  672. unsigned long trampoline_address = (unsigned long)&kretprobe_trampoline;
  673. kprobe_opcode_t *correct_ret_addr = NULL;
  674. INIT_HLIST_HEAD(&empty_rp);
  675. kretprobe_hash_lock(current, &head, &flags);
  676. /* fixup registers */
  677. #ifdef CONFIG_X86_64
  678. regs->cs = __KERNEL_CS;
  679. #else
  680. regs->cs = __KERNEL_CS | get_kernel_rpl();
  681. regs->gs = 0;
  682. #endif
  683. regs->ip = trampoline_address;
  684. regs->orig_ax = ~0UL;
  685. /*
  686. * It is possible to have multiple instances associated with a given
  687. * task either because multiple functions in the call path have
  688. * return probes installed on them, and/or more than one
  689. * return probe was registered for a target function.
  690. *
  691. * We can handle this because:
  692. * - instances are always pushed into the head of the list
  693. * - when multiple return probes are registered for the same
  694. * function, the (chronologically) first instance's ret_addr
  695. * will be the real return address, and all the rest will
  696. * point to kretprobe_trampoline.
  697. */
  698. hlist_for_each_entry_safe(ri, tmp, head, hlist) {
  699. if (ri->task != current)
  700. /* another task is sharing our hash bucket */
  701. continue;
  702. orig_ret_address = (unsigned long)ri->ret_addr;
  703. if (orig_ret_address != trampoline_address)
  704. /*
  705. * This is the real return address. Any other
  706. * instances associated with this task are for
  707. * other calls deeper on the call stack
  708. */
  709. break;
  710. }
  711. kretprobe_assert(ri, orig_ret_address, trampoline_address);
  712. correct_ret_addr = ri->ret_addr;
  713. hlist_for_each_entry_safe(ri, tmp, head, hlist) {
  714. if (ri->task != current)
  715. /* another task is sharing our hash bucket */
  716. continue;
  717. orig_ret_address = (unsigned long)ri->ret_addr;
  718. if (ri->rp && ri->rp->handler) {
  719. __this_cpu_write(current_kprobe, &ri->rp->kp);
  720. get_kprobe_ctlblk()->kprobe_status = KPROBE_HIT_ACTIVE;
  721. ri->ret_addr = correct_ret_addr;
  722. ri->rp->handler(ri, regs);
  723. __this_cpu_write(current_kprobe, NULL);
  724. }
  725. recycle_rp_inst(ri, &empty_rp);
  726. if (orig_ret_address != trampoline_address)
  727. /*
  728. * This is the real return address. Any other
  729. * instances associated with this task are for
  730. * other calls deeper on the call stack
  731. */
  732. break;
  733. }
  734. kretprobe_hash_unlock(current, &flags);
  735. hlist_for_each_entry_safe(ri, tmp, &empty_rp, hlist) {
  736. hlist_del(&ri->hlist);
  737. kfree(ri);
  738. }
  739. return (void *)orig_ret_address;
  740. }
  741. NOKPROBE_SYMBOL(trampoline_handler);
  742. /*
  743. * Called after single-stepping. p->addr is the address of the
  744. * instruction whose first byte has been replaced by the "int 3"
  745. * instruction. To avoid the SMP problems that can occur when we
  746. * temporarily put back the original opcode to single-step, we
  747. * single-stepped a copy of the instruction. The address of this
  748. * copy is p->ainsn.insn.
  749. *
  750. * This function prepares to return from the post-single-step
  751. * interrupt. We have to fix up the stack as follows:
  752. *
  753. * 0) Except in the case of absolute or indirect jump or call instructions,
  754. * the new ip is relative to the copied instruction. We need to make
  755. * it relative to the original instruction.
  756. *
  757. * 1) If the single-stepped instruction was pushfl, then the TF and IF
  758. * flags are set in the just-pushed flags, and may need to be cleared.
  759. *
  760. * 2) If the single-stepped instruction was a call, the return address
  761. * that is atop the stack is the address following the copied instruction.
  762. * We need to make it the address following the original instruction.
  763. *
  764. * If this is the first time we've single-stepped the instruction at
  765. * this probepoint, and the instruction is boostable, boost it: add a
  766. * jump instruction after the copied instruction, that jumps to the next
  767. * instruction after the probepoint.
  768. */
  769. static void resume_execution(struct kprobe *p, struct pt_regs *regs,
  770. struct kprobe_ctlblk *kcb)
  771. {
  772. unsigned long *tos = stack_addr(regs);
  773. unsigned long copy_ip = (unsigned long)p->ainsn.insn;
  774. unsigned long orig_ip = (unsigned long)p->addr;
  775. kprobe_opcode_t *insn = p->ainsn.insn;
  776. /* Skip prefixes */
  777. insn = skip_prefixes(insn);
  778. regs->flags &= ~X86_EFLAGS_TF;
  779. switch (*insn) {
  780. case 0x9c: /* pushfl */
  781. *tos &= ~(X86_EFLAGS_TF | X86_EFLAGS_IF);
  782. *tos |= kcb->kprobe_old_flags;
  783. break;
  784. case 0xc2: /* iret/ret/lret */
  785. case 0xc3:
  786. case 0xca:
  787. case 0xcb:
  788. case 0xcf:
  789. case 0xea: /* jmp absolute -- ip is correct */
  790. /* ip is already adjusted, no more changes required */
  791. p->ainsn.boostable = 1;
  792. goto no_change;
  793. case 0xe8: /* call relative - Fix return addr */
  794. *tos = orig_ip + (*tos - copy_ip);
  795. break;
  796. #ifdef CONFIG_X86_32
  797. case 0x9a: /* call absolute -- same as call absolute, indirect */
  798. *tos = orig_ip + (*tos - copy_ip);
  799. goto no_change;
  800. #endif
  801. case 0xff:
  802. if ((insn[1] & 0x30) == 0x10) {
  803. /*
  804. * call absolute, indirect
  805. * Fix return addr; ip is correct.
  806. * But this is not boostable
  807. */
  808. *tos = orig_ip + (*tos - copy_ip);
  809. goto no_change;
  810. } else if (((insn[1] & 0x31) == 0x20) ||
  811. ((insn[1] & 0x31) == 0x21)) {
  812. /*
  813. * jmp near and far, absolute indirect
  814. * ip is correct. And this is boostable
  815. */
  816. p->ainsn.boostable = 1;
  817. goto no_change;
  818. }
  819. default:
  820. break;
  821. }
  822. regs->ip += orig_ip - copy_ip;
  823. no_change:
  824. restore_btf();
  825. }
  826. NOKPROBE_SYMBOL(resume_execution);
  827. /*
  828. * Interrupts are disabled on entry as trap1 is an interrupt gate and they
  829. * remain disabled throughout this function.
  830. */
  831. int kprobe_debug_handler(struct pt_regs *regs)
  832. {
  833. struct kprobe *cur = kprobe_running();
  834. struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
  835. if (!cur)
  836. return 0;
  837. resume_execution(cur, regs, kcb);
  838. regs->flags |= kcb->kprobe_saved_flags;
  839. if ((kcb->kprobe_status != KPROBE_REENTER) && cur->post_handler) {
  840. kcb->kprobe_status = KPROBE_HIT_SSDONE;
  841. cur->post_handler(cur, regs, 0);
  842. }
  843. /* Restore back the original saved kprobes variables and continue. */
  844. if (kcb->kprobe_status == KPROBE_REENTER) {
  845. restore_previous_kprobe(kcb);
  846. goto out;
  847. }
  848. reset_current_kprobe();
  849. out:
  850. preempt_enable_no_resched();
  851. /*
  852. * if somebody else is singlestepping across a probe point, flags
  853. * will have TF set, in which case, continue the remaining processing
  854. * of do_debug, as if this is not a probe hit.
  855. */
  856. if (regs->flags & X86_EFLAGS_TF)
  857. return 0;
  858. return 1;
  859. }
  860. NOKPROBE_SYMBOL(kprobe_debug_handler);
  861. int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
  862. {
  863. struct kprobe *cur = kprobe_running();
  864. struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
  865. if (unlikely(regs->ip == (unsigned long)cur->ainsn.insn)) {
  866. /* This must happen on single-stepping */
  867. WARN_ON(kcb->kprobe_status != KPROBE_HIT_SS &&
  868. kcb->kprobe_status != KPROBE_REENTER);
  869. /*
  870. * We are here because the instruction being single
  871. * stepped caused a page fault. We reset the current
  872. * kprobe and the ip points back to the probe address
  873. * and allow the page fault handler to continue as a
  874. * normal page fault.
  875. */
  876. regs->ip = (unsigned long)cur->addr;
  877. /*
  878. * Trap flag (TF) has been set here because this fault
  879. * happened where the single stepping will be done.
  880. * So clear it by resetting the current kprobe:
  881. */
  882. regs->flags &= ~X86_EFLAGS_TF;
  883. /*
  884. * If the TF flag was set before the kprobe hit,
  885. * don't touch it:
  886. */
  887. regs->flags |= kcb->kprobe_old_flags;
  888. if (kcb->kprobe_status == KPROBE_REENTER)
  889. restore_previous_kprobe(kcb);
  890. else
  891. reset_current_kprobe();
  892. preempt_enable_no_resched();
  893. } else if (kcb->kprobe_status == KPROBE_HIT_ACTIVE ||
  894. kcb->kprobe_status == KPROBE_HIT_SSDONE) {
  895. /*
  896. * We increment the nmissed count for accounting,
  897. * we can also use npre/npostfault count for accounting
  898. * these specific fault cases.
  899. */
  900. kprobes_inc_nmissed_count(cur);
  901. /*
  902. * We come here because instructions in the pre/post
  903. * handler caused the page_fault, this could happen
  904. * if handler tries to access user space by
  905. * copy_from_user(), get_user() etc. Let the
  906. * user-specified handler try to fix it first.
  907. */
  908. if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
  909. return 1;
  910. /*
  911. * In case the user-specified fault handler returned
  912. * zero, try to fix up.
  913. */
  914. if (fixup_exception(regs, trapnr))
  915. return 1;
  916. /*
  917. * fixup routine could not handle it,
  918. * Let do_page_fault() fix it.
  919. */
  920. }
  921. return 0;
  922. }
  923. NOKPROBE_SYMBOL(kprobe_fault_handler);
  924. /*
  925. * Wrapper routine for handling exceptions.
  926. */
  927. int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
  928. void *data)
  929. {
  930. struct die_args *args = data;
  931. int ret = NOTIFY_DONE;
  932. if (args->regs && user_mode(args->regs))
  933. return ret;
  934. if (val == DIE_GPF) {
  935. /*
  936. * To be potentially processing a kprobe fault and to
  937. * trust the result from kprobe_running(), we have
  938. * be non-preemptible.
  939. */
  940. if (!preemptible() && kprobe_running() &&
  941. kprobe_fault_handler(args->regs, args->trapnr))
  942. ret = NOTIFY_STOP;
  943. }
  944. return ret;
  945. }
  946. NOKPROBE_SYMBOL(kprobe_exceptions_notify);
  947. int setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
  948. {
  949. struct jprobe *jp = container_of(p, struct jprobe, kp);
  950. unsigned long addr;
  951. struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
  952. kcb->jprobe_saved_regs = *regs;
  953. kcb->jprobe_saved_sp = stack_addr(regs);
  954. addr = (unsigned long)(kcb->jprobe_saved_sp);
  955. /*
  956. * As Linus pointed out, gcc assumes that the callee
  957. * owns the argument space and could overwrite it, e.g.
  958. * tailcall optimization. So, to be absolutely safe
  959. * we also save and restore enough stack bytes to cover
  960. * the argument area.
  961. * Use __memcpy() to avoid KASAN stack out-of-bounds reports as we copy
  962. * raw stack chunk with redzones:
  963. */
  964. __memcpy(kcb->jprobes_stack, (kprobe_opcode_t *)addr, MIN_STACK_SIZE(addr));
  965. regs->flags &= ~X86_EFLAGS_IF;
  966. trace_hardirqs_off();
  967. regs->ip = (unsigned long)(jp->entry);
  968. /*
  969. * jprobes use jprobe_return() which skips the normal return
  970. * path of the function, and this messes up the accounting of the
  971. * function graph tracer to get messed up.
  972. *
  973. * Pause function graph tracing while performing the jprobe function.
  974. */
  975. pause_graph_tracing();
  976. return 1;
  977. }
  978. NOKPROBE_SYMBOL(setjmp_pre_handler);
  979. void jprobe_return(void)
  980. {
  981. struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
  982. /* Unpoison stack redzones in the frames we are going to jump over. */
  983. kasan_unpoison_stack_above_sp_to(kcb->jprobe_saved_sp);
  984. asm volatile (
  985. #ifdef CONFIG_X86_64
  986. " xchg %%rbx,%%rsp \n"
  987. #else
  988. " xchgl %%ebx,%%esp \n"
  989. #endif
  990. " int3 \n"
  991. " .globl jprobe_return_end\n"
  992. " jprobe_return_end: \n"
  993. " nop \n"::"b"
  994. (kcb->jprobe_saved_sp):"memory");
  995. }
  996. NOKPROBE_SYMBOL(jprobe_return);
  997. NOKPROBE_SYMBOL(jprobe_return_end);
  998. int longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
  999. {
  1000. struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
  1001. u8 *addr = (u8 *) (regs->ip - 1);
  1002. struct jprobe *jp = container_of(p, struct jprobe, kp);
  1003. void *saved_sp = kcb->jprobe_saved_sp;
  1004. if ((addr > (u8 *) jprobe_return) &&
  1005. (addr < (u8 *) jprobe_return_end)) {
  1006. if (stack_addr(regs) != saved_sp) {
  1007. struct pt_regs *saved_regs = &kcb->jprobe_saved_regs;
  1008. printk(KERN_ERR
  1009. "current sp %p does not match saved sp %p\n",
  1010. stack_addr(regs), saved_sp);
  1011. printk(KERN_ERR "Saved registers for jprobe %p\n", jp);
  1012. show_regs(saved_regs);
  1013. printk(KERN_ERR "Current registers\n");
  1014. show_regs(regs);
  1015. BUG();
  1016. }
  1017. /* It's OK to start function graph tracing again */
  1018. unpause_graph_tracing();
  1019. *regs = kcb->jprobe_saved_regs;
  1020. __memcpy(saved_sp, kcb->jprobes_stack, MIN_STACK_SIZE(saved_sp));
  1021. preempt_enable_no_resched();
  1022. return 1;
  1023. }
  1024. return 0;
  1025. }
  1026. NOKPROBE_SYMBOL(longjmp_break_handler);
  1027. bool arch_within_kprobe_blacklist(unsigned long addr)
  1028. {
  1029. return (addr >= (unsigned long)__kprobes_text_start &&
  1030. addr < (unsigned long)__kprobes_text_end) ||
  1031. (addr >= (unsigned long)__entry_text_start &&
  1032. addr < (unsigned long)__entry_text_end);
  1033. }
  1034. int __init arch_init_kprobes(void)
  1035. {
  1036. return 0;
  1037. }
  1038. int arch_trampoline_kprobe(struct kprobe *p)
  1039. {
  1040. return 0;
  1041. }