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=1796179180; b=xx5kS5TEtNAEEo93XPR5HwxSwl2S1YFcIhZ5mjLCIYdQ1eJYy96qTALbhmPH8vK1dvWf bWXeab1hFmGIQKl/4yrPm8qt4LwyZcZfhcFVQHi1Th+UwvslU5sLY+4KZxG5r6cPKJ7xQ j4o4PdhL7IssuyhOPftD0C8e1e23kF+IYBgFdk97m/F2cahCTDBHaF01xHSyIKTKDdg3T M6oM1Lib/Si/dVMYao8uDmEnczJ7k1zaIH9l1JfXtkhXnLokfkQiPJDJdLfGGw234D1Ja td3o0ZAIe4jJwF/L6Aq3xZKITZqLP3chxatabpOwsdEceG2EiZLDrZNH4Nx2WeHQIdw== 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=DzOaZ4MqIs1oWBorGaCGCDeSRL96qc82/GVwnkhQHIm/PbvU/Gt+DZXKdEKjXMmXpu0z cs9qpVrCazccHV3i398IMTDWJxrt9oeuiyjnnuesELSC9wIkONa8EKmpZahSWlstUULuv IWJRsPVQKPXVok1S63Kd16bUoA8ohJyBrzRmJQl72+8YUjtnDDvff8l29aDzb7LHdtYut vaDSSpHxUBLi/Kpy7XtPqa8217Y3KcaM4t4+bA5mPzuxCnJU2fYRm4C9mWKPdcconkt9u 6g6xV8fPJzglzxMhT0Jf6uXs/bXjFYE963tumWGHxc+Ak01A8EFlEEwlHjX/UCsnuRg== 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 7E6D660A2620 for ; Wed, 2 Dec 2026 02:39:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7E6D660A2620 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-2ee2d612733so93639385ad.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=Zdtu2/AcNvRP5UG4GoJY5KrtPlbESzRnhYzNYH3Fnxy452AHPV0eccN/+PLYTDyiAY f/j8j/FfTBIA0KJA/qoFH835Ke2NRoS9ojvtD/K4h8zQRDn9zUJ0YcSdSApM8r9ZLsyN jiPebLqQ8Jzg1NP5rHprxQK30izPI0wbWBrxW3E5hfsmwT5VjowjG0qrCDWZupAY7db+ 4bYwYYD2OYLu94iTHWIZdPISVyx/zQIx5OZ1mugWqgNI2WKcFgAP3Mau0gAcUKNkMG2m kFKTNUdvsXn0gxKnQT0qKAtWC/qeJkFyoIyxc7DNV9qFNELuQZtdkgM6Y+nxJ6W3Omiy 0FOg== X-Forwarded-Encrypted: i=1; AL+hErEksrdp+/XAzaEbUycHDPvMxdP3ycklZyneSMnSnv2agtoSar1ev8n3kNy31VuNqPunWlMSRiFG2+XiaXI=@vger.kernel.org X-Gm-Message-State: APuU4Z9df6PXUQ6rcwZKqr84tcVvdyFa4/vHFVrcnYZF+d0DjtOhqZkz EITCfEB9EEHzpuiF8aW5jPha9+OejRJ5n8dT+lYkKofKv6UUE1Uj+3YxCDeJ27oJMxo5srKE+gG gERldfNuZijPuv6C4unSlXQ== 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-kernel@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