From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 6C7B2606A327 for ; Wed, 2 Dec 2026 02:39:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=VOSJOAA/; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=DPEawewM DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Unsubscribe-Post:List-Owner; bh=xk4l0uLXAGo30+fzfcJTrTHDrQ5nASu9Vtr11UT59PI=; b=VOSJOAA//MIhPpBd8686FotGI/ 1j0bQFUzJKGM5093xWCDCDFtUl7tzL+t54k4zqY+t8upFSPiSAHr1xInObvo88VBX2P0lJBbfc42v GNwsFd48DAaLgehekPgevuNcx70xl+xNornHfwkc2xceQgiiX3UkCqsFKZcIINCGs2O/vDMKfuX0G j5i7bpKVk+DHbtuuNFpeHXPzYBt/iIo3KzbLppV4fQGS2wxukg1iZ5Q8ouEWvdqceG2d9V+qpwMA1 27zMH0LE1wrBZ5qL6JNJRUPjdEksVAr9Few/FaLdliR6R2vopTaIynudV537h8n/dOuCuxi8q+8R4 4HNm4cdQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYaFy-00000009yhM-2u44; Wed, 02 Dec 2026 02:39:42 +0000 Received: from mail-pl1-x646.google.com ([2607:f8b0:4864:20::646]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYaFw-00000009ycS-0bWb for linux-riscv@lists.infradead.org; Wed, 02 Dec 2026 02:39:41 +0000 Received: by mail-pl1-x646.google.com with SMTP id d9443c01a7336-2f040056fd0so69147925ad.1 for ; Tue, 01 Dec 2026 18:39:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796179179; x=1796783979; darn=lists.infradead.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=noHP8aN68sunvxfqocXFOD0nEi7082hmsuoyid6KhcI=; b=DPEawewMAg/RCfVlJydNHh6KWlXAsThecqG05XxDPDc+eBixJ9DOO9aQTyaymr3LSd yrix6KHCPpFjg6Oh3JkWOw3Los3gjCfqdaq0kRYOaELvfjzmuaC9RtNlkNyd55HAvz+h 44urmiZojZ6inUc3C3fsHn51Dg9L7FcuuordjLgevdqmcADjND7aRuPY2LhEA7wsh8vH N820Q0arw+OXnwH8GPUmfvXLr9VopbxRM8+ExGA+feqeMswyVYoAdfQZAk8FM1Hv+HBf A9+Mm9G7tuFyxkjrv1KU4KJ8bHxhmzqOe08neOzdtTBiiKtC6A//o/YiqhX56Q+6wV6z SDcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796179179; x=1796783979; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=noHP8aN68sunvxfqocXFOD0nEi7082hmsuoyid6KhcI=; b=sS97dsJVIdrv00n/1mz/2XoEc8Av3+roZiXquhfJ0SN5mOwzH36HDgDISLxNslmYCS 1wY6jlmJ6bZYvxVP0NrNmEJLPfPmSwdD33igupvagDQ398mi3soJiZ/vV98XGdpCahkA b53lyDSgAX5DeVnYrxI3+i5JPtEx231/BIFxhH4CcjmQPv5xei5jTIGOGhMxfkwga35N 6iABRbAJLmhlg20aKEmNCxSbiNnuOk6ULOYXCqwxr/7JfuguIKenTlBO3i6avPhQHdI6 7qTIIeAxlVu5DgOKtWCIWLK28GXJBBVqP/T4p/ykNKjB7Y36qNjAlK0FRaoiFpveegnW N6ow== X-Forwarded-Encrypted: i=1; AL+hErG17ibjMTFKIlXs04TvqOUiKHgd/RFw6cEgV681xY4Dlg3gO5dx/vAVmhiJQBvbakgxdPJu+eBYij1wtg==@lists.infradead.org X-Gm-Message-State: APuU4Z9PmzQ1CxBw1U42lPWkkU6Ya9+D+ibK3XlICpS5GGKi5NP80RBL lukQL8JfJ575/Y4lWmJa8XguRfEj7GPksoA0YSC5WVg3VMXWKF8KUWBNMZlLTYPoccWXjVG6FlF 15IgE0rkvUlA+fAkYUvPf9A== X-Received: from plco2.prod.google.com ([2002:a17:902:e282:b0:2f1:6daa:948f]) (user=jthoughton job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e5c5:b0:2e9:528c:b9ea with SMTP id d9443c01a7336-2f03f18ed69mr305109975ad.11.1796179178435; Tue, 01 Dec 2026 18:39:38 -0800 (PST) Date: Wed, 2 Dec 2026 02:39:16 +0000 In-Reply-To: <20261202023920.595207-1-jthoughton@google.com> X-Archived-By: Mime-Version: 1.0 References: <20261202023920.595207-1-jthoughton@google.com> X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261202023920.595207-10-jthoughton@google.com> Subject: [PATCH v2 09/12] uaccess: Document that the user nofault helpers need an mm From: James Houghton To: Andrew Morton , Alexander Viro , Arnd Bergmann Cc: Sean Christopherson , Paolo Bonzini , Jim Mattson , Jens Axboe , David Hildenbrand , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , Madhavan Srinivasan , Chris Zankel , Max Filippov , Dinh Nguyen , Simon Schuster , David Sterba , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , KP Singh , Matt Bobrowski , Peter Zijlstra , Arnaldo Carvalho de Melo , Namhyung Kim , Steven Rostedt , Masami Hiramatsu , linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, io-uring@vger.kernel.org, James Houghton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261201_183940_188963_4A2FEBB7 X-CRM114-Status: GOOD ( 16.22 ) X-Spam-Score: -9.5 (---------) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" X-Spam-Status: No, score=-16.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 The callers of the user nofault helpers (copy_{from,to}_user_nofault(), strncpy_from_user_nofault() and strnlen_user_nofault()) that may run in any context now check for a NULL current->mm themselves (see the previous patches). Document that requirement, so that new callers do too. The remaining callers don't need to, as a NULL mm would be a bug there. The next patch makes the uaccess helpers warn in that case. - btrfs's tree search ioctl, and vread_iter() through copy_page_to_iter_nofault(), run in process context. They use the nofault helpers only because they can't take page faults there. - KVM's steal time update already returns early when current->mm is not the VM's mm. - riscv's and powerpc's dumping of user instructions on faults, and the Freescale PCI machine check handler, only access user memory when the faulting context is in user mode. - The architectures' perf_callchain_user(), e.g. powerpc's, which is only called by get_perf_callchain(), and only for a user task with an mm. Signed-off-by: James Houghton --- mm/maccess.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mm/maccess.c b/mm/maccess.c index 486559d68858..b99a1e465b1c 100644 --- a/mm/maccess.c +++ b/mm/maccess.c @@ -116,6 +116,10 @@ long strncpy_from_kernel_nofault(char *dst, const void *unsafe_addr, long count) * * Safely read from user address @src to the buffer at @dst. If a kernel fault * happens, handle that and return -EFAULT. + * + * The current task must have an mm. Callers that may run without one, e.g. + * tracing helpers that can run in kernel threads, must check current->mm + * themselves first. */ long copy_from_user_nofault(void *dst, const void __user *src, size_t size) { @@ -145,6 +149,10 @@ EXPORT_SYMBOL_GPL(copy_from_user_nofault); * * Safely write to address @dst from the buffer at @src. If a kernel fault * happens, handle that and return -EFAULT. + * + * The current task must have an mm. Callers that may run without one, e.g. + * tracing helpers that can run in kernel threads, must check current->mm + * themselves first. */ long copy_to_user_nofault(void __user *dst, const void *src, size_t size) { @@ -179,6 +187,10 @@ EXPORT_SYMBOL_GPL(copy_to_user_nofault); * * If @count is smaller than the length of the string, copies @count-1 bytes, * sets the last byte of @dst buffer to NUL and returns @count. + * + * The current task must have an mm. Callers that may run without one, e.g. + * tracing helpers that can run in kernel threads, must check current->mm + * themselves first. */ long strncpy_from_user_nofault(char *dst, const void __user *unsafe_addr, long count) @@ -217,6 +229,10 @@ long strncpy_from_user_nofault(char *dst, const void __user *unsafe_addr, * * Unlike strnlen_user, this can be used from IRQ handler etc. because * it disables pagefaults. + * + * The current task must have an mm. Callers that may run without one, e.g. + * tracing helpers that can run in kernel threads, must check current->mm + * themselves first. */ long strnlen_user_nofault(const void __user *unsafe_addr, long count) { -- 2.56.1.911.g883d8bcb20-goog _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv