|
| 1 | +tracing/perf: Fix double put of trace event when init fails |
| 2 | + |
| 3 | +jira LE-1907 |
| 4 | +Rebuild_History Non-Buildable kernel-3.10.0-1160.118.1.el7 |
| 5 | +commit-author Steven Rostedt (Google) <rostedt@goodmis.org> |
| 6 | +commit 7249921d94ff64f67b733eca0b68853a62032b3d |
| 7 | +Empty-Commit: Cherry-Pick Conflicts during history rebuild. |
| 8 | +Will be included in final tarball splat. Ref for failed cherry-pick at: |
| 9 | +ciq/ciq_backports/kernel-3.10.0-1160.118.1.el7/7249921d.failed |
| 10 | + |
| 11 | +If in perf_trace_event_init(), the perf_trace_event_open() fails, then it |
| 12 | +will call perf_trace_event_unreg() which will not only unregister the perf |
| 13 | +trace event, but will also call the put() function of the tp_event. |
| 14 | + |
| 15 | +The problem here is that the trace_event_try_get_ref() is called by the |
| 16 | +caller of perf_trace_event_init() and if perf_trace_event_init() returns a |
| 17 | +failure, it will then call trace_event_put(). But since the |
| 18 | +perf_trace_event_unreg() already called the trace_event_put() function, it |
| 19 | +triggers a WARN_ON(). |
| 20 | + |
| 21 | + WARNING: CPU: 1 PID: 30309 at kernel/trace/trace_dynevent.c:46 trace_event_dyn_put_ref+0x15/0x20 |
| 22 | + |
| 23 | +If perf_trace_event_reg() does not call the trace_event_try_get_ref() then |
| 24 | +the perf_trace_event_unreg() should not be calling trace_event_put(). This |
| 25 | +breaks symmetry and causes bugs like these. |
| 26 | + |
| 27 | +Pull out the trace_event_put() from perf_trace_event_unreg() and call it |
| 28 | +in the locations that perf_trace_event_unreg() is called. This not only |
| 29 | +fixes this bug, but also brings back the proper symmetry of the reg/unreg |
| 30 | +vs get/put logic. |
| 31 | + |
| 32 | +Link: https://lore.kernel.org/all/cover.1660347763.git.kjlx@templeofstupid.com/ |
| 33 | +Link: https://lkml.kernel.org/r/20220816192817.43d5e17f@gandalf.local.home |
| 34 | + |
| 35 | + Cc: stable@vger.kernel.org |
| 36 | +Fixes: 1d18538e6a092 ("tracing: Have dynamic events have a ref counter") |
| 37 | + Reported-by: Krister Johansen <kjlx@templeofstupid.com> |
| 38 | + Reviewed-by: Krister Johansen <kjlx@templeofstupid.com> |
| 39 | + Tested-by: Krister Johansen <kjlx@templeofstupid.com> |
| 40 | + Acked-by: Jiri Olsa <jolsa@kernel.org> |
| 41 | + Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> |
| 42 | +(cherry picked from commit 7249921d94ff64f67b733eca0b68853a62032b3d) |
| 43 | + Signed-off-by: Jonathan Maple <jmaple@ciq.com> |
| 44 | + |
| 45 | +# Conflicts: |
| 46 | +# kernel/trace/trace_event_perf.c |
| 47 | +diff --cc kernel/trace/trace_event_perf.c |
| 48 | +index df312b12b40f,61e3a2620fa3..000000000000 |
| 49 | +--- a/kernel/trace/trace_event_perf.c |
| 50 | ++++ b/kernel/trace/trace_event_perf.c |
| 51 | +@@@ -146,8 -176,6 +146,11 @@@ static void perf_trace_event_unreg(stru |
| 52 | + perf_trace_buf[i] = NULL; |
| 53 | + } |
| 54 | + } |
| 55 | +++<<<<<<< HEAD |
| 56 | + +out: |
| 57 | + + module_put(tp_event->mod); |
| 58 | +++======= |
| 59 | +++>>>>>>> 7249921d94ff (tracing/perf: Fix double put of trace event when init fails) |
| 60 | + } |
| 61 | + |
| 62 | + static int perf_trace_event_open(struct perf_event *p_event) |
| 63 | +* Unmerged path kernel/trace/trace_event_perf.c |
0 commit comments