From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.19 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796289228; b=bomyuajbN3uWUWAWnIF3iwYlYHeItiABmI8Q4aqb9oQDKCeV9zuj0LylimmUW4vgihVE PexiF1KDUKo/+7YZmrbB+K2fg/CEC/37V+iPbUu+ZAcKt1xv/76cot9Qm5Hi4a6b7IVDy 9Ok3J2WQio4RaOlfGzdZe/Hn4JvWKkO5olw0WWQ0vZQUItd0TWe5uxOdRYvnH72QKyHUE sB4P1r3kLELlWHkWsEVxSKibIMtXt78hp0x2JcS601jwApnJL23T1mnDCom0TOxZziGSk F2EJebObK12AKcLY+k/X850eQvrwJhwtjxLvBf/XaVECtDW1m2Dz8yD0gGF+Zw4+esQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796289228; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Message-ID:Date: MIME-Version:User-Agent:Subject:To:Cc:References:Content-Language: From:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=v8rgdqAFwY3bkJ+2O/YiyiBbZC6LIPeQ0rNhky+C6ug=; b=1koScHSrWc3PqeTC7uJyGsrHX+wrDUiU0BdmfpaTRmsJO83jglTQl8HZT1cLdjD4Ikgi qdaqhTYWCEBikBcx5IPiY2MRSBvGL6Rrm3+uIi6snoGga1eni09QU8b94nryy5syFinyb vVFn4xVUYaoG+C/6AcrrGuZtDn9r0tNsdD1henX14bNnNakcZBv5DXwcc8UEoiMpmvw02 B4mQvtEnOqt/eXDI4i1rrf8pbjwatHmAh0XojCPbzUh77zT1vSub541AfGpl818MIvjeH Ioi9WHk2I74Ug+3HvjhGkHdH1mbldbJwEykF83tMOHT/8Le2iatm7kBWjUj5DQwV+dw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=ikGSrovh; arc=none smtp.remote-ip=192.198.163.19 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AAC8606A68B; Thu, 3 Dec 2026 09:13:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6AAC8606A68B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=ikGSrovh DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796289227; x=1827825227; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=v8rgdqAFwY3bkJ+2O/YiyiBbZC6LIPeQ0rNhky+C6ug=; b=ikGSrovhHjNYY8Ryq7zutMJnMaEuCHSX2NPE1zeOLNPeeVPm/I/LsJ3r gruKsz2LZZVy8YtRLcvEWlgKbzFX4KU5Y+GzFlG3t0p+ZZLRy1vYju+Yh jaFI2rgpU+GQE1lzei4jZdJIBpgRQN7K1LWcX52p2DFAlZ55MJ6UiAm6q g327wQeCGy2lyT9e3XMQ7PE8rBSwxCkb8Sg2zpuzeD1WcROf6iRV1rYDm eyRdfkDDQ9ucbx/lc5o1ef9iy/YNYUBaZUh5nk2u8LJqxAzFw/GrB9o63 IQCq1KIHbtru1xOKDQnmh755+fQn638YrFZMtiDwnKBNV7jlTDgiRl+oW w==; X-CSE-ConnectionGUID: zGIUl5PeSsa13MAFNJ1ljQ== X-CSE-MsgGUID: l/AO5iBGS5WNzJCk5iaUrQ== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5256824" X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="5256824" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 01:13:46 -0800 X-CSE-ConnectionGUID: KFsURk2iS+2LbPvx9VPtZw== X-CSE-MsgGUID: 1sfPiFJ1RuGe+kgshZcJkg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="14317792" Received: from dapengmi-mobl1.ccr.corp.intel.com (HELO [10.124.241.239]) ([10.124.241.239]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 01:13:42 -0800 Message-ID: <6d20dd25-a59c-4734-a52a-afcce8a9fd6d@linux.intel.com> Date: Thu, 3 Dec 2026 17:13:39 +0800 X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] perf/core: Check for a NULL cpc before cancelling its hrtimer To: Hang Zhengyang , Peter Zijlstra , Ingo Molnar Cc: Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Hanxiang Xu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20261203073728.2470032-1-hang.zhengyang1010@gmail.com> Content-Language: en-US From: "Mi, Dapeng" In-Reply-To: <20261203073728.2470032-1-hang.zhengyang1010@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit It's a known issue, there is already a fixing patch for this issue. Thanks. https://lore.kernel.org/all/20261102005905.2017784-2-dapeng1.mi@linux.intel.com/ On 12/3/2026 3:37 PM, Hang Zhengyang wrote: > perf_pmu_register() allocates the per-CPU contexts one CPU at a time. > When one of these allocations fails, it returns -ENOMEM and > perf_pmu_free() runs with NULL entries for the CPUs that are not > allocated yet. The loop in perf_pmu_free() skips those entries, but > commit 35fbc5a85891 ("perf/core: Cancel hrtimer on > perf_pmu_unregister()") put the hrtimer_cancel() before the NULL check. > Such a failure then oopses instead of returning -ENOMEM: > > KASAN: null-ptr-deref in range [0x0000000000000108-0x000000000000010f] > RIP: 0010:hrtimer_active+0xc1/0x350 > Call Trace: > hrtimer_cancel+0x15/0x40 > perf_pmu_free+0x1cd/0x320 > perf_pmu_register+0x4e1/0xb40 > > The allocations are small GFP_KERNEL ones, so this needs fault injection > or a registering task that the OOM killer has picked. Found with failslab > fault injection on the allocations in perf_pmu_register(). > > Cancel the hrtimer after the NULL check. > > Fixes: 35fbc5a85891 ("perf/core: Cancel hrtimer on perf_pmu_unregister()") > Cc: stable@vger.kernel.org > Signed-off-by: Hang Zhengyang > --- > > Notes: > Tested with a module that sets current->fail_nth before each > perf_pmu_register() call, in a KVM guest with 4 CPUs, KASAN and failslab, > on tip/perf/urgent 67b34211a9eb: the oops above without the patch; with > it, fail_nth 1-4 return -ENOMEM and fail_nth 5 registers the PMU. > > I used Claude Code to find the issue, write the patch and run the test. > I reviewed the patch. > > kernel/events/core.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/events/core.c b/kernel/events/core.c > index 4ab3919ac78e..726ed5538397 100644 > --- a/kernel/events/core.c > +++ b/kernel/events/core.c > @@ -12999,9 +12999,9 @@ static void perf_pmu_free(struct pmu *pmu) > struct perf_cpu_pmu_context *cpc; > > cpc = *per_cpu_ptr(pmu->cpu_pmu_context, cpu); > - hrtimer_cancel(&cpc->hrtimer); > if (!cpc) > continue; > + hrtimer_cancel(&cpc->hrtimer); > if (cpc->epc.embedded) { > /* refcount managed */ > put_pmu_ctx(&cpc->epc); > > base-commit: 67b34211a9eb103aba474bc179fab3dd2912f07e