From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.72 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793051575; b=Ll5BkjXj96aMmTLnna7mc1yBXbGt6gVaeZRaGeSGta4y9VJGeQaJtkcuhVXUX2ESxZwE Q6JjNjfiJjvoTnVTdnPy5Pj35PzsLlNR47UkYzsuCLSjNQx5m7QEzcFrioNprMzK23zlD k8VX5Z7bVwwK/+RoClNgVJB2Y9AyCifpDxqXOXQn+W6UL49TnyV0gJhJhgEuSRnKK2uaf uehO7KFWpa2CCFNjg3MoIfuXMiwEfrliz/Eq+V2dNY8sAjUNFPgZ8I0b8+Fs0u7913EXy YmR5dyiPvitxpkRuBSYyOG1TzaPw8cl/HidWEo0fdPE2P9Kl/d8+hXXmQgn2sN0VAAQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793051575; 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=UPD1DyegWTB9pcC/MXMtMDXG2VZzMQeq5nacp4T1bXw=; b=CjCou1WQmmnWxF/to6+05IOm/GlniVJB14/aWKlhME0lQTXABxks+dTG/OvRbWxV0dCG n3VAheiAbEPGu2Yl2qKQhOkEU2c1woKxI0v2px2GHhHHGwEf6MeVjc/jloEERrBO3xjy5 riUAui71b8Z84+y15+zZHwY/GcJQT5t0SyxBbLUjjRvtqMEB6qcP8OxBGAJB8XPBko5ZG nHSRSuBtsdJVsoCdkWmCV+Y4fHhB36BQSgm4WBX690C6vz8doCtk5XjB2PqIhFGPoaVrC YdvS8DjJxagSav0+Lqp3VNxDQhNLd/pm4HRTCoErprdDiV7G0vSEPy6OKLe8iiAxPwQ== 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=20251104 header.b="rIaWZp/G"; arc=none smtp.remote-ip=209.85.216.72 Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (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 A285960A6F54 for ; Mon, 26 Oct 2026 21:52:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A285960A6F54 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, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20251104 header.b=rIaWZp/G Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-3ab7f1efe5dso5902353a91.1 for ; Mon, 26 Oct 2026 14:52:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1793051574; x=1793656374; 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=UPD1DyegWTB9pcC/MXMtMDXG2VZzMQeq5nacp4T1bXw=; b=rIaWZp/GdR9oaew/m3Hzd8eSd5saoP8GWO0K4K0joO8XQTv842j2gsBeHsxwEdM/8M MFM6vhduv3Y3n3hCqiAUqsnfRPKP9yOwLSHx/clGiyqH9Rxk0fMKXZZ7stPFt1zjCupR xRNu/7MegW08r0ydYWSIUj+FAUa3Ae6wfRzfeoO5pFfoBcMeRGz13T6mBB5UdlXqWjMq KF0ceJ1w9rr7iREcUm2HrRNiOXTB+r76yUWxKyQJbGshWQiGe6+nr3XF10eZqmjVMTie XjqLxoc2jQjq3WGmj9HfzvPA3b7EhbSB0eKWlpooXrtzhqxcQ9G3H1+HZnwFZsc4Q9d0 dwdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793051574; x=1793656374; 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=UPD1DyegWTB9pcC/MXMtMDXG2VZzMQeq5nacp4T1bXw=; b=1cyBTt2wJwYHFtJslOrgy6OPmcV8cQCTEHakQ2XoRRrM1uizBS0fatzFhk1pnA8HtB wAid8dAETXKjE3EkK2lhcuML+DGZcGxOdi8k/g1x313nqv/3kJonLduSTTJmtnGdBr/m sORPSoty/OhwR9PmykvZxkfnvHDjzMXnsF+Dr4R13hPbwUUzq25oRcrBe6b6KcnWT4M2 P/+HFKQAxDW6XczkFsip6t7TjdVWu0d62Pkcj40XOtHa+zimjhF/ZxjT8eJbm3+XZOZ2 /CE5bGWjft7j94CoPfd0WYlNxEOmRv/mU+0mxDvC/YH7sY/WKSXNs1wkshTDtKzDBjuf pYFw== X-Forwarded-Encrypted: i=1; AKwUvBy07WL8g7jMVSI49RUoplhaEco/3VcaD7u4yEczqmTrbBsQKRKq5Ppwduvbn1pHFCttqDgUyjtAkg==@vger.kernel.org X-Gm-Message-State: AFq9FYIpoZdRa5N7eVNAJ8d/yDTVtmJgJcoEzbX3N1x/L8y9tpov+bLd hLJ7CGIFrpOcQaavV3ReSRpI9WMELGxMMTfSSUbq3QjaUSR4o7/pq8KhqQMTItBfHXx7gIVglOi fpVvmraVMgfQzCdWWCmrJlg== X-Received: from pjyp7.prod.google.com ([2002:a17:90a:e707:b0:3ab:c373:bf62]) (user=jthoughton job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3e4d:b0:3ac:403d:6232 with SMTP id 98e67ed59e1d1-3adeb120167mr6870324a91.55.1793051573802; Mon, 26 Oct 2026 14:52:53 -0700 (PDT) Date: Mon, 26 Oct 2026 21:52:23 +0000 In-Reply-To: <20261026215226.3713941-1-jthoughton@google.com> X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261026215226.3713941-1-jthoughton@google.com> X-Mailer: git-send-email 2.56.0.307.g5fe7bd680c-goog Message-ID: <20261026215226.3713941-8-jthoughton@google.com> Subject: [RFC PATCH 07/10] uaccess: Fail user nofault helpers quietly when current->mm is NULL From: James Houghton To: Andrew Morton , Alexander Viro Cc: Thomas Gleixner , Peter Zijlstra , Kees Cook , Arnd Bergmann , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Sean Christopherson , Paolo Bonzini , Jim Mattson , Jens Axboe , Pavel Begunkov , "James E.J. Bottomley" , "Martin K. Petersen" , David Sterba , Chris Mason , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Josh Poimboeuf , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, kvm@vger.kernel.org, io-uring@vger.kernel.org, linux-scsi@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-kernel@vger.kernel.org, James Houghton Content-Type: text/plain; charset="UTF-8" The user nofault helpers (copy_{from,to}_user_nofault(), strncpy_from_user_nofault() and strnlen_user_nofault()) are meant to be callable from any context, e.g. from BPF programs, kprobes or perf, which may run on behalf of a kernel thread or of a task that has already gone through exit_mm(). In such a context, there is no user memory to access, and the right answer is simply to fail. Since the previous commit, the uaccess helpers they use warn when current->mm is NULL, e.g. bpf_probe_read_user_str() from a BPF program attached to a function called by a kernel thread would now trip the WARN_ON_ONCE() in strncpy_from_user(). Check for a NULL current->mm up front in these helpers, and fail without warning and without attempting the access. On x86, copy_from_user_nofault() was already refusing such accesses, as nmi_uaccess_okay() returns false when current->mm is not the loaded mm. For the same reason, make copy_to_user_iter_nofault() use should_fail_usercopy() directly, leaving the NULL mm check to copy_to_user_nofault(). Signed-off-by: James Houghton --- lib/iov_iter.c | 2 +- mm/maccess.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 3d6ecb50d778..21e2ccf1e8f2 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -33,7 +33,7 @@ size_t copy_to_user_iter_nofault(void __user *iter_to, size_t progress, { ssize_t res; - if (uaccess_should_fail()) + if (should_fail_usercopy()) return len; from += progress; diff --git a/mm/maccess.c b/mm/maccess.c index 486559d68858..678bb6165b39 100644 --- a/mm/maccess.c +++ b/mm/maccess.c @@ -121,6 +121,14 @@ long copy_from_user_nofault(void *dst, const void __user *src, size_t size) { long ret = -EFAULT; + /* + * The user nofault helpers may be called from any context, including + * from tasks that have no user memory to access (e.g. kernel threads). + * Fail quietly instead of tripping the warning in the uaccess helpers. + */ + if (!current->mm) + return ret; + if (!__access_ok(src, size)) return ret; @@ -150,6 +158,9 @@ long copy_to_user_nofault(void __user *dst, const void *src, size_t size) { long ret = -EFAULT; + if (!current->mm) + return ret; + if (access_ok(dst, size)) { pagefault_disable(); ret = __copy_to_user_inatomic(dst, src, size); @@ -188,6 +199,9 @@ long strncpy_from_user_nofault(char *dst, const void __user *unsafe_addr, if (unlikely(count <= 0)) return 0; + if (!current->mm) + return -EFAULT; + pagefault_disable(); ret = strncpy_from_user(dst, unsafe_addr, count); pagefault_enable(); @@ -222,6 +236,9 @@ long strnlen_user_nofault(const void __user *unsafe_addr, long count) { int ret; + if (!current->mm) + return 0; + pagefault_disable(); ret = strnlen_user(unsafe_addr, count); pagefault_enable(); -- 2.56.0.307.g5fe7bd680c-goog