Skip to content

tracing: hist: two named trigger error paths that free a published trigger

Donggeun Yoo linux-trace-kernel lkml sashiko-reviews 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 4 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2tracing: hist: take the reference before publishing the named triggerkernel/trace/trace_events_hist.c+6 -52 replies
2/2tracing: hist: undo the registration when enabling the trigger failskernel/trace/trace_events_hist.c+10 -71 reply

Reviews trailers per patch

1 of 2 patches has a Reviewed-by or Acked-by.

PatchTom Zanussi
1/2A-b
2/2

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/2] tracing: hist: two named trigger error paths that free a published trigger

Both of these were pointed out on the list against an unrelated hist patch [1], and both are the same shape as commit 6f86bdeab633 ("tracing:
Fix bad hist from corrupting named_triggers list"): a trigger that is on the global named_triggers list gets freed without being taken off it, and the next lookup by name reads the freed object.

Patch 1 is the init path. event_hist_trigger_named_init() saves the trigger under the name before it takes the reference that can fail, and does not undo the save.

Patch 2 is the enable path, the one case that fix did not reach. hist_trigger_enable() removes the trigger from file->triggers on failure, which is the only handle hist_unregister_trigger() has, so the ->free() that unlinks it never runs. Leaving it on the list lets the existing unregister do the whole unwind, which also stops out_free from touching a hist_data that hist_register_trigger() already destroyed.

The two are independent and can be taken separately.

Reproduced on x86_64 under KASAN_INLINE by making the two failures fire from a debug knob, since neither is reachable without an allocation failure or an event that refuses to register. Same kernel and initramfs either way, one boot per case:

                                        v7.3-rc2        patched
  control, no injected failure          clean           clean
  1) nested init fails                  KASAN           clean
  2) enable fails, new named trigger    KASAN           clean
  3) enable fails, shared histogram     KASAN + panic   clean

Case 3 reports in remove_hist_vars() rather than find_named_trigger(), from the out_free fall-through described in patch 2.

After each injected failure the same name is written again and is accepted on the patched kernel, so the trigger really did leave the list; on v7.3-rc2 case 2 rejects it.

selftests/ftrace test.d/trigger before and after: 45 results, identical item by item (32 passed, 3 failed, 2 unresolved, 8 unsupported). The failures and the unresolved results are there without the patches too.

Donggeun Yoo (2):
tracing: hist: take the reference before publishing the named trigger
tracing: hist: undo the registration when enabling the trigger fails

 kernel/trace/trace_events_hist.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

base-commit: df2908090cda368b01ff43709f51890076c56157

Signature · 1 line
2.53.0