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 5799E1F3D49 for ; Fri, 27 Dec 2024 13:54:07 +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=1735307647; cv=none; b=iLQmpdggN5shPaA/iKZZWgA3mw3ih2Gb6iqsjVygPb2+39muNAC+XPckKFK2UkrkPPQglGm8C+ZQlD+JI+dAxvXnBUlvF1xlsPf01d7BOhl57Xp4tChBSOqy5ROGtMgkeBVfzB5zWOCY9SXdmvxBz8eE8QPKmbBhWy5lOtvOFjY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735307647; c=relaxed/simple; bh=FdKiX9BHLq1wNKOj70e6E1fwuuiSflg5H6l75+S8kWM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ixbPAReepfepVadO9f5WAv9EJFhOxQSYju2FqPJtmIxQnvlPFhqwMa0GwA3CHJjCQturqb+va+CU1jJszIzSMchV2wOsbm/RFKhVkg7AAaFYfS7SivKEjGvUuynEX8Yj0+fdyKA99I4U/mBLq2hXQDUcBomwmfVIeOy6h8VCTsM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=kdE7CtBg; 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="kdE7CtBg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8DAEC4CED0; Fri, 27 Dec 2024 13:54:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1735307647; bh=FdKiX9BHLq1wNKOj70e6E1fwuuiSflg5H6l75+S8kWM=; h=From:To:Cc:Subject:Date:Reply-to:From; b=kdE7CtBgVSeLDlY4z1F+kihohoaaxx4vm8HwZtdDpdQ80xJwsndjjGE/+JWTpaDoL lz//7a4ZIB0WLo7pqK9qYGUbmEYLjQ4TMFeqzhMz/d03Otba5EijExj2sNH2lygWD4 +Qm2TqNLzQo1n7mdMs1KoNN18xExOLcLB0OMfcBA= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2024-53195: KVM: arm64: Get rid of userspace_irqchip_in_use Date: Fri, 27 Dec 2024 14:52:41 +0100 Message-ID: <2024122724-CVE-2024-53195-772a@gregkh> X-Mailer: git-send-email 2.47.1 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=4890; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=FdKiX9BHLq1wNKOj70e6E1fwuuiSflg5H6l75+S8kWM=; b=owGbwMvMwCRo6H6F97bub03G02pJDOl5GyVypS14Vgu4Zb61tXvWPtU45k7V8+3vVzw+ktl/t O36XMd9HbEsDIJMDLJiiixftvEc3V9xSNHL0PY0zBxWJpAhDFycAjCRa48Y5pmxyZm5f2k68jnw +OZuFtea6+/s3jLMU/aL3c5zk8nZkYHzsMrHiN6fUr+zAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit Description =========== In the Linux kernel, the following vulnerability has been resolved: KVM: arm64: Get rid of userspace_irqchip_in_use Improper use of userspace_irqchip_in_use led to syzbot hitting the following WARN_ON() in kvm_timer_update_irq(): WARNING: CPU: 0 PID: 3281 at arch/arm64/kvm/arch_timer.c:459 kvm_timer_update_irq+0x21c/0x394 Call trace: kvm_timer_update_irq+0x21c/0x394 arch/arm64/kvm/arch_timer.c:459 kvm_timer_vcpu_reset+0x158/0x684 arch/arm64/kvm/arch_timer.c:968 kvm_reset_vcpu+0x3b4/0x560 arch/arm64/kvm/reset.c:264 kvm_vcpu_set_target arch/arm64/kvm/arm.c:1553 [inline] kvm_arch_vcpu_ioctl_vcpu_init arch/arm64/kvm/arm.c:1573 [inline] kvm_arch_vcpu_ioctl+0x112c/0x1b3c arch/arm64/kvm/arm.c:1695 kvm_vcpu_ioctl+0x4ec/0xf74 virt/kvm/kvm_main.c:4658 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:907 [inline] __se_sys_ioctl fs/ioctl.c:893 [inline] __arm64_sys_ioctl+0x108/0x184 fs/ioctl.c:893 __invoke_syscall arch/arm64/kernel/syscall.c:35 [inline] invoke_syscall+0x78/0x1b8 arch/arm64/kernel/syscall.c:49 el0_svc_common+0xe8/0x1b0 arch/arm64/kernel/syscall.c:132 do_el0_svc+0x40/0x50 arch/arm64/kernel/syscall.c:151 el0_svc+0x54/0x14c arch/arm64/kernel/entry-common.c:712 el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:730 el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:598 The following sequence led to the scenario: - Userspace creates a VM and a vCPU. - The vCPU is initialized with KVM_ARM_VCPU_PMU_V3 during KVM_ARM_VCPU_INIT. - Without any other setup, such as vGIC or vPMU, userspace issues KVM_RUN on the vCPU. Since the vPMU is requested, but not setup, kvm_arm_pmu_v3_enable() fails in kvm_arch_vcpu_run_pid_change(). As a result, KVM_RUN returns after enabling the timer, but before incrementing 'userspace_irqchip_in_use': kvm_arch_vcpu_run_pid_change() ret = kvm_arm_pmu_v3_enable() if (!vcpu->arch.pmu.created) return -EINVAL; if (ret) return ret; [...] if (!irqchip_in_kernel(kvm)) static_branch_inc(&userspace_irqchip_in_use); - Userspace ignores the error and issues KVM_ARM_VCPU_INIT again. Since the timer is already enabled, control moves through the following flow, ultimately hitting the WARN_ON(): kvm_timer_vcpu_reset() if (timer->enabled) kvm_timer_update_irq() if (!userspace_irqchip()) ret = kvm_vgic_inject_irq() ret = vgic_lazy_init() if (unlikely(!vgic_initialized(kvm))) if (kvm->arch.vgic.vgic_model != KVM_DEV_TYPE_ARM_VGIC_V2) return -EBUSY; WARN_ON(ret); Theoretically, since userspace_irqchip_in_use's functionality can be simply replaced by '!irqchip_in_kernel()', get rid of the static key to avoid the mismanagement, which also helps with the syzbot issue. The Linux kernel CVE team has assigned CVE-2024-53195 to this issue. Affected and fixed versions =========================== Fixed in 6.6.64 with commit dd2f9861f27571d47998d71e7516bf7216db0b52 Fixed in 6.11.11 with commit c16e2dba39ff6ae84bb8dc9c8e0fb21d9b2f6f5c Fixed in 6.12.2 with commit fe425d5239a28c21e0c83ee7a8f4cb210d29fdb4 Fixed in 6.13-rc1 with commit 38d7aacca09230fdb98a34194fec2af597e8e20d 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-2024-53195 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/arm64/include/asm/kvm_host.h arch/arm64/kvm/arch_timer.c arch/arm64/kvm/arm.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/dd2f9861f27571d47998d71e7516bf7216db0b52 https://git.kernel.org/stable/c/c16e2dba39ff6ae84bb8dc9c8e0fb21d9b2f6f5c https://git.kernel.org/stable/c/fe425d5239a28c21e0c83ee7a8f4cb210d29fdb4 https://git.kernel.org/stable/c/38d7aacca09230fdb98a34194fec2af597e8e20d