Skip to content

Commit 66e9b07

Browse files
committed
kprobes: Prevent probes in .noinstr.text section
Instrumentation is forbidden in the .noinstr.text section. Make kprobes respect this. Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Alexandre Chartre <[email protected]> Acked-by: Peter Zijlstra <[email protected]> Acked-by: Masami Hiramatsu <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 4e321b7 commit 66e9b07

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

include/linux/module.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ struct module {
458458
void __percpu *percpu;
459459
unsigned int percpu_size;
460460
#endif
461+
void *noinstr_text_start;
462+
unsigned int noinstr_text_size;
461463

462464
#ifdef CONFIG_TRACEPOINTS
463465
unsigned int num_tracepoints;

kernel/kprobes.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,6 +2229,12 @@ static int __init populate_kprobe_blacklist(unsigned long *start,
22292229
/* Symbols in __kprobes_text are blacklisted */
22302230
ret = kprobe_add_area_blacklist((unsigned long)__kprobes_text_start,
22312231
(unsigned long)__kprobes_text_end);
2232+
if (ret)
2233+
return ret;
2234+
2235+
/* Symbols in noinstr section are blacklisted */
2236+
ret = kprobe_add_area_blacklist((unsigned long)__noinstr_text_start,
2237+
(unsigned long)__noinstr_text_end);
22322238

22332239
return ret ? : arch_populate_kprobe_blacklist();
22342240
}
@@ -2248,6 +2254,12 @@ static void add_module_kprobe_blacklist(struct module *mod)
22482254
end = start + mod->kprobes_text_size;
22492255
kprobe_add_area_blacklist(start, end);
22502256
}
2257+
2258+
start = (unsigned long)mod->noinstr_text_start;
2259+
if (start) {
2260+
end = start + mod->noinstr_text_size;
2261+
kprobe_add_area_blacklist(start, end);
2262+
}
22512263
}
22522264

22532265
static void remove_module_kprobe_blacklist(struct module *mod)
@@ -2265,6 +2277,12 @@ static void remove_module_kprobe_blacklist(struct module *mod)
22652277
end = start + mod->kprobes_text_size;
22662278
kprobe_remove_area_blacklist(start, end);
22672279
}
2280+
2281+
start = (unsigned long)mod->noinstr_text_start;
2282+
if (start) {
2283+
end = start + mod->noinstr_text_size;
2284+
kprobe_remove_area_blacklist(start, end);
2285+
}
22682286
}
22692287

22702288
/* Module notifier call back, checking kprobes on the module */

kernel/module.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3150,6 +3150,9 @@ static int find_module_sections(struct module *mod, struct load_info *info)
31503150
}
31513151
#endif
31523152

3153+
mod->noinstr_text_start = section_objs(info, ".noinstr.text", 1,
3154+
&mod->noinstr_text_size);
3155+
31533156
#ifdef CONFIG_TRACEPOINTS
31543157
mod->tracepoints_ptrs = section_objs(info, "__tracepoints_ptrs",
31553158
sizeof(*mod->tracepoints_ptrs),

0 commit comments

Comments
 (0)