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 B8AEC6F06A for ; Tue, 16 Sep 2025 13:00:48 +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=1758027648; cv=none; b=nk4HbVbr/Yjc5Wr9S51IkQERSUqBFf2OxjsDEhV6WaqZt5h5bA6l/5pnenY8nh2d5fJ9YpUmux3LhYG+cgVI7ly10SRJxVBSrd8NmhQRGOH1nEY+wlRgRhOh4maa2wCeUF1+P6K5jBZyXD4qC79tsnWZfBUc776s9PasT6mqNbY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758027648; c=relaxed/simple; bh=3CG4dZrsDlFaH4NSdWUU3XbZ+rwqaadJfQ7h1ZOrCe8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=nT6gVZBtbG3BvW4pHIw3MgV65hh7/x/kZnYdqr6QyboeHOqEMNvOKEi5PuJDSkDV2ETl0XWm79tEp6S5nVIjdSsBqh00JZVku4lROHvK5i+fs7EUSbE7zusrPkGlWHkZpSCbdkF7NLT6KlrxyPffPOKwgU0NDPqAxtJHzTymUJM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=v5m2iRwo; 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="v5m2iRwo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4D1FC4CEEB; Tue, 16 Sep 2025 13:00:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1758027648; bh=3CG4dZrsDlFaH4NSdWUU3XbZ+rwqaadJfQ7h1ZOrCe8=; h=From:To:Cc:Subject:Date:Reply-to:From; b=v5m2iRwo7/0TZGPQ+ihFrIeKrQUVnv6hSh9brDVGIJk5UNxHm+X0UnC4IQaRoUGy8 MSG6H3AevwtEcypt+cQHID3XLTdp95kSaZ6WH6E/drj+OXlpuE2UHmov2mYTRkl9nK M6PIUZ0S6a2iQTgZU+4bmKKq9tDMf1B7LrZkRVFU= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2025-39821: perf: Avoid undefined behavior from stopping/starting inactive events Date: Tue, 16 Sep 2025 15:00:27 +0200 Message-ID: <2025091616-CVE-2025-39821-3812@gregkh> X-Mailer: git-send-email 2.51.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=3683; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=1lUwaVayrhIbdUS4UwblAbvfRUDKkTZ3vbVT0gjYg3c=; b=owGbwMvMwCRo6H6F97bub03G02pJDBkn4xP6nm39/ufEl5UmAinrDdhvJ1crFnw+0Le1Y35X+ L3nokVrO2JZGASZGGTFFFm+bOM5ur/ikKKXoe1pmDmsTCBDGLg4BWAi6U0MC7ZxsjN+9VtxaE3t hwl9RtrCmaa5nQwzGWesu26/qehwqKzEedFnFjmPBKYpAAA= 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: Avoid undefined behavior from stopping/starting inactive events Calling pmu->start()/stop() on perf events in PERF_EVENT_STATE_OFF can leave event->hw.idx at -1. When PMU drivers later attempt to use this negative index as a shift exponent in bitwise operations, it leads to UBSAN shift-out-of-bounds reports. The issue is a logical flaw in how event groups handle throttling when some members are intentionally disabled. Based on the analysis and the reproducer provided by Mark Rutland (this issue on both arm64 and x86-64). The scenario unfolds as follows: 1. A group leader event is configured with a very aggressive sampling period (e.g., sample_period = 1). This causes frequent interrupts and triggers the throttling mechanism. 2. A child event in the same group is created in a disabled state (.disabled = 1). This event remains in PERF_EVENT_STATE_OFF. Since it hasn't been scheduled onto the PMU, its event->hw.idx remains initialized at -1. 3. When throttling occurs, perf_event_throttle_group() and later perf_event_unthrottle_group() iterate through all siblings, including the disabled child event. 4. perf_event_throttle()/unthrottle() are called on this inactive child event, which then call event->pmu->start()/stop(). 5. The PMU driver receives the event with hw.idx == -1 and attempts to use it as a shift exponent. e.g., in macros like PMCNTENSET(idx), leading to the UBSAN report. The throttling mechanism attempts to start/stop events that are not actively scheduled on the hardware. Move the state check into perf_event_throttle()/perf_event_unthrottle() so that inactive events are skipped entirely. This ensures only active events with a valid hw.idx are processed, preventing undefined behavior and silencing UBSAN warnings. The corrected check ensures true before proceeding with PMU operations. The problem can be reproduced with the syzkaller reproducer: The Linux kernel CVE team has assigned CVE-2025-39821 to this issue. Affected and fixed versions =========================== Issue introduced in 6.16 with commit 9734e25fbf5ae68eb04234b2cd14a4b36ab89141 and fixed in 6.16.5 with commit d689135aa9c5e4e0eab5a92bbe35dab0c8d6677f Issue introduced in 6.16 with commit 9734e25fbf5ae68eb04234b2cd14a4b36ab89141 and fixed in 6.17-rc3 with commit b64fdd422a85025b5e91ead794db9d3ef970e369 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-2025-39821 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: kernel/events/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/d689135aa9c5e4e0eab5a92bbe35dab0c8d6677f https://git.kernel.org/stable/c/b64fdd422a85025b5e91ead794db9d3ef970e369