Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796179180; b=FE24dB1LrAS0gYtf7YARrbwoGtT/pH2ci8vkRdXrpSwrOcg+RivZ6Zsj/xi7xpqtnN7F 4clwyL0Cz00xRmzuyHTGoynd+yk+FtQbVR/yKN/lGlVOg8nmqV9E66cV3TmbsPUxfOPMR G3R7Og5uzIxpvN/LW3NPtpYkF78h/IhcG8vH80m1QJuoo8vVP+Vu/VS1AO6lzoWijBLgk Qp3UA8NfWckkVc7KZY2/t9bNBnpjUhC5gdiD4O9AnHC59v7ghUo03//wCCrr/OZuiiXbZ t72kjkIfgXlzHZJczQ5oCFKPWgjNm5IbRyL8QmnYxFSlQFGdQX3eSgACdNe42AGD0Bg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796179180; 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=CO1I5Mhz5OGWubGzlf9pUix0xBuRV0IR316Czoo1vQ/BePZFPmBOhzICtP9JbY/VrZ4V O0x2BtuuEjJftXQIG+bECJ5D+EApHYLWlibvPeaiiQp1TAbve0hwT2XdvmtVMusFvlLaU fK81UBh4+nnV1EozPyB0lEmAFFnLaS4tl8x/JQAk6uwgJUsUwduj7TtqGRa0b0xXB52lv oMaZsAWRL3uFf2shOCe+zi+MHhETe1NjwLUFpQeD9yTIgJGvK0WjvyNaV2VjxStl1kXEw oinprakZI5prj95oVyeZc/L9pqsJqN9kK3tsp7hnKAlsZVDo3cWYF5fQIa2sWsbhgJw== 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.200 Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (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 8163860A2622 for ; Wed, 2 Dec 2026 02:39:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8163860A2622 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-f200.google.com with SMTP id d9443c01a7336-2f0381f07a0so128990765ad.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=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=bARfIjSlOfT1FSpe+LeZ3//tw0QkwR9Og1xT5vd5zIaCqRx5eLvQWsNqPKDdzBJEt/ g4vLKEKKiQogU2iK2pilYM3P3QmJqG34sg2Ma7xB2v+ADARxuHTZq3f8wZ0styc41vM7 lFDg7fRAIm9NLjLYN+QyutqlIpP8XS4AmWBrewO2leIk32RVgC6AnEz5QHH32NMnbyG1 ip5ugVkCE1rwSH7mbJViS8PGbcIfFdN3Lj4LU/aewhpkmJKiYtMOeF9knuzZK7yTzh6z FsrLkcZzYBOpehgYZ/jDDXF6mhXsCqvI0KRm1gOm75Hw1ceSGavJp+KUBs5iompBwVa3 JdWQ== X-Forwarded-Encrypted: i=1; AL+hErHT2atRJtxKYV6HJ/B4Jiisw3rEpm6nOJMr6jAikYOZcHcDfMAR2ZQtEDrqHLgOJspNUSE=@vger.kernel.org X-Gm-Message-State: APuU4Z8OBOu4k9mxLmYZ2X6VRDqlLB9oUCdnc7ZjsM07+RTRzqaWBot/ Ak3vDQeCMluJgihKlDkqjmCBcMOjTlv32e1KVMpbGHRjKgY5xqBMy8E8CEuZBG7pu2t6G62ex7g UP26SCV45e1UMD0r4uvOc/g== 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: bpf@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