- Two fixes to correct how kprobes handles INT3 now that they're added by other

functionality like the rethunks and not only kgdb
 
 - Remove __init section markings of two functions which are referenced by a
   function in the .text section
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEzv7L6UO9uDPlPSfHEsHwGGHeVUoFAmOxoToACgkQEsHwGGHe
 VUoozA//b2pOA7baV5AudIBRZiKK3Tgviy3JfnGuiBMEI9gKQhzkefWQxk4X7hLA
 +b4UIdQMTLHuUqNPpQYgazW6Sb7HS6TqdTww6MNKKrb3ngnGFI+q6ERuoVyvxTeR
 dv9jtU79aqXTc5n2xpEtL2e2aZCmTQyDo853gq8o50Zji2mdSCdizMJzkfzVTZbI
 oXpqyTlpIP2csos9C9w6HXDshF5Papll6CLoxfafm/bakICKTfYO53pK9nWl/Kre
 beDLPuYiY1nHKFTEApyPp4qEGYVaUfxXHDL7taTLxHcoAh2UQgTdMfJthZGLN+M4
 0wgG+oK51I9vULcaIBQ95Qsonl/c7hMx/P2r22XR42hozAkrb8/vQsZD28SJTBlG
 Sqc+ptzTWB0NfNpbvVQAbMLWTghK1fDcPplHDTmVqcFAtDyBMQymXMTnl9eujyBW
 GJmOEAqPb6n9oAfCkERIGCoca3ebDA4hJsYmfxCx+c03Pcr9A1h3zxdGbfl2tazO
 s5un3uK+dSTZKVufQZBpjl7dtqBDNzQX7JVjkKS2ql4i9M9DmbPPagRAnGirxFlR
 WwRWRa9hcM6Jtg5UoH7Go7NW6PQzHFb1/BOqLnNuvq5hCBAB5ae+24+WE4ZNgbcj
 KtpnwRrwpjEltLBhfb+atwpvO+zieB575lNLeUCcbk3/Qjm1AuE=
 =ZQnP
 -----END PGP SIGNATURE-----

Merge tag 'x86_urgent_for_v6.2_rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86 fixes from Borislav Petkov:

 - Two fixes to correct how kprobes handles INT3 now that they're added
   by other functionality like the rethunks and not only kgdb

 - Remove __init section markings of two functions which are referenced
   by a function in the .text section

* tag 'x86_urgent_for_v6.2_rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  x86/kprobes: Fix optprobe optimization check with CONFIG_RETHUNK
  x86/kprobes: Fix kprobes instruction boudary check with CONFIG_RETHUNK
  x86/calldepth: Fix incorrect init section references
This commit is contained in:
Linus Torvalds 2023-01-01 11:19:50 -08:00
commit 5b129817ae
3 changed files with 17 additions and 25 deletions

View File

@ -119,7 +119,7 @@ static bool is_coretext(const struct core_text *ct, void *addr)
return within_module_coretext(addr);
}
static __init_or_module bool skip_addr(void *dest)
static bool skip_addr(void *dest)
{
if (dest == error_entry)
return true;
@ -181,7 +181,7 @@ static const u8 nops[] = {
0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
};
static __init_or_module void *patch_dest(void *dest, bool direct)
static void *patch_dest(void *dest, bool direct)
{
unsigned int tsize = SKL_TMPL_SIZE;
u8 *pad = dest - tsize;

View File

@ -37,6 +37,7 @@
#include <linux/extable.h>
#include <linux/kdebug.h>
#include <linux/kallsyms.h>
#include <linux/kgdb.h>
#include <linux/ftrace.h>
#include <linux/kasan.h>
#include <linux/moduleloader.h>
@ -281,12 +282,15 @@ static int can_probe(unsigned long paddr)
if (ret < 0)
return 0;
#ifdef CONFIG_KGDB
/*
* Another debugging subsystem might insert this breakpoint.
* In that case, we can't recover it.
* If there is a dynamically installed kgdb sw breakpoint,
* this function should not be probed.
*/
if (insn.opcode.bytes[0] == INT3_INSN_OPCODE)
if (insn.opcode.bytes[0] == INT3_INSN_OPCODE &&
kgdb_has_hit_break(addr))
return 0;
#endif
addr += insn.length;
}

View File

@ -15,6 +15,7 @@
#include <linux/extable.h>
#include <linux/kdebug.h>
#include <linux/kallsyms.h>
#include <linux/kgdb.h>
#include <linux/ftrace.h>
#include <linux/objtool.h>
#include <linux/pgtable.h>
@ -279,19 +280,6 @@ static int insn_is_indirect_jump(struct insn *insn)
return ret;
}
static bool is_padding_int3(unsigned long addr, unsigned long eaddr)
{
unsigned char ops;
for (; addr < eaddr; addr++) {
if (get_kernel_nofault(ops, (void *)addr) < 0 ||
ops != INT3_INSN_OPCODE)
return false;
}
return true;
}
/* Decode whole function to ensure any instructions don't jump into target */
static int can_optimize(unsigned long paddr)
{
@ -334,15 +322,15 @@ static int can_optimize(unsigned long paddr)
ret = insn_decode_kernel(&insn, (void *)recovered_insn);
if (ret < 0)
return 0;
#ifdef CONFIG_KGDB
/*
* In the case of detecting unknown breakpoint, this could be
* a padding INT3 between functions. Let's check that all the
* rest of the bytes are also INT3.
* If there is a dynamically installed kgdb sw breakpoint,
* this function should not be probed.
*/
if (insn.opcode.bytes[0] == INT3_INSN_OPCODE)
return is_padding_int3(addr, paddr - offset + size) ? 1 : 0;
if (insn.opcode.bytes[0] == INT3_INSN_OPCODE &&
kgdb_has_hit_break(addr))
return 0;
#endif
/* Recover address */
insn.kaddr = (void *)addr;
insn.next_byte = (void *)(addr + insn.length);