From 90bdfac94a38d6dac18208413cd0e6e1b49a3599 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 11 Feb 2014 06:02:42 -0500 Subject: [PATCH] Fix: OOT lttng-statedump tracepoints not visible with signed kernels Users have reported being unable to trace non-signed modules loaded within a kernel supporting module signature. Here is the relevant report of this issue to Linux upstream, with a proposed fix: https://lkml.org/lkml/2014/2/10/747 Work-around the issue for lttng-statedump.ko tracepoints. Signed-off-by: Mathieu Desnoyers --- lttng-statedump-impl.c | 9 ++++++++ wrapper/tracepoint.h | 52 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/lttng-statedump-impl.c b/lttng-statedump-impl.c index 1269a3e0..ce47f041 100755 --- a/lttng-statedump-impl.c +++ b/lttng-statedump-impl.c @@ -52,6 +52,7 @@ #include "wrapper/fdtable.h" #include "wrapper/nsproxy.h" #include "wrapper/irq.h" +#include "wrapper/tracepoint.h" #ifdef CONFIG_LTTNG_HAS_LIST_IRQ #include @@ -422,6 +423,14 @@ int lttng_statedump_start(struct lttng_session *session) } EXPORT_SYMBOL_GPL(lttng_statedump_start); +static +int __init lttng_statedump_init(void) +{ + return wrapper_lttng_fixup_sig(THIS_MODULE); +} + +module_init(lttng_statedump_init); + MODULE_LICENSE("GPL and additional rights"); MODULE_AUTHOR("Jean-Hugues Deschenes"); MODULE_DESCRIPTION("Linux Trace Toolkit Next Generation Statedump"); diff --git a/wrapper/tracepoint.h b/wrapper/tracepoint.h index 798d785b..60b36856 100644 --- a/wrapper/tracepoint.h +++ b/wrapper/tracepoint.h @@ -25,6 +25,7 @@ #include #include +#include #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)) @@ -41,4 +42,55 @@ #endif /* HAVE_KABI_2635_TRACEPOINT */ +#ifdef CONFIG_MODULE_SIG + +#include +#include "kallsyms.h" + +static inline +int wrapper_tracepoint_module_notify(struct notifier_block *nb, + unsigned long val, struct module *mod) +{ + int (*tracepoint_module_notify_sym)(struct notifier_block *nb, + unsigned long val, struct module *mod); + + tracepoint_module_notify_sym = + (void *) kallsyms_lookup_funcptr("tracepoint_module_notify"); + if (tracepoint_module_notify_sym) { + return tracepoint_module_notify_sym(nb, val, mod); + } else { + printk(KERN_WARNING "LTTng: tracepoint_module_notify symbol lookup failed.\n"); + return -ENOSYS; + } +} + +static inline +int wrapper_lttng_fixup_sig(struct module *mod) +{ + int ret = 0; + + /* + * This is for module.c confusing force loaded modules with + * unsigned modules. + */ + if (!THIS_MODULE->sig_ok && + THIS_MODULE->taints & (1U << TAINT_FORCED_MODULE)) { + THIS_MODULE->taints &= ~(1U << TAINT_FORCED_MODULE); + ret = wrapper_tracepoint_module_notify(NULL, + MODULE_STATE_COMING, mod); + THIS_MODULE->taints |= (1U << TAINT_FORCED_MODULE); + } + return ret; +} + +#else /* CONFIG_MODULE_SIG */ + +static inline +int wrapper_lttng_fixup_sig(struct module *mod) +{ + return 0; +} + +#endif /* #else CONFIG_MODULE_SIG */ + #endif /* _LTTNG_WRAPPER_TRACEPOINT_H */ -- 2.34.1