From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796179182; b=AjY1bqBPARUjJT8/MtdLGK6k3JUAHN/8PYIJ0ZQR/90Ugqq/8GC+zfdnKK/TnPr5ZLa/ 1Jtwd4uTo6sWYInyGbAcGlHZUQ8PnsTT9K+L2V26EXYkox3Cc2mMap1desO7VR6iUbfiw By5MsyKjcKWhbXIy0R/z7bYDuMlSeLVk7uNQgaUe1VG7J42lrlBd7zM0l50iY2jxtxYzH Tvo7BiEWN/LUAspKPA5+srl2lPITxSQGQvDfd9giKQ+zhZTqtjKJ+ZRA3Te0xpsHzcC5u ++hoF4bVtFO6baJG6nzspQJe8Gy4xmNB5yuiRm9EOAVYsFbs7eb6mqmnBQfwW3IAZrA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796179182; 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=a+7inMn7vYrz09vu/nTsgINnd+XMgL31rmcpqUu51d8=; b=yucqT75bdw5cuW6sv1GEOaTyR4oywplwguLWso8oUWL12kcQ4WTe5dI+g7WGgHUWpygU TdtmGGvIU45YqiGaoaaAb74wT05BqTBhBYezNArFrQbtEbj/Vfoocqo3bDdT5RwJLtyk0 lNpubbNbEknofj9obwMqIJr/7k27jqhlWUeTgLjUO2xOE79wiWANxGBDvU/O99xAwOwEA aWpHmaSmtdQXYK/afZ3LUSE89O1Q+Kx04q12wAwo95QBa6gr3GEamh3df9XLa1OUQxL3C 8V92YTEy0owXRu6/a6y0i8eughgybFVMeszmF7czmDNUZwpN3I27VXzAqur8DeoQo7Q== 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=CLFsQmcq; arc=none smtp.remote-ip=209.85.214.197 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (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 0AB5C606DBDD for ; Wed, 2 Dec 2026 02:39:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0AB5C606DBDD 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=CLFsQmcq Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2f17b9759d2so1442935ad.3 for ; Tue, 01 Dec 2026 18:39:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796179181; x=1796783981; 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=a+7inMn7vYrz09vu/nTsgINnd+XMgL31rmcpqUu51d8=; b=CLFsQmcqym9pVCA+u6oDkbgI8GZvpb5paJha+asyT/4xAM0sbVSKZydPpube/gwW/h W2z5gwQLHz+kx7/C1skvGRrLnsyDZe994YEJakKOc7nU+mOx3u4HT0Z88napc5nzLLy/ 0e9wklM7+S51GbDtj0jbyFBSC0mqCfpktit4Oi8ko+/1gCL4ntEJf1dBTfZPpRfc/MY/ L80Wu2bCnt1jUPmSW5haHeenQTN9XamMgC838PO/ULwSL+OwdJey/AySy8zjSJyVVqsb s3W9uodW5xjgTE+6eaKZXGingZiLIBJkCz94QdgQooQKU1XNFKsihLub1U9FK69nGSc8 VKmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796179181; x=1796783981; 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=a+7inMn7vYrz09vu/nTsgINnd+XMgL31rmcpqUu51d8=; b=SCFfFJHNIQmq/fEzfCwhsFlR1mC1zlFxqxHcAuTTqhqSyOws/+q+2ShNp8xcW0Rbjb DmEYDiH+ndN35Dd7yJOpJHwfYujuE5QLlS1K9hZcVLps5949JThYK0fc/xmllqCRDj11 KdiL4kHSECUlTBUZw1Gifp8poGsPU1N5oc1L/2ddPdHdRcQRYVWslWbb5OPy/1okMWrL Eil1RvHjxS2qQMYkNNWEGPftKVo3xeM00Fdy/C3Q/QXucKftBgEdUTU4WhQMrEalkk/L 8zr6ahRPCncK3Z3zSbbWVfeNMpFqgIWZEBpUAnbxHDSvFtZb8pyjr6df528Yj3/iiuFQ uxoA== X-Forwarded-Encrypted: i=1; AL+hErHazLCoi8G/8fwfaDwwD3NmITcW0FxQS0yRnrM18fJuC4YYoHtraiyLpLvL/j2CL7+nmSmSZWVFGAuX@vger.kernel.org X-Gm-Message-State: APuU4Z/mksZHEN4PUmouriZTJ0dueHSvxoQsu5BIqeg28uoX/U3bogu6 cGyQ5VTFMh3VJ5UuzWEaW4d5DV9jL3k0ons/Wy6YLy/LWc7vFACrmCuiCVZCw5JiCcoV6VZR+Pa KVMOPwGB9iofBU4cuuYZ0JQ== X-Received: from plbkb11.prod.google.com ([2002:a17:903:338b:b0:2ef:d980:1df7]) (user=jthoughton job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f708:b0:2e9:5772:9ab2 with SMTP id d9443c01a7336-2f03f24bf61mr385032495ad.41.1796179181112; Tue, 01 Dec 2026 18:39:41 -0800 (PST) Date: Wed, 2 Dec 2026 02:39:18 +0000 In-Reply-To: <20261202023920.595207-1-jthoughton@google.com> X-Mailing-List: linux-arch@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-12-jthoughton@google.com> Subject: [PATCH v2 11/12] uaccess: Refuse and warn on masked user accesses without 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" With masked user access (x86-64 and powerpc), mask_user_address() and masked_user_*_access_begin() take the place of access_ok(), so the NULL current->mm check that the previous patch added to access_ok() doesn't cover these paths. Check for a NULL current->mm explicitly in their callers, and fail without attempting the access if there is none: - _inline_copy_from_user(), i.e. copy_from_user(). - The generic copy_from_user_inatomic_nontemporal(). - copy_from_user_iter(), used by the user-backed iov_iters. - strncpy_from_user() and strnlen_user(). - __scoped_user_access_begin(), i.e. scoped_user_*_access() and get_user_inline()/put_user_inline(). - x86's copy_from_user_inatomic_nontemporal() and copy_user_flushcache(). - powerpc's futex operations and copy_from_user_flushcache(). These are all the callers of the masking helpers. In the generic paths, the check is only needed when masking is used, as the other branch calls access_ok(). Signed-off-by: James Houghton --- arch/powerpc/include/asm/futex.h | 4 ++++ arch/powerpc/lib/pmem.c | 2 ++ arch/x86/include/asm/uaccess_64.h | 2 ++ arch/x86/lib/usercopy_64.c | 2 ++ include/linux/uaccess.h | 16 ++++++++++++---- lib/iov_iter.c | 3 +++ lib/strncpy_from_user.c | 3 +++ lib/strnlen_user.c | 3 +++ 8 files changed, 31 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/include/asm/futex.h b/arch/powerpc/include/asm/futex.h index 8cf3b2e97e17..412e74006328 100644 --- a/arch/powerpc/include/asm/futex.h +++ b/arch/powerpc/include/asm/futex.h @@ -33,6 +33,8 @@ static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval, { int oldval = 0, ret; + if (uaccess_without_mm()) + return -EFAULT; uaddr = masked_user_access_begin(uaddr); switch (op) { @@ -68,6 +70,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, int ret = 0; u32 prev; + if (uaccess_without_mm()) + return -EFAULT; uaddr = masked_user_access_begin(uaddr); __asm__ __volatile__ ( diff --git a/arch/powerpc/lib/pmem.c b/arch/powerpc/lib/pmem.c index 0f0f2d851ac6..9a20f12629c0 100644 --- a/arch/powerpc/lib/pmem.c +++ b/arch/powerpc/lib/pmem.c @@ -71,6 +71,8 @@ size_t copy_from_user_flushcache(void *dest, const void __user *src, { unsigned long not_copied, start = (unsigned long) dest; + if (uaccess_without_mm()) + return size; src = mask_user_address(src); not_copied = __copy_from_user(dest, src, size); clean_pmem_range(start, start + size); diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h index 5ef55e67f112..9be404c080a5 100644 --- a/arch/x86/include/asm/uaccess_64.h +++ b/arch/x86/include/asm/uaccess_64.h @@ -158,6 +158,8 @@ copy_from_user_inatomic_nontemporal(void *dst, const void __user *src, { long ret; kasan_check_write(dst, size); + if (uaccess_without_mm()) + return size; src = mask_user_address(src); stac(); ret = copy_to_nontemporal(dst, (__force const void *)src, size); diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c index c47d8cd0e243..df845d00d774 100644 --- a/arch/x86/lib/usercopy_64.c +++ b/arch/x86/lib/usercopy_64.c @@ -48,6 +48,8 @@ size_t copy_user_flushcache(void *dst, const void __user *src, size_t size) unsigned long flushed, dest = (unsigned long) dst; unsigned long rc; + if (uaccess_without_mm()) + return size; src = masked_user_access_begin(src); rc = copy_to_nontemporal(dst, (__force const void *)src, size); user_access_end(); diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h index 6801afaabbc7..ff7132cdda65 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h @@ -170,9 +170,12 @@ _inline_copy_from_user(void *to, const void __user *from, unsigned long n) might_fault(); if (should_fail_usercopy()) goto fail; - if (can_do_masked_user_access()) + if (can_do_masked_user_access()) { + /* Masking doesn't go through access_ok(), so check here. */ + if (uaccess_without_mm()) + goto fail; from = mask_user_address(from); - else { + } else { if (!access_ok(from, n)) goto fail; /* @@ -331,11 +334,14 @@ static inline __must_check unsigned long copy_from_user_inatomic_nontemporal(void *to, const void __user *from, unsigned long n) { - if (can_do_masked_user_access()) + if (can_do_masked_user_access()) { + if (uaccess_without_mm()) + return n; from = mask_user_address(from); - else + } else { if (!access_ok(from, n)) return n; + } return __copy_from_user_inatomic(to, from, n); } @@ -751,6 +757,8 @@ static __always_inline void __scoped_user_rw_access_end(const void *p) typeof(uptr) __retptr; \ \ if (can_do_masked_user_access()) { \ + if (uaccess_without_mm()) \ + goto elbl; \ __retptr = masked_user_##mode##_access_begin(uptr); \ } else { \ __retptr = uptr; \ diff --git a/lib/iov_iter.c b/lib/iov_iter.c index af005ef5cb82..0bce317e2961 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -50,6 +50,9 @@ size_t copy_from_user_iter(void __user *iter_from, size_t progress, if (should_fail_usercopy()) return len; if (can_do_masked_user_access()) { + /* Masking doesn't go through access_ok(), so check here. */ + if (uaccess_without_mm()) + return res; iter_from = mask_user_address(iter_from); } else { if (!access_ok(iter_from, len)) diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c index 5bb752ff7c61..ee8cbd21b3f5 100644 --- a/lib/strncpy_from_user.c +++ b/lib/strncpy_from_user.c @@ -126,6 +126,9 @@ long strncpy_from_user(char *dst, const char __user *src, long count) if (can_do_masked_user_access()) { long retval; + /* Masking doesn't go through access_ok(), so check here. */ + if (uaccess_without_mm()) + return -EFAULT; src = masked_user_read_access_begin(src); retval = do_strncpy_from_user(dst, src, count, count); user_read_access_end(); diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c index 4a6574b67f82..7eebac5a4134 100644 --- a/lib/strnlen_user.c +++ b/lib/strnlen_user.c @@ -99,6 +99,9 @@ long strnlen_user(const char __user *str, long count) if (can_do_masked_user_access()) { long retval; + /* Masking doesn't go through access_ok(), so check here. */ + if (uaccess_without_mm()) + return 0; str = masked_user_read_access_begin(str); retval = do_strnlen_user(str, count, count); user_read_access_end(); -- 2.56.1.911.g883d8bcb20-goog From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06153606A323 for ; Wed, 2 Dec 2026 02:40:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=GCldonwh; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=BEJy7dnP; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=qTmEGN9k DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Unsubscribe-Post:List-Owner; bh=of2dBl5zJehx6hxt8Fbb6OBZ4cramP+xukCaAnd0UzU=; b=GCldonwhaPNZXrykKEystnm2S/ lj23XMLmsBRwFzVCEmP8oqg6a7l13lFJoFOzOkbHKdzyZCyAL67og7hpJ1J8zcJzn4ETZmLekKqH4 NYYSBRlDtbxztd0t1wQsod44NsdAUw11WCJSZnlklwOP7X4fPODdPZunP7OUj3NHyUuhOLBZv6te5 VbJVColBKQKwJ7HgDmbdDwRs5Y+Wls8d7OwK9cmH00hV5M1CQDN5/WkY097Z8QIq9yV9VB4Nz5JaN W/++Ulj1CKd5YLzPuvmCvN1X7RiYLbRlf0DEOAozqQ10OTyFBQxt8SNMl6n5nkREd/lQN18PVkVLG JPRlwNFw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYaG8-00000009yyH-2nBb; Wed, 02 Dec 2026 02:39:52 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYaG4-00000009yqn-42D8 for linux-riscv@bombadil.infradead.org; Wed, 02 Dec 2026 02:39:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: Message-ID:References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=a+7inMn7vYrz09vu/nTsgINnd+XMgL31rmcpqUu51d8=; b=BEJy7dnPW/ZZ4xXKpNphxbg95d 7wruVjkn9b/wuPrZWF5voOpEt5HHHGOKvM5F5d17pUICAQaCDNu0y2i5kiQeEqSSTem/WJh8fhvLA x0C2fWprBnBWTj3NWl4fxl9bUZvzkbZtK0eSjcdFYEzwwey/WVUcKcC28nY6Qbbfs9TVFl9WQnLMM D5/A+VJBf3qrwF4ykaDOHsSpS56Cqwg/2SOEqxUaiF1rFblq3LVOAmzxxAS3NcVCQQpvq/Oad1wap mZvGGUZDZGVT5OdItEh5eJSZwAO3TSShELPr/zBeXdpMdhnHk/+8XT7x3fmgndmghz6SrsgIUYGA6 ze4NFWJw==; Received: from mail-pl1-x646.google.com ([2607:f8b0:4864:20::646]) by casper.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYaFz-00000000XNW-3h3M for linux-riscv@lists.infradead.org; Wed, 02 Dec 2026 02:39:47 +0000 Received: by mail-pl1-x646.google.com with SMTP id d9443c01a7336-2f17b9759d2so1443025ad.3 for ; Tue, 01 Dec 2026 18:39:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796179181; x=1796783981; darn=lists.infradead.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=a+7inMn7vYrz09vu/nTsgINnd+XMgL31rmcpqUu51d8=; b=qTmEGN9kbS7M0iE1m0drCgnq694dKz1im4ckaVja1ABfuGmcMsK3+akq5d4LiOTw73 EWzuajnMBcRlVe8EYVDkeNieGd+Sc98B0JTARIJmw0gRo6cysAKhBPtGBRWxJp4NUnjc aHub8nZq04rRGLzULy/8Imgnrq/QJMfdnCA5LykcP7+8TCHaWlZFIUusy2AAEkDH1avy GoS+pHz1jn/Op99CYTvI5Rfm9Rz7iFuM9D5VXZ7JrsjNrdDBm8pdXXtJVPJIV8vsr8Mj PaME2FRRAkDanontfmyY0URTg0ZiFfHNj/vJag3W9wVAcO2Tr8y3DYW1nTHMx469eq3r jq1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796179181; x=1796783981; 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=a+7inMn7vYrz09vu/nTsgINnd+XMgL31rmcpqUu51d8=; b=d44oRE88n+Bj/bvr+mlwJ3K7n81FPlTcAk2f+qWBmzEYkJ3dzeTqeFgEtiINjBLNQV ludiLRm8t0VFoyBWHRTn3llpMDAlgfuL4GU4XaWn3syK+j+ATrRvT2j0AOs1lVl9dKaO SfGUXVFNlzwdj0ili/VK0O9/kAvIYN5pklQ5ZedxEJxUzFaQAdSXq9KUz+6rP63CIyrT eJDR4m8UDewhDNol8kgBxWBEtq8kvuv5Xz7wkKpb8mPnW1UmYEfIAGL4YtSi1KbML+F/ R4JyRtI4fDV9e6jXshp3hHDDcjsx9NqEXQh1FiH1nNYsf+kaQxOcsD0fmfl3lY2ORKdC 2nQA== X-Forwarded-Encrypted: i=1; AL+hErGVrI2EKBdFxuL7/+GxXtlTffkcQiyM6fG+bpHvTHT1NqHfhVuSir+9wdEtmtTHNF4GSh9uvlXkvz0ZeQ==@lists.infradead.org X-Gm-Message-State: APuU4Z8+nA0hIX+PlNCxCBazyM7EZG6wXNjVq90dWLaBfKJNXLRPdt78 i2QSHAR174Pshy2SpyUwEE29vV1LRIML0ouLvyeWKaA1fKcjpe3OVouTRJ0z7TPxA9KNkJvvVA3 WrMhSYxy25cbgLz6gdDQa+Q== X-Received: from plbkb11.prod.google.com ([2002:a17:903:338b:b0:2ef:d980:1df7]) (user=jthoughton job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f708:b0:2e9:5772:9ab2 with SMTP id d9443c01a7336-2f03f24bf61mr385032495ad.41.1796179181112; Tue, 01 Dec 2026 18:39:41 -0800 (PST) Date: Wed, 2 Dec 2026 02:39:18 +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-12-jthoughton@google.com> Subject: [PATCH v2 11/12] uaccess: Refuse and warn on masked user accesses without 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261202_023944_009849_AE18712F X-CRM114-Status: GOOD ( 19.55 ) X-Spam-Score: -9.5 (---------) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" X-Spam-Status: No, score=-16.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 With masked user access (x86-64 and powerpc), mask_user_address() and masked_user_*_access_begin() take the place of access_ok(), so the NULL current->mm check that the previous patch added to access_ok() doesn't cover these paths. Check for a NULL current->mm explicitly in their callers, and fail without attempting the access if there is none: - _inline_copy_from_user(), i.e. copy_from_user(). - The generic copy_from_user_inatomic_nontemporal(). - copy_from_user_iter(), used by the user-backed iov_iters. - strncpy_from_user() and strnlen_user(). - __scoped_user_access_begin(), i.e. scoped_user_*_access() and get_user_inline()/put_user_inline(). - x86's copy_from_user_inatomic_nontemporal() and copy_user_flushcache(). - powerpc's futex operations and copy_from_user_flushcache(). These are all the callers of the masking helpers. In the generic paths, the check is only needed when masking is used, as the other branch calls access_ok(). Signed-off-by: James Houghton --- arch/powerpc/include/asm/futex.h | 4 ++++ arch/powerpc/lib/pmem.c | 2 ++ arch/x86/include/asm/uaccess_64.h | 2 ++ arch/x86/lib/usercopy_64.c | 2 ++ include/linux/uaccess.h | 16 ++++++++++++---- lib/iov_iter.c | 3 +++ lib/strncpy_from_user.c | 3 +++ lib/strnlen_user.c | 3 +++ 8 files changed, 31 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/include/asm/futex.h b/arch/powerpc/include/asm/futex.h index 8cf3b2e97e17..412e74006328 100644 --- a/arch/powerpc/include/asm/futex.h +++ b/arch/powerpc/include/asm/futex.h @@ -33,6 +33,8 @@ static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval, { int oldval = 0, ret; + if (uaccess_without_mm()) + return -EFAULT; uaddr = masked_user_access_begin(uaddr); switch (op) { @@ -68,6 +70,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, int ret = 0; u32 prev; + if (uaccess_without_mm()) + return -EFAULT; uaddr = masked_user_access_begin(uaddr); __asm__ __volatile__ ( diff --git a/arch/powerpc/lib/pmem.c b/arch/powerpc/lib/pmem.c index 0f0f2d851ac6..9a20f12629c0 100644 --- a/arch/powerpc/lib/pmem.c +++ b/arch/powerpc/lib/pmem.c @@ -71,6 +71,8 @@ size_t copy_from_user_flushcache(void *dest, const void __user *src, { unsigned long not_copied, start = (unsigned long) dest; + if (uaccess_without_mm()) + return size; src = mask_user_address(src); not_copied = __copy_from_user(dest, src, size); clean_pmem_range(start, start + size); diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h index 5ef55e67f112..9be404c080a5 100644 --- a/arch/x86/include/asm/uaccess_64.h +++ b/arch/x86/include/asm/uaccess_64.h @@ -158,6 +158,8 @@ copy_from_user_inatomic_nontemporal(void *dst, const void __user *src, { long ret; kasan_check_write(dst, size); + if (uaccess_without_mm()) + return size; src = mask_user_address(src); stac(); ret = copy_to_nontemporal(dst, (__force const void *)src, size); diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c index c47d8cd0e243..df845d00d774 100644 --- a/arch/x86/lib/usercopy_64.c +++ b/arch/x86/lib/usercopy_64.c @@ -48,6 +48,8 @@ size_t copy_user_flushcache(void *dst, const void __user *src, size_t size) unsigned long flushed, dest = (unsigned long) dst; unsigned long rc; + if (uaccess_without_mm()) + return size; src = masked_user_access_begin(src); rc = copy_to_nontemporal(dst, (__force const void *)src, size); user_access_end(); diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h index 6801afaabbc7..ff7132cdda65 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h @@ -170,9 +170,12 @@ _inline_copy_from_user(void *to, const void __user *from, unsigned long n) might_fault(); if (should_fail_usercopy()) goto fail; - if (can_do_masked_user_access()) + if (can_do_masked_user_access()) { + /* Masking doesn't go through access_ok(), so check here. */ + if (uaccess_without_mm()) + goto fail; from = mask_user_address(from); - else { + } else { if (!access_ok(from, n)) goto fail; /* @@ -331,11 +334,14 @@ static inline __must_check unsigned long copy_from_user_inatomic_nontemporal(void *to, const void __user *from, unsigned long n) { - if (can_do_masked_user_access()) + if (can_do_masked_user_access()) { + if (uaccess_without_mm()) + return n; from = mask_user_address(from); - else + } else { if (!access_ok(from, n)) return n; + } return __copy_from_user_inatomic(to, from, n); } @@ -751,6 +757,8 @@ static __always_inline void __scoped_user_rw_access_end(const void *p) typeof(uptr) __retptr; \ \ if (can_do_masked_user_access()) { \ + if (uaccess_without_mm()) \ + goto elbl; \ __retptr = masked_user_##mode##_access_begin(uptr); \ } else { \ __retptr = uptr; \ diff --git a/lib/iov_iter.c b/lib/iov_iter.c index af005ef5cb82..0bce317e2961 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -50,6 +50,9 @@ size_t copy_from_user_iter(void __user *iter_from, size_t progress, if (should_fail_usercopy()) return len; if (can_do_masked_user_access()) { + /* Masking doesn't go through access_ok(), so check here. */ + if (uaccess_without_mm()) + return res; iter_from = mask_user_address(iter_from); } else { if (!access_ok(iter_from, len)) diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c index 5bb752ff7c61..ee8cbd21b3f5 100644 --- a/lib/strncpy_from_user.c +++ b/lib/strncpy_from_user.c @@ -126,6 +126,9 @@ long strncpy_from_user(char *dst, const char __user *src, long count) if (can_do_masked_user_access()) { long retval; + /* Masking doesn't go through access_ok(), so check here. */ + if (uaccess_without_mm()) + return -EFAULT; src = masked_user_read_access_begin(src); retval = do_strncpy_from_user(dst, src, count, count); user_read_access_end(); diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c index 4a6574b67f82..7eebac5a4134 100644 --- a/lib/strnlen_user.c +++ b/lib/strnlen_user.c @@ -99,6 +99,9 @@ long strnlen_user(const char __user *str, long count) if (can_do_masked_user_access()) { long retval; + /* Masking doesn't go through access_ok(), so check here. */ + if (uaccess_without_mm()) + return 0; str = masked_user_read_access_begin(str); retval = do_strnlen_user(str, count, count); user_read_access_end(); -- 2.56.1.911.g883d8bcb20-goog _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv