From: Mathieu Desnoyers Date: Fri, 12 Oct 2018 18:47:53 +0000 (-0400) Subject: Fix: adapt to kernel relative references X-Git-Tag: v2.9.11~3 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=f083002c25bb222c2e07bbffb17f77afab96b765;p=lttng-modules.git Fix: adapt to kernel relative references Upstream Linux commit 46e0c9be20 introduces relative references in the struct tracepoint array of pointers. Up to (including) v4.19-rc7, the upstream kernel has a type mismatch bug that allows it to pass an out-of-bound end of array to modules coming/going notifiers. The fix for upstream Linux is to introduce a new type: tracepoint_ptr_t, which can be used to adequately iterate on the array. It is introduced prior to v4.19 as commit 9c0be3f6b5d77 "tracepoint: Fix tracepoint array element size mismatch". Signed-off-by: Mathieu Desnoyers --- diff --git a/lttng-tracepoint.c b/lttng-tracepoint.c index 7a50dd28..4cfec385 100644 --- a/lttng-tracepoint.c +++ b/lttng-tracepoint.c @@ -30,6 +30,7 @@ #include #include +#include /* * Protect the tracepoint table. lttng_tracepoint_mutex nests within @@ -241,7 +242,7 @@ int lttng_tracepoint_coming(struct tp_module *tp_mod) struct tracepoint_entry *e; struct lttng_tp_probe *p; - tp = tp_mod->mod->tracepoints_ptrs[i]; + tp = lttng_tracepoint_ptr_deref(&tp_mod->mod->tracepoints_ptrs[i]); e = get_tracepoint(tp->name); if (!e) { e = add_tracepoint(tp->name); @@ -282,7 +283,7 @@ int lttng_tracepoint_going(struct tp_module *tp_mod) struct tracepoint_entry *e; struct lttng_tp_probe *p; - tp = tp_mod->mod->tracepoints_ptrs[i]; + tp = lttng_tracepoint_ptr_deref(&tp_mod->mod->tracepoints_ptrs[i]); e = get_tracepoint(tp->name); if (!e || !e->tp) continue; diff --git a/wrapper/tracepoint.h b/wrapper/tracepoint.h index 780f9a86..a860cb82 100644 --- a/wrapper/tracepoint.h +++ b/wrapper/tracepoint.h @@ -120,4 +120,16 @@ int wrapper_lttng_fixup_sig(struct module *mod) #endif /*#else #if defined(CONFIG_MODULE_SIG) && defined(MODULE) */ +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,19,0)) +static inline struct tracepoint *lttng_tracepoint_ptr_deref(tracepoint_ptr_t *p) +{ + return tracepoint_ptr_deref(p); +} +#else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,19,0)) */ +static inline struct tracepoint *lttng_tracepoint_ptr_deref(struct tracepoint **p) +{ + return *p; +} +#endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,19,0)) */ + #endif /* _LTTNG_WRAPPER_TRACEPOINT_H */