]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf: Move security_perf_event_free() call to __free_event()
authorSean Christopherson <seanjc@google.com>
Sat, 6 Dec 2025 00:16:39 +0000 (16:16 -0800)
committerPeter Zijlstra <peterz@infradead.org>
Wed, 17 Dec 2025 12:31:04 +0000 (13:31 +0100)
Move the freeing of any security state associated with a perf event from
_free_event() to __free_event(), i.e. invoke security_perf_event_free() in
the error paths for perf_event_alloc().  This will allow adding potential
error paths in perf_event_alloc() that can occur after allocating security
state.

Note, kfree() and thus security_perf_event_free() is a nop if
event->security is NULL, i.e. calling security_perf_event_free() even if
security_perf_event_alloc() fails or is never reached is functionality ok.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Xudong Hao <xudong.hao@intel.com>
Link: https://patch.msgid.link/20251206001720.468579-4-seanjc@google.com
kernel/events/core.c

index fab358daa42e7158222c3cc2d19e3399dad1d0ec..6973483d0dfa61519c9ea18ea3e8974120035645 100644 (file)
@@ -5601,6 +5601,8 @@ static void __free_event(struct perf_event *event)
 {
        struct pmu *pmu = event->pmu;
 
+       security_perf_event_free(event);
+
        if (event->attach_state & PERF_ATTACH_CALLCHAIN)
                put_callchain_buffers();
 
@@ -5664,8 +5666,6 @@ static void _free_event(struct perf_event *event)
 
        unaccount_event(event);
 
-       security_perf_event_free(event);
-
        if (event->rb) {
                /*
                 * Can happen when we close an event with re-directed output.