From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796244029; b=e6yzoDAJ0/pt/1qys+BSSnyXuuJQHiJXyBzcVP5qw+FXxJbtJmvJVSEh+cdiVgT3R+p4 aG5/NDoL+BLkpxvbOBzq3gv1UXKEC6QwXE4uR87plPBMQVda8A3K2mNPTvb+6iSX9nDef l3hYJvsSJh9TfzwfUrwD9X9f7sV0dzy4jmWy4GIPbSOFR5P670jlsQ9fxdxzNqAkJVuob KZdBAg2XbxO2AqOF0AIfqK/4DinwNT5YDILX7oTUlxcjvoLwn5HVp8r8QcCXojlQF3Pu0 oTXQ4eXCCTMQbdhl2TUU3RGSMzAtxr7e9coO7CPTfw3R5xnzb4m6YTyRI4zF0s7yuyQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796244029; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=4mGmG2DeDUu57Y6mNZWwI4QWYm5vYK4KpffhD88sF3s=; b=e3LKuhzuN2IB+puP70UjyZBGD9NXQQYp1ZbSVkwNRqqKY9O0Hp/VmfNS7Pcuyy0e3gZb v2Eia5RDHHiQRANTLSaFtprzvP0k31zDyKzr80RrYlhK75KINeNrJWnClC14z9vsmClS7 iynyGFUajE+zOu3kMSPRMJGZyqXP7zUfR4gvFQ4M56ZnXZLwD+GCDncorPFFP2iBKobs8 UPu9EnJts9X+r9JyJqndnl0Snozb/HLv+M+OI747d5OwXpdJLyOLnGq851nES7MqVtOxw C0ssuBzZjMMdlua0xy6Ahu7a3T5nezM5viR4dDihEEa6QgPiKsLjuBuwi2OuOGyWD/A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=Ve43Fw7C; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E697606A322; Wed, 2 Dec 2026 20:40:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=Ve43Fw7C Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0CC5C1F0089A; Wed, 2 Dec 2026 20:40:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796244028; bh=4mGmG2DeDUu57Y6mNZWwI4QWYm5vYK4KpffhD88sF3s=; h=Date:To:From:In-Reply-To:References:Subject; b=Ve43Fw7CObV0/Senx0Kxzu+r7GKkF5hAe3u8ugvZ7LzP5EYnF8FdqfaS5Mn99tl7N hcI13K19NQb0rOLncp4gRyMvOvkKa7VtJW6SU7CDKOS/Acz43nEMFNt2G/I1djmiEC DoSOvSOQGV9fHtQRLoLllFSjCr1Bww2ak2/J7PDc= Date: Wed, 02 Dec 2026 12:40:27 -0800 To: mm-commits@vger.kernel.org,stable@vger.kernel.org,rostedt@goodmis.org, mingo@kernel.org,mhiramat@kernel.org,liam@infradead.org,david@kernel.org, daniel@iogearbox.net,ast@kernel.org,andrii@kernel.org,jthoughton@google.com, akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261201211926.3463573-1-jthoughton@google.com> References: <20261201211926.3463573-1-jthoughton@google.com> Subject: + mm-maccess-check-nmi_uaccess_okay-in-user-nofault-helpers.patch added to mm-new branch Message-Id: <20261202204028.0CC5C1F0089A@smtp.kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: mm/maccess: check nmi_uaccess_okay() in user nofault helpers has been added to the -mm mm-new branch. Its filename is mm-maccess-check-nmi_uaccess_okay-in-user-nofault-helpers.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-maccess-check-nmi_uaccess_okay-in-user-nofault-helpers.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: James Houghton Subject: mm/maccess: check nmi_uaccess_okay() in user nofault helpers Date: Tue, 01 Dec 2026 21:19:26 +0000 Unlike copy_from_user_nofault(), which checks nmi_uaccess_okay() before accessing user memory, copy_to_user_nofault(), strncpy_from_user_nofault(), and strnlen_user_nofault() do not. On x86, nmi_uaccess_okay() verifies that cpu_tlbstate.loaded_mm matches current->mm. Even when current->mm is non-NULL, the active CR3 can point to a different address space in several windows: - during context_switch() between switch_mm_irqs_off() and switch_to(), - during kthread_use_mm() between assigning tsk->mm and completing switch_mm_irqs_off(), and - while a temporary mm (such as text_poke_mm or efi_mm) is loaded via use_temporary_mm(). When an NMI, kprobe, tracepoint, or BPF tracing program invokes strncpy_from_user_nofault() or strnlen_user_nofault() (for example via bpf_probe_read_user_str() or fetch_store_string_user()) during one of these windows, the access proceeds against the wrong page tables. While bpf_probe_write_user() already checks nmi_uaccess_okay() itself, copy_to_user_nofault() is exported and should provide the same guarantee as the rest of the user nofault helpers. Check nmi_uaccess_okay() in copy_to_user_nofault(), strncpy_from_user_nofault(), and strnlen_user_nofault(), failing with -EFAULT (or 0 for strnlen_user_nofault()) if the loaded mm does not match current->mm. Link: https://patch.msgid.link/20261201211926.3463573-1-jthoughton@google.com Fixes: 3d7081822f7f ("uaccess: Add non-pagefault user-space read functions") Fixes: 1d1585ca0f48 ("uaccess: Add non-pagefault user-space write function") Signed-off-by: James Houghton Signed-off-by: Andrew Morton Reported-by: Sashiko Closes: https://sashiko.dev/bug/linux-5fcfa8c4-b00c-4ee4-95c6-4b24ec497bca Acked-by: David Hildenbrand (Arm) Acked-by: Alexei Starovoitov Cc: Liam R. Howlett Cc: Steven Rostedt Cc: Masami Hiramatsu Cc: Ingo Molnar Cc: Andrii Nakryiko Cc: Daniel Borkmann Cc: mm/maccess.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/mm/maccess.c~mm-maccess-check-nmi_uaccess_okay-in-user-nofault-helpers +++ a/mm/maccess.c @@ -150,6 +150,9 @@ long copy_to_user_nofault(void __user *d { long ret = -EFAULT; + if (!nmi_uaccess_okay()) + return ret; + if (access_ok(dst, size)) { pagefault_disable(); ret = __copy_to_user_inatomic(dst, src, size); @@ -188,6 +191,9 @@ long strncpy_from_user_nofault(char *dst if (unlikely(count <= 0)) return 0; + if (!nmi_uaccess_okay()) + return -EFAULT; + pagefault_disable(); ret = strncpy_from_user(dst, unsafe_addr, count); pagefault_enable(); @@ -222,6 +228,9 @@ long strnlen_user_nofault(const void __u { int ret; + if (!nmi_uaccess_okay()) + return 0; + pagefault_disable(); ret = strnlen_user(unsafe_addr, count); pagefault_enable(); _ Patches currently in -mm which might be from jthoughton@google.com are hugetlb-dont-restore-vmemmap-of-non-hvoed-folios-on-bulk-restore-error.patch mm-maccess-check-nmi_uaccess_okay-in-user-nofault-helpers.patch