Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11C1F1ACECE for ; Thu, 1 May 2025 14:11:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746108686; cv=none; b=qM1WX+TddPry5aSjh/XoEeQOmnmH71Mf1YvsdCStXHvrP9V3cNIH56cOxTHMqd01lIoQ8UQiVe3zfn2IA7Dks9/klVZHi/NnyImaklswxA953dDz/IkKxT/RRE/RYcUyMu9zide6L8dgBjs70Iiu/Dj4BhlhMM46j6frF2fXqK0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746108686; c=relaxed/simple; bh=NJwcQgq8lNADPN94KpNrJletRoM42ftMQBwp63dEwBM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=H64hcMFLPYhNHEwdmpHSnfsCZUKefAgTbM2ScFNMWwDVF5yG64LsvZu6ktpdsW+G9Q2V9mjS9TvaLUt6BGz2UwqlOrPyP9eORRmH0BLu83msZDNpX5lHPRijr9OT4k1CPJyU+oveHn0PBZZMfIUpSoJSxd9Nbzil/dS8qaAir/g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ZTfYQPYr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ZTfYQPYr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73BF0C4CEE3; Thu, 1 May 2025 14:11:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1746108685; bh=NJwcQgq8lNADPN94KpNrJletRoM42ftMQBwp63dEwBM=; h=From:To:Cc:Subject:Date:Reply-to:From; b=ZTfYQPYrQo4oqhmpyy2twpFv9gDYhcSKp4PU8+xk2AqTVUpJwMTtky/LKFt+q50z/ x57iYpQHszNbHDu3DPHxndAiyxD+9w32OuveZz2T8tj0BvY2auENhGeb6tnHT1Ard9 wh4VV3DGCmsqxtLbsFnomZn0iT9oWrPQiGafLYsQ= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2022-49781: perf/x86/amd: Fix crash due to race between amd_pmu_enable_all, perf NMI and throttling Date: Thu, 1 May 2025 16:09:31 +0200 Message-ID: <2025050119-CVE-2022-49781-4e5e@gregkh> X-Mailer: git-send-email 2.49.0 Precedence: bulk X-Mailing-List: linux-cve-announce@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reply-to: , X-Developer-Signature: v=1; a=openpgp-sha256; l=3548; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=ingOatwHRpmYGsfKxTZXST7PmhnOI2mI+g9bnYM3dig=; b=owGbwMvMwCRo6H6F97bub03G02pJDBnCDf13klWN3MxLysK3mAVP9EsIYjUQdPg7hf9eS0n0k io/y+COWBYGQSYGWTFFli/beI7urzik6GVoexpmDisTyBAGLk4BmIjgJoYFp2etsFF4GJzGe/Xf O6OdC41zZIwUGOaKlz+bEHg2SPfO1BSZP++qvrQ8EfMBAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit From: Greg Kroah-Hartman Description =========== In the Linux kernel, the following vulnerability has been resolved: perf/x86/amd: Fix crash due to race between amd_pmu_enable_all, perf NMI and throttling amd_pmu_enable_all() does: if (!test_bit(idx, cpuc->active_mask)) continue; amd_pmu_enable_event(cpuc->events[idx]); A perf NMI of another event can come between these two steps. Perf NMI handler internally disables and enables _all_ events, including the one which nmi-intercepted amd_pmu_enable_all() was in process of enabling. If that unintentionally enabled event has very low sampling period and causes immediate successive NMI, causing the event to be throttled, cpuc->events[idx] and cpuc->active_mask gets cleared by x86_pmu_stop(). This will result in amd_pmu_enable_event() getting called with event=NULL when amd_pmu_enable_all() resumes after handling the NMIs. This causes a kernel crash: BUG: kernel NULL pointer dereference, address: 0000000000000198 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page [...] Call Trace: amd_pmu_enable_all+0x68/0xb0 ctx_resched+0xd9/0x150 event_function+0xb8/0x130 ? hrtimer_start_range_ns+0x141/0x4a0 ? perf_duration_warn+0x30/0x30 remote_function+0x4d/0x60 __flush_smp_call_function_queue+0xc4/0x500 flush_smp_call_function_queue+0x11d/0x1b0 do_idle+0x18f/0x2d0 cpu_startup_entry+0x19/0x20 start_secondary+0x121/0x160 secondary_startup_64_no_verify+0xe5/0xeb amd_pmu_disable_all()/amd_pmu_enable_all() calls inside perf NMI handler were recently added as part of BRS enablement but I'm not sure whether we really need them. We can just disable BRS in the beginning and enable it back while returning from NMI. This will solve the issue by not enabling those events whose active_masks are set but are not yet enabled in hw pmu. The Linux kernel CVE team has assigned CVE-2022-49781 to this issue. Affected and fixed versions =========================== Issue introduced in 5.19 with commit ada543459cab7f653dcacdaba4011a8bb19c627c and fixed in 6.0.10 with commit fd5e454b856ed86b090336e269695d9908609b71 Issue introduced in 5.19 with commit ada543459cab7f653dcacdaba4011a8bb19c627c and fixed in 6.1 with commit baa014b9543c8e5e94f5d15b66abfe60750b8284 Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community. Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at https://cve.org/CVERecord/?id=CVE-2022-49781 will be updated if fixes are backported, please check that for the most up to date information about this issue. Affected files ============== The file(s) affected by this issue are: arch/x86/events/amd/core.c Mitigation ========== The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits: https://git.kernel.org/stable/c/fd5e454b856ed86b090336e269695d9908609b71 https://git.kernel.org/stable/c/baa014b9543c8e5e94f5d15b66abfe60750b8284