From nobody Tue Dec 16 14:42:46 2025 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B733E1F4CA9 for ; Sat, 6 Dec 2025 00:17:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764980255; cv=none; b=gt3DKWdemvb30OL9HXYSTE2nOtDr6lHP/DO0mwOtptqkpy8kU2WmmZDVxS2QmzgxKs+jwkITVMZEFJCjNFXwEOPc3suPPsOGKIMHi7PP2Gs5UssCcW74D9iorG1r0VnxQ3HNQciKe5Y4nYIYPH+1UmRSxNAoHPrhGP5qM1oRejk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764980255; c=relaxed/simple; bh=LI1sDcOO4Y4+JFloEIGoQdv+YZQhyxul+6jzUgodhT0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=iFQop8SordN6kGoPFMOHF6oG6yxx517CeKiO+p+CEp0ogwtCzB8jSysacovN22Rzedyc5o/rFV65gjnrVn1b2aFl6wJlg0gLw0c7tBuLVBJGe29XE/+03zDn6vmVBoaSK5cXt2zf2SbGibNXOIr2f/8SvTmP0BUptNH9Q+qGIAg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=pVau5ElV; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pVau5ElV" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-7d481452732so4329232b3a.1 for ; Fri, 05 Dec 2025 16:17:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764980253; x=1765585053; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=8zDbYh8g4andZgSq5KjxfJP+Yx1X56NwE8CC/T+SiEI=; b=pVau5ElVfZwx0/su8cO5Rqh691AFnnWz6RrzYp3Sy65JPI1sKLjj3nW7KYdYWSmgsA wqN6uooeeNSfiSWQFYEKWRKU9ZwvgOCJBkSzZIj08kSsx/88FS4ffQzGkIwZoDTYK2fe YJIMyGVKJKi5DgVWO1duCxNlrtonrWGH83SxF98yGTP5vVDKUHMvdqQZABZ36WTJ29iL RI5r+azoW8h5jtBTj9Xq5a58S16XF3XksydgNWse0hYPABjSLnLJS5pjFaYDr/N18kw3 ozAvHONmGu+4ouR4dU08quepnzo35TueGFCL97Yv3oFX4i5vB0N70+o+A0xMxMmtCF/0 Iiuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764980253; x=1765585053; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8zDbYh8g4andZgSq5KjxfJP+Yx1X56NwE8CC/T+SiEI=; b=hzzmetc6csdNu08rZTvFwbnRnILznXng8/OcxXUrdgHhNIIJp70XvxSP/k/q9Z7Ck1 G0w04pGdBYY+iVsgl2o/tXcG1KVEnyC6Km4BqYb/6rQlvIKUOuaka8waBtZneTpd1hXw elqpMstSYiVu5e214Owx8TWO24EvL/L+KgU4s7zKP43IJPolG+IIt+to/GBHWnb7lDPO lnAY6Awc2ca3cIrs2GvurWN18epoyNmOU7CkgFMc1/khWEB1YzDj8S7Da2cIeENLNpAm MRXEI+0BT14iQGltHHdOo1WxrUHVTq5c2tZKLckkYe/RfUbpeVRI3LMZZtalZodpoHFX x5Hg== X-Forwarded-Encrypted: i=1; AJvYcCWzJSuwO055KouUuMfq5avlGaZE0nFiHLd4fc6rD+tfV8ocgn4sTscv7WJa+t/ql+8JVzU9sPqojljV89s=@vger.kernel.org X-Gm-Message-State: AOJu0Yz2pLrFL1CJ5/jAtJ3XwCzeG/VMoCuNrG94ZNicG9q4S2+0t0RB hUZpOxxhgbGoi7LPPRscw4Wip7c8ohh4jt474PF64ZjthSoeifoU8/NYyof2ww+q+wGuctIu2/V Xl/eONQ== X-Google-Smtp-Source: AGHT+IF/oM705F739LTH8aiHz6AKpqWGtQrIi8ngNpofrp5S2I+xWIdijTs20meiR96WS9wVH7kHD0C0BxI= X-Received: from pgce2.prod.google.com ([2002:a05:6a02:1c2:b0:bd0:79b2:aa3f]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:7b23:b0:366:1880:7e06 with SMTP id adf61e73a8af0-36618807e8dmr621575637.0.1764980252791; Fri, 05 Dec 2025 16:17:32 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 5 Dec 2025 16:16:39 -0800 In-Reply-To: <20251206001720.468579-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251206001720.468579-1-seanjc@google.com> X-Mailer: git-send-email 2.52.0.223.gf5cc29aaa4-goog Message-ID: <20251206001720.468579-4-seanjc@google.com> Subject: [PATCH v6 03/44] perf: Move security_perf_event_free() call to __free_event() From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Xin Li , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Sean Christopherson , Paolo Bonzini Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, loongarch@lists.linux.dev, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Mingwei Zhang , Xudong Hao , Sandipan Das , Dapeng Mi , Xiong Zhang , Manali Shukla , Jim Mattson Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Tested-by: Xudong Hao Signed-off-by: Sean Christopherson --- kernel/events/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 1e37ab90b815..e34112df8b31 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -5602,6 +5602,8 @@ static void __free_event(struct perf_event *event) { struct pmu *pmu =3D event->pmu; =20 + security_perf_event_free(event); + if (event->attach_state & PERF_ATTACH_CALLCHAIN) put_callchain_buffers(); =20 @@ -5665,8 +5667,6 @@ static void _free_event(struct perf_event *event) =20 unaccount_event(event); =20 - security_perf_event_free(event); - if (event->rb) { /* * Can happen when we close an event with re-directed output. --=20 2.52.0.223.gf5cc29aaa4-goog