From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796179183; b=NlFYmg9Oqa/WNlB7j/ZLcHZcto8oyKEbHpGm8bHNLUX3+c+BTV26fiYObpXYc0lIi0ts eaXrtnTbSGRehMGM8s7L6nnQ25KC3l3MD9X2fpWkHUljfAttG2DexX8TT8GW/Lk8fEoWe HlX24d/CiSO8hY97dhKlGJtu7EoIwH8GzNWfyffv+NYSF2eWGRidJ97grjIsA/1unCnlv QHpevEJxiG7EkwIbYam092iHPCvIwwTBsyKdq8etKpDNIwwHS+MYphuIoE0T2h/wqjMNP ucZyWbVfOgM9nfJJZV5Ej9JfZ7WVZ2OIjIMP4jaB1IdVxEUmzgxmneEPQ22pXWmQ8Kw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796179183; 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=YzwDy+tWxS+4zgdZfjchBFrZz6WSRxFROtgSmfrulws=; b=t+ay4h19GhgxVr0Nj59RHOttfkyGp7MlricxaCwy5kPVQMGNlziyttrLRsLznNLkJSj8 k5VKMXsSwi3XP4rra85KpeUepT5HPMbLoc9tFt3X7bndscGLX/B9ujEu9d1q4XV+PJu0F KzzhIHrKnVR0UPROu//++7aLc9I8KfMEpaQZalRfoIdzf1fLCXggMD2X/t9o+idse/ZyG d2yrP8CeRbltXUArWQT2RI8kuwiBhMcVNdSokkPK84C4TlSYCh5ucSTgjXXhQgF7pz5x6 RjkVk8sKkbO0AJU7mPdahAgXfSI2d0fjs/owm9M9oRmilsA+XCMxxH7lBHyX1RJosiQ== 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=KQkUa8U1; arc=none smtp.remote-ip=209.85.215.200 Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.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 90BCC606E95C for ; Wed, 2 Dec 2026 02:39:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 90BCC606E95C 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=KQkUa8U1 Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-cd652c0385bso9335967a12.2 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=1796179183; x=1796783983; 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=YzwDy+tWxS+4zgdZfjchBFrZz6WSRxFROtgSmfrulws=; b=KQkUa8U1X91JgG+yTvUGMPbgZDNDrqrEKoJAdiM/qYSNWgT73doycy+RM7OFYXz8fg 6Pbd38lXeZOOcwa1Q1Xwa5/ezJ4ISuC6QesUE3lZvmc6WuKojtUvNONevm/Ahs3sqdIe A0YBudE0Iz57+JOEcXdjOr/uHjyX2Q/iYmuUKPzJnlfv2cleS3M2bquXZY4yvQDwlqcA cs7dpTt7bSbcv68hwdLP6/kEUnGxyYLdZP+zutMV+5T4H6nzOqFAUwl9+LU3l4zS54Hv 9X7WoR55cxvGx7Vod3Ntuznv9Pol/bjbpePKVt3RJa1RQK1tJzh8MZwi5WXDARhWJgxj jKMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796179183; x=1796783983; 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=YzwDy+tWxS+4zgdZfjchBFrZz6WSRxFROtgSmfrulws=; b=i+4cPqLYqULV8lBPlkkp+F3NOoNcQoLZfla1p8EwDnvLqERUnjN3Ry660ZZBmpniwX 4CaVISpv0lGfIdz0SDXr99zUELjW4thTxcjcYf1hhrJPplG1l9W+/e00Vp051n6LNPWq QUmIjHdlBTmGM/HODTuUVF7ig7x/AI4lL2L00gr2Y/yU0YIzUThHgvmeM5V9IHa87xXx zOszgzzLvh1JX0noZuW1eRV8Tl1uYKY1EdD/rszlZA2WW69O0QSTdzxl2FpI6N2B2Wz2 WQ8I0OrRwNuMAUERxh/yLnP950f02MaqoFIsTo8hXcEbfGBTOu28oe7YHjvaAXStWDez vyOA== X-Forwarded-Encrypted: i=1; AL+hErE2Fa0CqSmUMo4yJZV0sH95esiIb7AaKh/Nm2Jf7RC797aonO06Aw0IzGYs4y3eLurrgeQ=@vger.kernel.org X-Gm-Message-State: APuU4Z8YH7y1TvmQLWnUUd3H+OyQkmCr91ZN3uY1IJuA4LIMXSyhIxlr Pi+AlDIkfjl14OySzFNovnKYsWSdw4Vsv95H5CJtLS3LzH1dDUpHWCXsU7hVOePUO8+C7fz6xeZ /r6oritehQiCzJoVPVy17hQ== X-Received: from pjbgj2.prod.google.com ([2002:a17:90b:1082:b0:3b4:119b:5835]) (user=jthoughton job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1dc2:b0:3b5:32db:117 with SMTP id 98e67ed59e1d1-3b532db0508mr18734575a91.53.1796179182548; Tue, 01 Dec 2026 18:39:42 -0800 (PST) Date: Wed, 2 Dec 2026 02:39:19 +0000 In-Reply-To: <20261202023920.595207-1-jthoughton@google.com> X-Mailing-List: kvm@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-13-jthoughton@google.com> Subject: [PATCH v2 12/12] uaccess: Refuse and warn on unchecked 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" __copy_{from,to}_user() and __copy_{from,to}_user_inatomic() don't call access_ok(): they rely on the caller having called it earlier. That earlier check may have happened in a different context, e.g. KVM checks a guest's memory slots when they are set up, and then accesses them through __copy_{from,to}_user() from whichever task happens to run the vCPU, or to tear down the VM. So the check in access_ok() doesn't cover these accesses. Add uaccess_should_fail(), which combines the NULL current->mm check with the existing should_fail_usercopy() fault injection, and use it in place of should_fail_usercopy() in __copy_{from,to}_user() and __copy_to_user_inatomic(). __copy_from_user_inatomic() never called should_fail_usercopy(), so only add the NULL mm check there, rather than start injecting failures that some of its callers don't expect, e.g. __wp_page_copy_user() warns if the copy fails twice. arm64's copy_from_user_flushcache() also relies on an earlier access_ok(), so add the check to it as well. Ideally, the remaining users of these unchecked accessors would be converted to the checked ones, which would make these checks unnecessary, but that can be done separately. The callers of copy_from_user_nofault() that may run without an mm check for it first (see "uaccess: Document that the user nofault helpers need an mm"), and the generic user stack unwinding entry points (perf_callchain(), get_perf_callchain() and stack_trace_save_user()) only unwind the user stack of a user task with an mm, so neither is affected by the check in __copy_from_user_inatomic(). Signed-off-by: James Houghton --- arch/arm64/include/asm/uaccess.h | 3 +++ include/linux/uaccess.h | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 6ce7d0fe3bf9..be4d34dfe63f 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -484,6 +484,9 @@ extern unsigned long __must_check __copy_user_flushcache(void *to, const void __ static inline size_t copy_from_user_flushcache(void *dst, const void __user *src, size_t size) { kasan_check_write(dst, size); + /* Like __copy_from_user(), this relies on an earlier access_ok(). */ + if (uaccess_without_mm()) + return size; return __copy_user_flushcache(dst, __uaccess_mask_ptr(src), size); } #endif diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h index ff7132cdda65..dc60acd25617 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h @@ -11,6 +11,15 @@ #include #include +/* + * Return true if a user copy must not be attempted, either because the + * current task has no mm, or because a failure is being injected. + */ +static __always_inline bool uaccess_should_fail(void) +{ + return uaccess_without_mm() || should_fail_usercopy(); +} + #include /* @@ -101,6 +110,8 @@ __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n) { unsigned long res; + if (uaccess_without_mm()) + return n; instrument_copy_from_user_before(to, from, n); check_object_size(to, n, false); res = raw_copy_from_user(to, from, n); @@ -115,7 +126,7 @@ __copy_from_user(void *to, const void __user *from, unsigned long n) might_fault(); instrument_copy_from_user_before(to, from, n); - if (should_fail_usercopy()) + if (uaccess_should_fail()) return n; check_object_size(to, n, false); res = raw_copy_from_user(to, from, n); @@ -139,7 +150,7 @@ __copy_from_user(void *to, const void __user *from, unsigned long n) static __always_inline __must_check unsigned long __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n) { - if (should_fail_usercopy()) + if (uaccess_should_fail()) return n; instrument_copy_to_user(to, from, n); check_object_size(from, n, true); @@ -150,7 +161,7 @@ static __always_inline __must_check unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n) { might_fault(); - if (should_fail_usercopy()) + if (uaccess_should_fail()) return n; instrument_copy_to_user(to, from, n); check_object_size(from, n, true); -- 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 C3CDE606A33A for ; Wed, 2 Dec 2026 02:39:55 +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=rOkmKQb5; 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=HsY1H8hQ 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=g9rLo71YDFn9bdtu4WLxAdET+6GdMlPawqXw4DMpA2s=; b=rOkmKQb5AigJ23+1c+yHEjqWqt coVGAchPCadFvRj2D9AHapKls/utO6WuSwU+KfZ7AwD2xv03xSwuy81wFrhwMtM7kMXwlXritEO38 W5VeV5fCqeHbjSJcKbxW/rMsLULF0LrIQEyuTtkjI5hYJ7M0EHQnM8FydePTptAXebLoiRHeonKIj LWKMFLJx1FBOGo2aT757sOZvZo5YZWr0gFeX7vHblICkvWU3+ggolL8SqXHc7dYPBf1QotJzmLRz4 OjykRlPL8Go4yem1Iy5GGXGpmwnrXnoLrtYB3N4LrBjHaPR2K2Rwb78rG1y/+SYH1px2UtYXa7w85 yTJRjBPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYaG6-00000009yuC-1MFe; Wed, 02 Dec 2026 02:39:51 +0000 Received: from mail-pg1-x545.google.com ([2607:f8b0:4864:20::545]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYaG0-00000009yiG-1gHy for linux-riscv@lists.infradead.org; Wed, 02 Dec 2026 02:39:45 +0000 Received: by mail-pg1-x545.google.com with SMTP id 41be03b00d2f7-cd60e4e8bc3so8690103a12.1 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=1796179183; x=1796783983; 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=YzwDy+tWxS+4zgdZfjchBFrZz6WSRxFROtgSmfrulws=; b=HsY1H8hQ8gmMojc4dbEUI8smEI914IihnTLTM+l9wryFsiYNIItTVtRBOiTGrlf6bR 5d6cLXnf/rlAvoB1C20zlqmJyg+HqYRnbmtMXwbwfw2LJMci+4Z6wiiX0xqSgb9P+WGO o1k2svJTDK12y0Xug8t2lhVYH8MCXW59BOU7UZL6rOPs0DuntLIaaiJIgWNRrTqy7+Th RcV5jwYS1kBiW49pLRXuav9NLueIFUxaKOeBp02QyKyQl5kQQ0pUyz9KYIl8aqfVETyu ZIdCtFNks0IQt1aQ6SsiUVNpop/2Jyz3zU2HAvOKqVFxhMqUC4KvIXSAZUqT43/y6e6I cEQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796179183; x=1796783983; 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=YzwDy+tWxS+4zgdZfjchBFrZz6WSRxFROtgSmfrulws=; b=jel/9CRt9Nipylzt6KQY7RwyWNTrxG+hDRH23fGnu1aISANS0mOPl8bZs8cyLPjXk+ /5eEcmOr06WN9Mo6AatmrlDWfHyv+cd98IsIcVQvu6UOX1zxz0qe0fzn8/ox+QJlX2yJ Tcipn3vP9nxQXqONZxnSXmJGJOACpS7sr3bjqCG2McM6RZz3Vna36FxKJ1N0CsDNO16W MjEOWSuTGqiBChwjCJPkBiY5BfoaiiIyt1KRBJIVltNCnTQ9+cY1EVyVIZe5EfajXS8/ s3uEltFuNVsgO91qRximi8DsTPQORd60QzICj6Lri8HGAGjkTfy8kA9TSPgNblnayPcI JjLg== X-Forwarded-Encrypted: i=1; AL+hErFVpgZv5fgA/KSjBkrGOotN8/BOFQJh4+vS696amo/n5DgIwxbFi41jBbBWbIuKiLs52cnVV8stOftQVQ==@lists.infradead.org X-Gm-Message-State: APuU4Z/7sKaRMsYSi1UjCwSz+V0SrlaoAftpfFzL3iFk7GoKn7ycaVRr ORmkdHm9FTNxK0bdLvNIG+ZQ5SfZr3tsvHDw0wqKwq9SYsTRAU6lwHOKyEC1qbd+kSh3Wa7PGH6 IQefyYgGdvhUPWqYSuLGXwQ== X-Received: from pjbgj2.prod.google.com ([2002:a17:90b:1082:b0:3b4:119b:5835]) (user=jthoughton job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1dc2:b0:3b5:32db:117 with SMTP id 98e67ed59e1d1-3b532db0508mr18734575a91.53.1796179182548; Tue, 01 Dec 2026 18:39:42 -0800 (PST) Date: Wed, 2 Dec 2026 02:39:19 +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-13-jthoughton@google.com> Subject: [PATCH v2 12/12] uaccess: Refuse and warn on unchecked 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-20261201_183944_468861_5A6B0D4A X-CRM114-Status: GOOD ( 22.46 ) 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 __copy_{from,to}_user() and __copy_{from,to}_user_inatomic() don't call access_ok(): they rely on the caller having called it earlier. That earlier check may have happened in a different context, e.g. KVM checks a guest's memory slots when they are set up, and then accesses them through __copy_{from,to}_user() from whichever task happens to run the vCPU, or to tear down the VM. So the check in access_ok() doesn't cover these accesses. Add uaccess_should_fail(), which combines the NULL current->mm check with the existing should_fail_usercopy() fault injection, and use it in place of should_fail_usercopy() in __copy_{from,to}_user() and __copy_to_user_inatomic(). __copy_from_user_inatomic() never called should_fail_usercopy(), so only add the NULL mm check there, rather than start injecting failures that some of its callers don't expect, e.g. __wp_page_copy_user() warns if the copy fails twice. arm64's copy_from_user_flushcache() also relies on an earlier access_ok(), so add the check to it as well. Ideally, the remaining users of these unchecked accessors would be converted to the checked ones, which would make these checks unnecessary, but that can be done separately. The callers of copy_from_user_nofault() that may run without an mm check for it first (see "uaccess: Document that the user nofault helpers need an mm"), and the generic user stack unwinding entry points (perf_callchain(), get_perf_callchain() and stack_trace_save_user()) only unwind the user stack of a user task with an mm, so neither is affected by the check in __copy_from_user_inatomic(). Signed-off-by: James Houghton --- arch/arm64/include/asm/uaccess.h | 3 +++ include/linux/uaccess.h | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 6ce7d0fe3bf9..be4d34dfe63f 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -484,6 +484,9 @@ extern unsigned long __must_check __copy_user_flushcache(void *to, const void __ static inline size_t copy_from_user_flushcache(void *dst, const void __user *src, size_t size) { kasan_check_write(dst, size); + /* Like __copy_from_user(), this relies on an earlier access_ok(). */ + if (uaccess_without_mm()) + return size; return __copy_user_flushcache(dst, __uaccess_mask_ptr(src), size); } #endif diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h index ff7132cdda65..dc60acd25617 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h @@ -11,6 +11,15 @@ #include #include +/* + * Return true if a user copy must not be attempted, either because the + * current task has no mm, or because a failure is being injected. + */ +static __always_inline bool uaccess_should_fail(void) +{ + return uaccess_without_mm() || should_fail_usercopy(); +} + #include /* @@ -101,6 +110,8 @@ __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n) { unsigned long res; + if (uaccess_without_mm()) + return n; instrument_copy_from_user_before(to, from, n); check_object_size(to, n, false); res = raw_copy_from_user(to, from, n); @@ -115,7 +126,7 @@ __copy_from_user(void *to, const void __user *from, unsigned long n) might_fault(); instrument_copy_from_user_before(to, from, n); - if (should_fail_usercopy()) + if (uaccess_should_fail()) return n; check_object_size(to, n, false); res = raw_copy_from_user(to, from, n); @@ -139,7 +150,7 @@ __copy_from_user(void *to, const void __user *from, unsigned long n) static __always_inline __must_check unsigned long __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n) { - if (should_fail_usercopy()) + if (uaccess_should_fail()) return n; instrument_copy_to_user(to, from, n); check_object_size(from, n, true); @@ -150,7 +161,7 @@ static __always_inline __must_check unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n) { might_fault(); - if (should_fail_usercopy()) + if (uaccess_should_fail()) return n; instrument_copy_to_user(to, from, n); check_object_size(from, n, true); -- 2.56.1.911.g883d8bcb20-goog _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv