mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-01 14:44:12 +00:00
kprobes: Blacklist symbols in arch-defined prohibited area
[ Upstream commit fb1a59fae8
]
Blacklist symbols in arch-defined probe-prohibited areas.
With this change, user can see all symbols which are prohibited
to probe in debugfs.
All archtectures which have custom prohibit areas should define
its own arch_populate_kprobe_blacklist() function, but unless that,
all symbols marked __kprobes are blacklisted.
Reported-by: Andrea Righi <righi.andrea@gmail.com>
Tested-by: Andrea Righi <righi.andrea@gmail.com>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: David S. Miller <davem@davemloft.net>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Yonghong Song <yhs@fb.com>
Link: http://lkml.kernel.org/r/154503485491.26176.15823229545155174796.stgit@devbox
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
73c1ca2dda
commit
98cf16d33c
2 changed files with 56 additions and 14 deletions
|
@ -243,10 +243,13 @@ extern int arch_init_kprobes(void);
|
|||
extern void show_registers(struct pt_regs *regs);
|
||||
extern void kprobes_inc_nmissed_count(struct kprobe *p);
|
||||
extern bool arch_within_kprobe_blacklist(unsigned long addr);
|
||||
extern int arch_populate_kprobe_blacklist(void);
|
||||
extern bool arch_kprobe_on_func_entry(unsigned long offset);
|
||||
extern bool kprobe_on_func_entry(kprobe_opcode_t *addr, const char *sym, unsigned long offset);
|
||||
|
||||
extern bool within_kprobe_blacklist(unsigned long addr);
|
||||
extern int kprobe_add_ksym_blacklist(unsigned long entry);
|
||||
extern int kprobe_add_area_blacklist(unsigned long start, unsigned long end);
|
||||
|
||||
struct kprobe_insn_cache {
|
||||
struct mutex mutex;
|
||||
|
|
|
@ -2096,6 +2096,47 @@ void dump_kprobe(struct kprobe *kp)
|
|||
}
|
||||
NOKPROBE_SYMBOL(dump_kprobe);
|
||||
|
||||
int kprobe_add_ksym_blacklist(unsigned long entry)
|
||||
{
|
||||
struct kprobe_blacklist_entry *ent;
|
||||
unsigned long offset = 0, size = 0;
|
||||
|
||||
if (!kernel_text_address(entry) ||
|
||||
!kallsyms_lookup_size_offset(entry, &size, &offset))
|
||||
return -EINVAL;
|
||||
|
||||
ent = kmalloc(sizeof(*ent), GFP_KERNEL);
|
||||
if (!ent)
|
||||
return -ENOMEM;
|
||||
ent->start_addr = entry;
|
||||
ent->end_addr = entry + size;
|
||||
INIT_LIST_HEAD(&ent->list);
|
||||
list_add_tail(&ent->list, &kprobe_blacklist);
|
||||
|
||||
return (int)size;
|
||||
}
|
||||
|
||||
/* Add all symbols in given area into kprobe blacklist */
|
||||
int kprobe_add_area_blacklist(unsigned long start, unsigned long end)
|
||||
{
|
||||
unsigned long entry;
|
||||
int ret = 0;
|
||||
|
||||
for (entry = start; entry < end; entry += ret) {
|
||||
ret = kprobe_add_ksym_blacklist(entry);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
if (ret == 0) /* In case of alias symbol */
|
||||
ret = 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __init __weak arch_populate_kprobe_blacklist(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Lookup and populate the kprobe_blacklist.
|
||||
*
|
||||
|
@ -2107,26 +2148,24 @@ NOKPROBE_SYMBOL(dump_kprobe);
|
|||
static int __init populate_kprobe_blacklist(unsigned long *start,
|
||||
unsigned long *end)
|
||||
{
|
||||
unsigned long entry;
|
||||
unsigned long *iter;
|
||||
struct kprobe_blacklist_entry *ent;
|
||||
unsigned long entry, offset = 0, size = 0;
|
||||
int ret;
|
||||
|
||||
for (iter = start; iter < end; iter++) {
|
||||
entry = arch_deref_entry_point((void *)*iter);
|
||||
|
||||
if (!kernel_text_address(entry) ||
|
||||
!kallsyms_lookup_size_offset(entry, &size, &offset))
|
||||
ret = kprobe_add_ksym_blacklist(entry);
|
||||
if (ret == -EINVAL)
|
||||
continue;
|
||||
|
||||
ent = kmalloc(sizeof(*ent), GFP_KERNEL);
|
||||
if (!ent)
|
||||
return -ENOMEM;
|
||||
ent->start_addr = entry;
|
||||
ent->end_addr = entry + size;
|
||||
INIT_LIST_HEAD(&ent->list);
|
||||
list_add_tail(&ent->list, &kprobe_blacklist);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
|
||||
/* Symbols in __kprobes_text are blacklisted */
|
||||
ret = kprobe_add_area_blacklist((unsigned long)__kprobes_text_start,
|
||||
(unsigned long)__kprobes_text_end);
|
||||
|
||||
return ret ? : arch_populate_kprobe_blacklist();
|
||||
}
|
||||
|
||||
/* Module notifier call back, checking kprobes on the module */
|
||||
|
|
Loading…
Reference in a new issue