Fix: adapt to kernel relative references
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 12 Oct 2018 18:47:53 +0000 (14:47 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 18 Oct 2018 14:31:14 +0000 (10:31 -0400)
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 <mathieu.desnoyers@efficios.com>
lttng-tracepoint.c
wrapper/tracepoint.h

index ec77e7ccfb7dbfa4a7ffb62f232682f6ff824690..bbb2c7a4fdb04a79664f2bd2e5ca679176124d78 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <lttng-tracepoint.h>
 #include <wrapper/list.h>
+#include <wrapper/tracepoint.h>
 
 /*
  * Protect the tracepoint table. lttng_tracepoint_mutex nests within
@@ -228,7 +229,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);
@@ -269,7 +270,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;
index 208a8ab3ddbb11ceefe1b8e9010e96f42843b83e..23bc6e2590fedcc21072f0eb2d91dd45d95beb86 100644 (file)
@@ -107,4 +107,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 */
This page took 0.031591 seconds and 4 git commands to generate.