From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9861A606DBD1 for ; Wed, 2 Dec 2026 02:40:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=n3sD861t Received: by kanga.kvack.org (Postfix) id 91DD26B061D; Tue, 1 Dec 2026 21:39:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8CED96B061F; Tue, 1 Dec 2026 21:39:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7BE016B0620; Tue, 1 Dec 2026 21:39:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2A7296B061D for ; Tue, 1 Dec 2026 21:39:42 -0500 (EST) Received: from smtpin02.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9001A1A0183 for ; Wed, 2 Dec 2026 02:39:41 +0000 (UTC) X-FDA: 85497487362.02.74A765B Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by imf20.hostedemail.com (Postfix) with ESMTP id D9D711C0007 for ; Wed, 2 Dec 2026 02:39:39 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20260707 header.b=n3sD861t; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of 36oQPawoKCJE4E29F12E9819916z.x97638FI-775Gvx5.9C1@flex--jthoughton.bounces.google.com designates 209.85.214.197 as permitted sender) smtp.mailfrom=36oQPawoKCJE4E29F12E9819916z.x97638FI-775Gvx5.9C1@flex--jthoughton.bounces.google.com ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796179180; b=G37OO75A5kwr6RHgz38XxcDJi0nkjqhRrVlmCOpPUquMIxFj5V9iISoqF/B1AFJVBULek4 UkZ/HMhyqrlSfCgE0zKaRU8UE1RYily7tPRpLWZpwPHlFbvaDGNgK0v5l44ftSXuR7bE2N wRafIy9rvH0kEeWBt8WNa+Zy3ZH52Fc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796179180; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=noHP8aN68sunvxfqocXFOD0nEi7082hmsuoyid6KhcI=; b=ARyDyzPLWxZSQnMvPvHEIgCphMQcMzMRsh3Adfea0YHolqnAdPUKSg2I+Cx1FGn2LFYQ1v hl/w6esx/aC/39SzuxXA/ojSPva1nNyo29caVTmQ1cmBtqU5bSaZaxAejhYG1fgkRM8rrQ YrLY7BbT+mlxY5Tm2iCkxdkClm+0mto= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20260707 header.b=n3sD861t; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of 36oQPawoKCJE4E29F12E9819916z.x97638FI-775Gvx5.9C1@flex--jthoughton.bounces.google.com designates 209.85.214.197 as permitted sender) smtp.mailfrom=36oQPawoKCJE4E29F12E9819916z.x97638FI-775Gvx5.9C1@flex--jthoughton.bounces.google.com Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2f040056fd0so69147975ad.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=kvack.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=n3sD861tHE+1rAKY/4PND7Xg0TsCwSNyqGJQTfD8XLLtjIr9yr6YL4OaBQFOaUjjHg Meram8fpbbrbwsSStvHW842rc6PDend71EIX41sP450TOsPyWDPPI5J4ulIkxoSz/eId RswNDLi2wzRcz+AVQemGicWvRdFemD0GpUvqS5M+NIAx/xdIzQsJ3+YutC75Shmk/T6X zKvWK9EeQR6etsQHGaP3v16BBVTFtEQtDc2S8JlR/Eh2T0Ly/bEErSEAp+J7sLQOvgSz nLx6Gf/7/sgpdCAaOOPbAm0jF3lTY2lyGfc2uXFKYiS54AhIyxxToHrscI+ZVmwFceMU 0ucQ== 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=R3KHSfgWzhU7VfXJpo0hnzkW1sy+zc/XO5rYNjvoJ+8qx2it2Y3UjYbwzSU1L7CAuz n4xL5bOkOkmvwyh+cFYtBnLzd9AuZ4VLI51V9cQxRKveTVzhEQO2eYtGdHJ4CCJSL38h 685eF2QTOdLIR53i0Yp58xf0ZiiOAFD62g1qkt8Cuvd+n8OujxlIsyT1yC8VwMeT1S4o 6aYtVarAivMf8F7rHk/N1Y4Uf8LYK/10r6YUdNOaN7eUhxHMQEQN/dEQXoPgLVVq3enG 07ZLzaH32glChDhlIzH1vMpXgfU8lPZ33KhqMWYgTzNm/jfDrpVJ3R2JpgYhGCAG+GVE iGzw== X-Forwarded-Encrypted: i=1; AL+hErFI7a2O9eQubfakz0natjg6b+08fcPnw4zzerB+uNUj9MzffGln0WsTugw849eSOeB12b6aFnZObA==@kvack.org X-Gm-Message-State: APuU4Z/1SFA/5ldC7K6PGMR4gXPcc/Imx/+v2YI9c2hPG2JFOz3npQiH TDOvxrZGFxDI7ac8M0tlMuwIewmH3wFn7dh+SysAyGBRu0WX0wpAaKFwixWCs6t2/cjTE2QYihB h/Bpt0skk4aV2rGLKuRcB4A== 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 Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: txg4emwe4uh5whh8phnpyn8zatgwb4d4 X-Rspamd-Server: rspam03 X-Rspam-User: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=4.0.1 X-Rspamd-Queue-Id: D9D711C0007 X-HE-Tag: 1796179179-955513 X-HE-Meta: U2FsdGVkX1+ab5lWnLYUN2yI4VWO+1UYTXrDjz1MXo0N98MLDeiHTgFGuRSpfHgqWiC0wOY58cqSDdpURUmlmZDhj3Da6N+NS4VJckJnEB5uKIyPRdM6z735BzNFkvtjF+wTwUvpAPeJ42SwAUWs4+XZWcodfEH/LyEGcuiM2VeiY2zNcxeJF1M2/9J/iIDrWJcGI1U6r9wK30gT0om6yFUhPuERmreTkAD3GokjyVf1Aibo+FVaedpUYmMMNRCgDv1vAnYADbz2fPrNPRPg3i/krhKbGYAB5jKvK60tvXIffKedytZK+elneXej2Xb8ikMvXSfr8GfzfSrfUOZvguUbZue12RfKCSeo7OCnXF76k3BMPbM/EnFBfrQ6F/ZOydw37Tcaxw/MS6KVnRe5r2bILaBoXePhiaggwhdp35dOx5HJT1H/oG1T2kc9jrp88kKx14Idl6A6UjjFxEbofPw68UFWMTAcrV1zYCDXdYVX56OjxgF8VwBKTSyKgldAwfGhfKB3IlGGb1dMr9ci000/Y0QYnQg1fEzxvg+KjTmhfEY0smzNTrpl5Bdk+gUkpd6m8kjXdWcvs+ojQLjWKH5/gAM0xdIIo+jwxUbuHP7aTSNC4P4z3WPfjISBQedSlm3Q8FIj9O+BQS0HjxwQPt/sFcdeX7kRNZsbFqHxRIH4sB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ub78p9t1KO94WWqVfcgZxhy4aqu0uuOqLNjF5lRG586ipNX8JZcP/zMY24JX8nnNXV7m/mW90PCtMCg== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: 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