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 C58A82CA6 for ; Wed, 28 Aug 2024 07:11:59 +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=1724829119; cv=none; b=jF2uSagvgHqLLUVWXYgXQTIAtsaMYPiN6LOkmGx3MKVUo4hFpWNDcAox4x9g+QsX6Rg6w7O4txTQGedRr84IHIe9uL4g0DeHBNCZqtc+7yAgeEUFduIc3ZgcHUd5eRYnXcWq7tsXDcJ4x1sfi3iNGge5itMePDhx3JnjbmH5Ebs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724829119; c=relaxed/simple; bh=/0eUINn38cv3xONQpSSJ+7aADEW/Sxc6L5NWJ3ShfuI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=pZOQHh/k4LTqHsY3BfvLnZxSrkkIa5HxSlKf00Hbqau9c9lezl/t0t8FC8N+z31C3jN9QJL/0bl9X+Il8gPc2c4xF30K+79I6+ntFkjh14W9qCx0Ew+eUUBT1vpingCxmPvju1K7c+wbiSpsH3s8ANqTCvc2qbsmlp6uqkycvjM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=p/bTOec6; 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="p/bTOec6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C56FAC4FDF8; Wed, 28 Aug 2024 07:11:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1724829119; bh=/0eUINn38cv3xONQpSSJ+7aADEW/Sxc6L5NWJ3ShfuI=; h=From:To:Cc:Subject:Date:Reply-to:From; b=p/bTOec66JkfvDK4qDTw5NYuxWLBXcMy5xkQFGIp0TRYYKwuLXKL9DOxXsfBaXfdc 2pBtVtl6DSZ5lRJX7Ps3eQIyBLhA3/YDDmgReYR2nVWemmWGC8zUrOQemw9FX9geQP O0KCgF/n9hOxmTbnW5DjS6ch53dtpQuQwQ7UYSZw= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2024-44943: mm: gup: stop abusing try_grab_folio Date: Wed, 28 Aug 2024 09:11:53 +0200 Message-ID: <2024082853-CVE-2024-44943-234f@gregkh> X-Mailer: git-send-email 2.46.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=4790; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=/0eUINn38cv3xONQpSSJ+7aADEW/Sxc6L5NWJ3ShfuI=; b=owGbwMvMwCRo6H6F97bub03G02pJDGnnzu7cwfvm7fmfMsf88zeEP2O3edi1fSOvH2/2I8k3D 4R2eTzW6IhlYRBkYpAVU2T5so3n6P6KQ4pehranYeawMoEMYeDiFICJqExjmCu4Y5dDw6L59yal lvlsTLn1euXbb28Y5pmkn+OdXbBTvKhWJIbb9qNC9qejrwE= 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: mm: gup: stop abusing try_grab_folio A kernel warning was reported when pinning folio in CMA memory when launching SEV virtual machine. The splat looks like: [ 464.325306] WARNING: CPU: 13 PID: 6734 at mm/gup.c:1313 __get_user_pages+0x423/0x520 [ 464.325464] CPU: 13 PID: 6734 Comm: qemu-kvm Kdump: loaded Not tainted 6.6.33+ #6 [ 464.325477] RIP: 0010:__get_user_pages+0x423/0x520 [ 464.325515] Call Trace: [ 464.325520] [ 464.325523] ? __get_user_pages+0x423/0x520 [ 464.325528] ? __warn+0x81/0x130 [ 464.325536] ? __get_user_pages+0x423/0x520 [ 464.325541] ? report_bug+0x171/0x1a0 [ 464.325549] ? handle_bug+0x3c/0x70 [ 464.325554] ? exc_invalid_op+0x17/0x70 [ 464.325558] ? asm_exc_invalid_op+0x1a/0x20 [ 464.325567] ? __get_user_pages+0x423/0x520 [ 464.325575] __gup_longterm_locked+0x212/0x7a0 [ 464.325583] internal_get_user_pages_fast+0xfb/0x190 [ 464.325590] pin_user_pages_fast+0x47/0x60 [ 464.325598] sev_pin_memory+0xca/0x170 [kvm_amd] [ 464.325616] sev_mem_enc_register_region+0x81/0x130 [kvm_amd] Per the analysis done by yangge, when starting the SEV virtual machine, it will call pin_user_pages_fast(..., FOLL_LONGTERM, ...) to pin the memory. But the page is in CMA area, so fast GUP will fail then fallback to the slow path due to the longterm pinnalbe check in try_grab_folio(). The slow path will try to pin the pages then migrate them out of CMA area. But the slow path also uses try_grab_folio() to pin the page, it will also fail due to the same check then the above warning is triggered. In addition, the try_grab_folio() is supposed to be used in fast path and it elevates folio refcount by using add ref unless zero. We are guaranteed to have at least one stable reference in slow path, so the simple atomic add could be used. The performance difference should be trivial, but the misuse may be confusing and misleading. Redefined try_grab_folio() to try_grab_folio_fast(), and try_grab_page() to try_grab_folio(), and use them in the proper paths. This solves both the abuse and the kernel warning. The proper naming makes their usecase more clear and should prevent from abusing in the future. peterx said: : The user will see the pin fails, for gpu-slow it further triggers the WARN : right below that failure (as in the original report): : : folio = try_grab_folio(page, page_increm - 1, : foll_flags); : if (WARN_ON_ONCE(!folio)) { <------------------------ here : /* : * Release the 1st page ref if the : * folio is problematic, fail hard. : */ : gup_put_folio(page_folio(page), 1, : foll_flags); : ret = -EFAULT; : goto out; : } [1] https://lore.kernel.org/linux-mm/1719478388-31917-1-git-send-email-yangge1116@126.com/ [shy828301@gmail.com: fix implicit declaration of function try_grab_folio_fast] Link: https://lkml.kernel.org/r/CAHbLzkowMSso-4Nufc9hcMehQsK9PNz3OSu-+eniU-2Mm-xjhA@mail.gmail.com The Linux kernel CVE team has assigned CVE-2024-44943 to this issue. Affected and fixed versions =========================== Issue introduced in 6.6 with commit 57edfcfd3419 and fixed in 6.6.47 with commit 26273f5f4cf6 Issue introduced in 6.6 with commit 57edfcfd3419 and fixed in 6.10 with commit f442fa614137 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-44943 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: mm/gup.c mm/huge_memory.c mm/internal.h 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/26273f5f4cf68b29414e403837093408a9c98e1f https://git.kernel.org/stable/c/f442fa6141379a20b48ae3efabee827a3d260787