From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.198 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796179179; b=B0bP3En++gkaG/lOI7deHsIDUhF5iElpIP0plUZNT11iFn+bbs37Z3QeNmG3Rf+KyYGJ jxx9CLYndGy+YMztDP0r+yW7XtEvjgCPh+vB7kNsbRBA2Qf2417LURwhJ9lcEKpXmRNpO VYp2KAhTP3ehDHySPtSVf2nFXYJsmsgqqETw7K4dWVeI7zS9WiTmpBThKW1lnXX9upK4h 5L2Xd7dy0ofdnuiK41IXFuzD86zlXEEMEocHYs6aU3hFpX+QPe5xHKdJ5EAH4vW7lnYy5 L+nAakP5TG3edt1u0nP39EQya1HkDkodduEfRwY+HpdXmj7/UzDEk0LXkqbrj82ojFQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796179179; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=noHP8aN68sunvxfqocXFOD0nEi7082hmsuoyid6KhcI=; b=ohZS2mMRKctxcQI32rgnx94uoTnmjdA4V/zPW9EWu2eQ8Kxtmehq6mcLusJ28rU059v2 i6nA3VVDNW1/e4eMEt9wMh/RIOjISzHldempNDqC46PfcjGHg+s9xkm+o32/ISABDMj4Y 3X3cL9tOBpFqA25TAXyz1QpVB+gOn8KP0T+4T9ifL60FMPzQuhJ57BGKW14+KqoqVi7vs gJviHgzi46SUZ2ovKqbmFud/aBSLZX2zFC0LZZglc4Litg8qfBCcdzKDaHHLlhVf8lhWo xNTC4WAlNbWqyDMsinxio4cYH7JvmRiR7obT1l5Eu2+LgwCqgSJkqBqmgiWtOEZ/GnQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=agM3AiMd; arc=none smtp.remote-ip=209.85.214.198 Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E64A60A261E for ; Wed, 2 Dec 2026 02:39:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7E64A60A261E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com 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=agM3AiMd Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-2f022026e60so134552255ad.0 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=vger.kernel.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=agM3AiMdY1xd9Gc4U4h+mk9bEkaCW42K6Y9/n7WmenYxTewin3TwFblRNIB6yRKNCI 6TGX/Ko6JGHqT5wt4F4pVpX1uGBzVjG5GFkc2NFK5HefTqoChNYo808iCddbnLKCu4FF lATACToi+wy9B5Q13FKNjCn9/EJnQX5YiZa4qFpfXDY/YrD1l/qSHgl8e5Kk5dy0QIrZ IGfv0R5l/cYJcrP4pKrZzt2DYTXVBOS7eG9HhsX2lef+T/n1u/DjCs3jSggdlr3KwLsU HSrtPjKKjXjtvuwgX579e7o5SJ2J4UbV2hzrP4fh09FID9LSgNuBsLRFcLIV+wFjnt0c 0UVg== 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=G4o8g0mdIOtHMfiJQJPURcVvGUV0zvHBAVB9AULXkpKWM0eHu0ciq9+KpEwYnQcVK3 EQHdKak1hP9zjhQf0za2I8Cv8XWqimiNdwPYNZ4pZ9C+jBtYBN7CrTIdBKafZmW8DKyV XTZ1LkrxxaYBhkoSYqoARm2USo86IgQ9JyRCOfM7isnjWqO0i5J1gFMEfQ3M7/iAyc9X Y2V+pJQx8SoXwZmU3Ln56dOtf9M9WmzvQHtHs6OGOYsI8bXxr9vRlC1YubwkPAKzaEos ql41EqcwDQsFi+hpAr5YsXrs86paSKW1GcboSDfN0SrcHLGFdsAvWWErgYnlLUthLiJz rPFA== X-Forwarded-Encrypted: i=1; AL+hErGl9w/JWI868ecyfxMLdRAYfrRzOjvAVOFQS7ia0PK0nXE65fSL8abkQJvhgNjrC+qccMFsznqLhpim6Q==@vger.kernel.org X-Gm-Message-State: APuU4Z+gIDOKugkeX831l4Rx0yeq7AQirPoYHMPMJ6UIjGoNBYxyrVo+ +gF2fFMf6INwwewLOxo2/0IsE9ZnSo/6YalMG6VEpc8IvDXTiN1qgU1sFMKzWa9POkfTQe81Bsh 5fJXyaiMVjwkp+80kQezuHQ== 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-Mailing-List: linux-block@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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" 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