]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tracepoint: balance regfunc() on func_add() failure in tracepoint_add_func()
authorDavid Carlier <devnexen@gmail.com>
Mon, 13 Apr 2026 19:06:01 +0000 (20:06 +0100)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Tue, 14 Apr 2026 09:17:02 +0000 (05:17 -0400)
When a tracepoint goes through the 0 -> 1 transition, tracepoint_add_func()
invokes the subsystem's ext->regfunc() before attempting to install the
new probe via func_add(). If func_add() then fails (for example, when
allocate_probes() cannot allocate a new probe array under memory pressure
and returns -ENOMEM), the function returns the error without calling the
matching ext->unregfunc(), leaving the side effects of regfunc() behind
with no installed probe to justify them.

For syscall tracepoints this is particularly unpleasant: syscall_regfunc()
bumps sys_tracepoint_refcount and sets SYSCALL_TRACEPOINT on every task.
After a leaked failure, the refcount is stuck at a non-zero value with no
consumer, and every task continues paying the syscall trace entry/exit
overhead until reboot. Other subsystems providing regfunc()/unregfunc()
pairs exhibit similarly scoped persistent state.

Mirror the existing 1 -> 0 cleanup and call ext->unregfunc() in the
func_add() error path, gated on the same condition used there so the
unwind is symmetric with the registration.

Fixes: 8cf868affdc4 ("tracing: Have the reg function allow to fail")
Cc: stable@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Link: https://patch.msgid.link/20260413190601.21993-1-devnexen@gmail.com
Signed-off-by: David Carlier <devnexen@gmail.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/tracepoint.c

index 91905aa19294d27348f87f8bcd73c05a246bc6a3..dffef52a807bc83f8bdcfce090fda04939a2e436 100644 (file)
@@ -300,6 +300,8 @@ static int tracepoint_add_func(struct tracepoint *tp,
                        lockdep_is_held(&tracepoints_mutex));
        old = func_add(&tp_funcs, func, prio);
        if (IS_ERR(old)) {
+               if (tp->ext && tp->ext->unregfunc && !static_key_enabled(&tp->key))
+                       tp->ext->unregfunc();
                WARN_ON_ONCE(warn && PTR_ERR(old) != -ENOMEM);
                return PTR_ERR(old);
        }