summaryrefslogtreecommitdiffstats
path: root/kernel/static_call.c
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2020-08-18 15:57:43 +0200
committerIngo Molnar <mingo@kernel.org>2020-09-01 09:58:04 +0200
commit6333e8f73b834f54e395a056e6002403f0862c51 (patch)
treee347bbf8a19d2efcdae91fdd8338c8b175ce4cd5 /kernel/static_call.c
parentstatic_call: Add inline static call infrastructure (diff)
downloadlinux-6333e8f73b834f54e395a056e6002403f0862c51.tar.xz
linux-6333e8f73b834f54e395a056e6002403f0862c51.zip
static_call: Avoid kprobes on inline static_call()s
Similar to how we disallow kprobes on any other dynamic text (ftrace/jump_label) also disallow kprobes on inline static_call()s. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20200818135804.744920586@infradead.org
Diffstat (limited to 'kernel/static_call.c')
-rw-r--r--kernel/static_call.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/kernel/static_call.c b/kernel/static_call.c
index d24349244675..753b2f1b4fb8 100644
--- a/kernel/static_call.c
+++ b/kernel/static_call.c
@@ -204,8 +204,58 @@ static int __static_call_init(struct module *mod,
return 0;
}
+static int addr_conflict(struct static_call_site *site, void *start, void *end)
+{
+ unsigned long addr = (unsigned long)static_call_addr(site);
+
+ if (addr <= (unsigned long)end &&
+ addr + CALL_INSN_SIZE > (unsigned long)start)
+ return 1;
+
+ return 0;
+}
+
+static int __static_call_text_reserved(struct static_call_site *iter_start,
+ struct static_call_site *iter_stop,
+ void *start, void *end)
+{
+ struct static_call_site *iter = iter_start;
+
+ while (iter < iter_stop) {
+ if (addr_conflict(iter, start, end))
+ return 1;
+ iter++;
+ }
+
+ return 0;
+}
+
#ifdef CONFIG_MODULES
+static int __static_call_mod_text_reserved(void *start, void *end)
+{
+ struct module *mod;
+ int ret;
+
+ preempt_disable();
+ mod = __module_text_address((unsigned long)start);
+ WARN_ON_ONCE(__module_text_address((unsigned long)end) != mod);
+ if (!try_module_get(mod))
+ mod = NULL;
+ preempt_enable();
+
+ if (!mod)
+ return 0;
+
+ ret = __static_call_text_reserved(mod->static_call_sites,
+ mod->static_call_sites + mod->num_static_call_sites,
+ start, end);
+
+ module_put(mod);
+
+ return ret;
+}
+
static int static_call_add_module(struct module *mod)
{
return __static_call_init(mod, mod->static_call_sites,
@@ -273,8 +323,26 @@ static struct notifier_block static_call_module_nb = {
.notifier_call = static_call_module_notify,
};
+#else
+
+static inline int __static_call_mod_text_reserved(void *start, void *end)
+{
+ return 0;
+}
+
#endif /* CONFIG_MODULES */
+int static_call_text_reserved(void *start, void *end)
+{
+ int ret = __static_call_text_reserved(__start_static_call_sites,
+ __stop_static_call_sites, start, end);
+
+ if (ret)
+ return ret;
+
+ return __static_call_mod_text_reserved(start, end);
+}
+
static void __init static_call_init(void)
{
int ret;