Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp107700pxb; Tue, 15 Feb 2022 06:30:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJwLtVe5RLwSmuKchut/Uc5eUBotWaEicxx8y+g6DblGsCE+pNFhJC1EnOuFi01FD/kV/00a X-Received: by 2002:a17:907:96a1:: with SMTP id hd33mr3157935ejc.13.1644935454988; Tue, 15 Feb 2022 06:30:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644935454; cv=none; d=google.com; s=arc-20160816; b=RilJIHMHWUg8b5pm4aVsVt+Whe97h8YlQp0TGzzAIPIEjfNnL9KiD2L5LwyNi/hnyh mGXgQQfFdTQIYDQRuXXUEOj8L2xPxq2O9Y6YL4xYvphgCIfFDphrDnm/IQzAhqUmCqcJ Q/Nc1mnwBYrUpUXqeUVTJmSVkYKD6vhnushAB3DWt+AjqwQwBJ3oaPkH6DN4ZS/3LLKj nDepgdJ2i6OBuyIMgay+HpBXaCKEBCc6/yDHnyXWZBJ2hv2aAHv5k9YukmU2A6oJT2ph DF1uohRZapKJVbYD14Si1nD837I4Haw6k0gJ4MhAC5uJhVf7jdcwspelFe1scENwpvAV S4dA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=dmoZrWMfpUDBkmDzIVgLC4yppY56VGT20o2j9/EtNsE=; b=ZOB4vL9/oEtaVfXjteHJwFO/wLNzERo9vErW5PTwaUECQrqXXZD8fYLn8bgQOQntId BOlGy2GxCjRab1NBtTDpnWtoeLEGY8PdRkSyR6Y93upDegBjEdrxnRO2MRAGufou64zs 2BENps2M3+yUeq1MGbXBlIA+r+goIVdSac5T2MVfrV3eB+KzHpJo6ZoIe+f1w/bBGc/N nEnpZqZNVpKjI77c1tjbkBTPTXiDa+VmmImD5/RUiyMMoGXJizt+Jd1RryZhae/PSHWG 3QzmgJRcg8tGcndLlguRdWwd09qyhks9EwNwoagb90UOD/e0kKoAp0ozzRG+EmPblhJQ z5hQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v25si5838354edq.646.2022.02.15.06.30.28; Tue, 15 Feb 2022 06:30:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236599AbiBOKhn (ORCPT + 99 others); Tue, 15 Feb 2022 05:37:43 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:46170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236575AbiBOKhj (ORCPT ); Tue, 15 Feb 2022 05:37:39 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A720C710C4; Tue, 15 Feb 2022 02:37:29 -0800 (PST) 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 Cc: Arnd Bergmann , Linus Torvalds , Christoph Hellwig , linux-arch , Linux Memory Management List , Linux API , Arnd Bergmann , Linux Kernel Mailing List , Russell King , Will Deacon , Guo Ren , Brian Cain , Geert Uytterhoeven , Michal Simek , Thomas Bogendoerfer , Nick Hu , Greentime Hu , Dinh Nguyen , Stafford Horne , Helge Deller , Michael Ellerman , Peter Zijlstra , Ingo Molnar , Heiko Carstens , Rich Felker , "David S. Miller" , Richard Weinberger , X86 ML , Max Filippov , "Eric W. Biederman" , Andrew Morton , alpha , "open list:SYNOPSYS ARC ARCHITECTURE" , Linux ARM , linux-csky@vger.kernel.org, "open list:QUALCOMM HEXAGON..." , linux-ia64@vger.kernel.org, linux-m68k , "open list:MIPS" , Openrisc , "open list:PARISC ARCHITECTURE" , "open list:LINUX FOR POWERPC (32-BIT AND 64-BIT)" , linux-riscv , "open list:S390" , Linux-sh list , "open list:SPARC + UltraSPARC (sparc/sparc64)" , linux-um , "open list:TENSILICA XTENSA PORT (xtensa)" , Robin Murphy 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-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.