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 91E01170A11 for ; Wed, 18 Jun 2025 11:08:56 +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=1750244936; cv=none; b=U0QWC/TEkAKA28uGkwTzM2sDhjPlnpPLkunD2FK8HLNFyBpAmPmTwdaqptkSSViQ3meLdOi8RYWzmrOmEarWz+ioPz8Xun92ZsXvA1KRDM3qTzZJs6JwgUfJ7zy7N8tvjXMs5xVA9821tOJnfT8h74t28+tcgJWVnYnkH9k7r1s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750244936; c=relaxed/simple; bh=bDjdDM5VieynZFHiR1/DxwfZw5JpW0Rc6AXxjgTNw/k=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Plo4eQ4jx+NFtJmK0cdBze4czc9vJHD4Ekj8XqW/7+64S6EsvOs5iQWTtjri6qlt607RCzIB1/l4Va74DHopR4aSeBX35GLBAtqXMpN/5vAiRAmkb6UuS124zFPpnKjpk7bTn4EyDoSIJworTSKH2Z5BbTHC3LYxDAROViXpfFU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=b5Omzt9n; 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="b5Omzt9n" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 199A1C4CEE7; Wed, 18 Jun 2025 11:08:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750244936; bh=bDjdDM5VieynZFHiR1/DxwfZw5JpW0Rc6AXxjgTNw/k=; h=From:To:Cc:Subject:Date:Reply-to:From; b=b5Omzt9naIKtqmixaVNkSxx8qfCtAyqOJAA1IMi4p/EWIMP01Nu59JeFc2FPxq8x+ pw6OGJa7tDaRlIR6dM5ZBoH+3TBmEFlifD4ttiZIjjAtscU9lYzqItHsaGi6+mx80b K4YplK+xiv7G976g1VPW31PEI2iby3zFT5f3PW8M= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2022-50081: KVM: Unconditionally get a ref to /dev/kvm module when creating a VM Date: Wed, 18 Jun 2025 13:02:26 +0200 Message-ID: <2025061857-CVE-2022-50081-80dc@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=4565; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=hlmkGF/bhwD5RCnmGdF7IobeZ5nmWAFo6M7GLfNPoIQ=; b=owGbwMvMwCRo6H6F97bub03G02pJDBlBczIlzyz468DAGO8056PHVFk+KfXc4k/brIpubI/V2 sIU8+RhRywLgyATg6yYIsuXbTxH91ccUvQytD0NM4eVCWQIAxenAEzkx0uGBQs9C+dv2PeKv4rH oLhhBfsH/udJzQzzk7bJb9T5v3uzwM49829PXyE7fdk7XgA= 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: KVM: Unconditionally get a ref to /dev/kvm module when creating a VM Unconditionally get a reference to the /dev/kvm module when creating a VM instead of using try_get_module(), which will fail if the module is in the process of being forcefully unloaded. The error handling when try_get_module() fails doesn't properly unwind all that has been done, e.g. doesn't call kvm_arch_pre_destroy_vm() and doesn't remove the VM from the global list. Not removing VMs from the global list tends to be fatal, e.g. leads to use-after-free explosions. The obvious alternative would be to add proper unwinding, but the justification for using try_get_module(), "rmmod --wait", is completely bogus as support for "rmmod --wait", i.e. delete_module() without O_NONBLOCK, was removed by commit 3f2b9c9cdf38 ("module: remove rmmod --wait option.") nearly a decade ago. It's still possible for try_get_module() to fail due to the module dying (more like being killed), as the module will be tagged MODULE_STATE_GOING by "rmmod --force", i.e. delete_module(..., O_TRUNC), but playing nice with forced unloading is an exercise in futility and gives a falsea sense of security. Using try_get_module() only prevents acquiring _new_ references, it doesn't magically put the references held by other VMs, and forced unloading doesn't wait, i.e. "rmmod --force" on KVM is all but guaranteed to cause spectacular fireworks; the window where KVM will fail try_get_module() is tiny compared to the window where KVM is building and running the VM with an elevated module refcount. Addressing KVM's inability to play nice with "rmmod --force" is firmly out-of-scope. Forcefully unloading any module taints kernel (for obvious reasons) _and_ requires the kernel to be built with CONFIG_MODULE_FORCE_UNLOAD=y, which is off by default and comes with the amusing disclaimer that it's "mainly for kernel developers and desperate users". In other words, KVM is free to scoff at bug reports due to using "rmmod --force" while VMs may be running. The Linux kernel CVE team has assigned CVE-2022-50081 to this issue. Affected and fixed versions =========================== Issue introduced in 5.15.33 with commit 43637ee17092eef0b97a327bb4355230060431c4 and fixed in 5.15.63 with commit 177bf354200962c6f0de6dd37c86a9bf3b54003a Issue introduced in 5.18 with commit 5f6de5cbebee925a612856fce6f9182bb3eee0db and fixed in 5.19.4 with commit 865e08b77c244eed0b80439320e7e8440f61ebce Issue introduced in 5.18 with commit 5f6de5cbebee925a612856fce6f9182bb3eee0db and fixed in 6.0 with commit 405294f29faee5de8c10cb9d4a90e229c2835279 Issue introduced in 4.9.311 with commit 6e84a56ce3215f078e9a70e309d602a961806aca Issue introduced in 4.14.276 with commit c1dd3547c191dc9724884cbc37432af2df382702 Issue introduced in 4.19.238 with commit c7e4e89455fceb2002269402b9335a185e9db2e6 Issue introduced in 5.4.189 with commit a1c03f11cc3c703fa39691d2dab98a5f5543326c Issue introduced in 5.10.110 with commit eccfee44949d2d8ac9675d5b3f29cacaed5ba6c8 Issue introduced in 5.16.19 with commit 2ec90e21f1c0cd2b71014c96474e003b029c457f Issue introduced in 5.17.2 with commit 9b709d19bb34955de210f1fc2e71d7c9a961f3c1 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-50081 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: virt/kvm/kvm_main.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/177bf354200962c6f0de6dd37c86a9bf3b54003a https://git.kernel.org/stable/c/865e08b77c244eed0b80439320e7e8440f61ebce https://git.kernel.org/stable/c/405294f29faee5de8c10cb9d4a90e229c2835279