From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3D7A9C433F5 for ; Tue, 15 Feb 2022 10:38:00 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4JycxL2K0jz3cXV for ; Tue, 15 Feb 2022 21:37:58 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=arm.com (client-ip=217.140.110.172; helo=foss.arm.com; envelope-from=mark.rutland@arm.com; receiver=) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lists.ozlabs.org (Postfix) with ESMTP id 4Jycws0Wr8z3bT5 for ; Tue, 15 Feb 2022 21:37:31 +1100 (AEDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 31BC21063; Tue, 15 Feb 2022 02:37:29 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.89.144]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3CBA53F66F; Tue, 15 Feb 2022 02:37:22 -0800 (PST) Date: Tue, 15 Feb 2022 10:37:15 +0000 From: Mark Rutland To: Ard Biesheuvel Subject: Re: [PATCH 08/14] arm64: simplify access_ok() Message-ID: References: <20220214163452.1568807-1-arnd@kernel.org> <20220214163452.1568807-9-arnd@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rich Felker , linux-ia64@vger.kernel.org, Linux-sh list , Peter Zijlstra , "open list:MIPS" , Linux Memory Management List , Guo Ren , "open list:SPARC + UltraSPARC \(sparc/sparc64\)" , "open list:QUALCOMM HEXAGON..." , linux-riscv , Will Deacon , Christoph Hellwig , linux-arch , "open list:S390" , Brian Cain , Helge Deller , X86 ML , Russell King , linux-csky@vger.kernel.org, Ingo Molnar , Geert Uytterhoeven , "open list:SYNOPSYS ARC ARCHITECTURE" , Robin Murphy , "open list:TENSILICA XTENSA PORT \(xtensa\)" , Arnd Bergmann , Heiko Carstens , alpha , linux-um , "open list:LINUX FOR POWERPC \(32-BIT AND 64-BIT\)" , linux-m68k , Openrisc , Greentime Hu , Stafford Horne , Linux ARM , Arnd Bergmann , Michal Simek , Thomas Bogendoerfer , "open list:PARISC ARCHITECTURE" , Nick Hu , Max Filippov , Linux API , Linux Kernel Mailing List , Dinh Nguyen , "Eric W. Biederman" , Richard Weinberger , Andrew Morton , Linus Torvalds , "David S. Miller" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Tue, Feb 15, 2022 at 10:21:16AM +0100, Ard Biesheuvel wrote: > On Tue, 15 Feb 2022 at 10:13, Arnd Bergmann wrote: > > > > On Tue, Feb 15, 2022 at 9:17 AM Ard Biesheuvel wrote: > > > On Mon, 14 Feb 2022 at 17:37, Arnd Bergmann wrote: > > > > From: Arnd Bergmann > > > > > > > > > > With set_fs() out of the picture, wouldn't it be sufficient to check > > > that bit #55 is clear? (the bit that selects between TTBR0 and TTBR1) > > > That would also remove the need to strip the tag from the address. > > > > > > Something like > > > > > > asm goto("tbnz %0, #55, %2 \n" > > > "tbnz %1, #55, %2 \n" > > > :: "r"(addr), "r"(addr + size - 1) :: notok); > > > return 1; > > > notok: > > > return 0; > > > > > > with an additional sanity check on the size which the compiler could > > > eliminate for compile-time constant values. > > > > That should work, but I don't see it as a clear enough advantage to > > have a custom implementation. For the constant-size case, it probably > > isn't better than a compiler-scheduled comparison against a > > constant limit, but it does hurt maintainability when the next person > > wants to change the behavior of access_ok() globally. > > > > arm64 also has this leading up to the range check, and I think we'd no > longer need it: > > if (IS_ENABLED(CONFIG_ARM64_TAGGED_ADDR_ABI) && > (current->flags & PF_KTHREAD || test_thread_flag(TIF_TAGGED_ADDR))) > addr = untagged_addr(addr); > ABI-wise, we aim to *reject* tagged pointers unless the task is using the tagged addr ABI, so we need to retain both the untagging logic and the full pointer check (to actually check the tag bits) unless we relax that ABI decision generally (or go context-switch the TCR_EL1.TBI* bits). Since that has subtle ABI implications, I don't think we should change that within this series. If we *did* relax things, we could just check bit 55 here, and unconditionally clear that in uaccess_mask_ptr(), since LDTR/STTR should fault on kernel memory. On parts with meltdown those might not fault until committed, and so we need masking to avoid speculative access to a kernel pointer, and that requires the prior explciit check. Thanks, Mark.