Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp6680574rwb; Wed, 18 Jan 2023 08:07:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXvRLNDuEsn95FXTbOp7+WjWbPQy9MsrkHbJNIeaE6ccGnrUhzt/FLQigFFbXBA3GUIAiPAd X-Received: by 2002:a17:906:4d0a:b0:84d:3e38:2f0c with SMTP id r10-20020a1709064d0a00b0084d3e382f0cmr22083553eju.67.1674058051387; Wed, 18 Jan 2023 08:07:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674058051; cv=none; d=google.com; s=arc-20160816; b=q0kA7PwcCsa2VgZVR4eIon1wwPsQsUn6Na0oxXnHzmMz32I2ajDbegmIAy2Bm6/QHX cN97NEvQkBbptbf1TLWZGPyPvKfqYxsExDT+yHJPToHB57jopHIFU2dtebc8GgU/OzID EQbvfNN0w/44VEC0CsVGpZI4/KgxBKBc9XUrdQc6Lg5X7ObCtT3/dCbQ9oniA00Cy3++ 5miO1aEZxQMJ1r03sw4VnIcMIgnCzWP/6eSdUKRMNMdw0ECanSM6D5eqm7f4I1Q2VevF CYfOtzXYmF495wDjM6LVBfby9zWcMTuAZFRjs8m6yJfP0r+OdCCs9Qq66c87rN0ZqFo5 lHnA== 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:dkim-signature; bh=jP8Fr6MlbMMjd8lIYq+Vp79w4vg/s3Wf0pcdTIx4qDE=; b=IH3pew+N+7ml5qOOjl39BWr1ZS29QGEiOTiPgV8EHZYGVHnbg15z2VocO4AallUuGn AlwhcWtO2Rumne1Ts7V8YqRnfNbiLOUwA2FJafr9xnoVzUuW2I5YJ2S5Uk0kj6N5+Rg1 OsHrg3Zl5EtAz0wZ1Lh7U6/tBZOL7IAeTku/GvDKTsf0/xCDaODpUJT+Kxc7LK3yKX5s PSTMkWXGvDlGcIox+SRivTqOCfwWWrxGl3wjL9k3WHGO5VmWRyxdW53hpSqzmWQGFsal oBXsMcNasusng5sqy61cADDOSXlhB1JiKK42PgbwrLYIyZv+EjINshG3k7lEC6UYacyu a3RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=MoQkuL37; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qa34-20020a17090786a200b0086eddd33abbsi14305751ejc.202.2023.01.18.08.07.20; Wed, 18 Jan 2023 08:07:31 -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; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=MoQkuL37; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230306AbjARPyJ (ORCPT + 45 others); Wed, 18 Jan 2023 10:54:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230380AbjARPxY (ORCPT ); Wed, 18 Jan 2023 10:53:24 -0500 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A63653B1D for ; Wed, 18 Jan 2023 07:50:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=jP8Fr6MlbMMjd8lIYq+Vp79w4vg/s3Wf0pcdTIx4qDE=; b=MoQkuL37B2+b7WYJ1xAEOmL8rN WqVWIVHp/L8/FMWDkPRjcSWDEdbS6e6Pl0Fa9Q33tvk/VZNoO0C1/FSauVwgI5A7cK/xa6id0Sxqf 5Ps78va3nbGyMVH0ppiMGsk2R+emHHe9AE3wFoyXqF1FQxDKikJc25fgwxgaxl28ANaVv6nkdnlvc QkSWyjFuNwg2Blc4d2sAXdWf0bJ4Sp7dbtnFH7KN8Ek5Y/a8WfxxUoi+Xq6G/+COIeLvINHZwjcDa wCF0HEWJ6W1Edxh/bxwUDq9XLv5jYtMqoxnq65RW/lCMuPvlArz4nqfgkHfhbUyID+Yssn5c/TAFL 3HtHax+g==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pIAgu-0002C7-0E; Wed, 18 Jan 2023 15:49:32 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id B864C30006D; Wed, 18 Jan 2023 16:49:57 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 9CBAC20F42661; Wed, 18 Jan 2023 16:49:57 +0100 (CET) Date: Wed, 18 Jan 2023 16:49:57 +0100 From: Peter Zijlstra To: "Kirill A. Shutemov" Cc: Dave Hansen , Andy Lutomirski , x86@kernel.org, Kostya Serebryany , Andrey Ryabinin , Andrey Konovalov , Alexander Potapenko , Taras Madan , Dmitry Vyukov , "H . J . Lu" , Andi Kleen , Rick Edgecombe , Bharata B Rao , Jacob Pan , Ashok Raj , Linus Torvalds , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCHv14 01/17] x86/mm: Rework address range check in get_user() and put_user() Message-ID: References: <20230111123736.20025-1-kirill.shutemov@linux.intel.com> <20230111123736.20025-2-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230111123736.20025-2-kirill.shutemov@linux.intel.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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 Wed, Jan 11, 2023 at 03:37:20PM +0300, Kirill A. Shutemov wrote: > The functions get_user() and put_user() check that the target address > range resides in the user space portion of the virtual address space. > In order to perform this check, the functions compare the end of the > range against TASK_SIZE_MAX. > > For kernels compiled with CONFIG_X86_5LEVEL, this process requires some > additional trickery using ALTERNATIVE, as TASK_SIZE_MAX depends on the > paging mode in use. > > Linus suggested that this check could be simplified for 64-bit kernels. > It is sufficient to check bit 63 of the address to ensure that the range > belongs to user space. Additionally, the use of branches can be avoided > by setting the target address to all ones if bit 63 is set. > > There's no need to check the end of the access range as there's huge > gap between end of userspace range and start of the kernel range. The > gap consists of canonical hole and unused ranges on both kernel and > userspace sides. So far I can follow, however > If an address with bit 63 set is passed down, it will trigger a #GP > exception. _ASM_EXTABLE_UA() complains about this. Replace it with > plain _ASM_EXTABLE() as it is expected behaviour now. here I don't. The new logic basically squishes every kernel address to -1L -- a known unmapped address, but getting that address in {get,put}_user() is still a fail, right? We used to manually branch to bad_get_user when outside TASK_SIZE_MAX, now we rely on #GP. So why silence it?