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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7AF3C38147 for ; Wed, 18 Jan 2023 15:50:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 357566B0072; Wed, 18 Jan 2023 10:50:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3072C6B0073; Wed, 18 Jan 2023 10:50:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A7F26B0074; Wed, 18 Jan 2023 10:50:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0C2406B0072 for ; Wed, 18 Jan 2023 10:50:18 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id D246A40C57 for ; Wed, 18 Jan 2023 15:50:17 +0000 (UTC) X-FDA: 80368356474.14.13E7B36 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf24.hostedemail.com (Postfix) with ESMTP id 13A65180014 for ; Wed, 18 Jan 2023 15:50:14 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=MoQkuL37; spf=none (imf24.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674057016; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jP8Fr6MlbMMjd8lIYq+Vp79w4vg/s3Wf0pcdTIx4qDE=; b=Mh3d4aERZsLWOptR0iWIyLPMBqK0XlyX/pCnT+LUAx0pyD4NXmeemi4OzyhbigoeAhc5e+ +QhO1nz2zZAthZccIzT2k5/6ZgKkFPG0XQGcloz+ek5vbtDqlMZlaMy9CeN7VNV8isCNpG 59ql8amKkSiTZb9apjD93UvzmJv2bbo= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=MoQkuL37; spf=none (imf24.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674057016; a=rsa-sha256; cv=none; b=TAXNFtf8I6bm7tifyfsxx3MLMg0tZeYtNYGIkZZUUXaZ/LaqqHe5+N8/Jy7v+3Fd7ZgFT9 oEjpQRLT7SgDIvMA6mNKYnPxPWaKGxCZ3KEMC+hC2Rlv2YSJU4MSfpOzeCK6BLWsH0YCeQ kpYklCfH7/6RWw1tGBdA+0WOd5Ec7t4= 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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 13A65180014 X-Stat-Signature: de5tgoh9gwnn9emo377aoqh75eewhf4x X-Rspam-User: X-HE-Tag: 1674057014-712594 X-HE-Meta: U2FsdGVkX189aWsGYjPeyq2Tr8wS46o5N8514ja4YwhoVTXQXUVU6kk/xti+vSBe7zRNSrLeroJ6XL3240RoxJIcua99tfFZhhSh/uMLwilHL6fY+4QrCuXQRJeePdndkXv/AWqcmikhKEvwAefGLHUC82pCfQoniCt6HscwgH59lHgo6NyLBjIockz4nfapQEkW44RLzYqcCPeiIUefCfVddT+roU9RFa6Wsnbk9cIxGluo1D0ZEmwEVVy9NFbu5FuRB4TmK7klxYl9R+JndnH6LOgNCEE40KFI/1mqD01qVBr0EDzFXvD7xuBJr9FevUsVPKWCYGC83+kUMW3aQrD6gDoZTr5njd4GU2ACIqZRlh06gjmta+m/yQhhFYPXRJ//NJ0c/HLaJjCFN6WU5Ick+K/D/rBMC8V7Ti7hm8rNoPt7a8XnXBg2irtHHlOzTPIkQ7LcG304fXSwVrXoZ2x/zggaIjq5WarDNzp//6yjRf/dP2lwnj2sc191z7Hsgk1ElJkNd8CYtRw4jZVIl5NYgzXRs3koGTtYx2v3Xn3itq6uTRmo4JS0IwPbGkP/5SsbmzooQYyN/7qslmJFHskZ3hD/L3DgB3jkJFq6MbVqPIfJBbRTplOV1kmFKo3wsZzuPdJBw2FABsFse5R4fq+CjnCUSHMN+iWjswvXWQWng5VuYyLLVTjhvc7tmjLcIaUXKTh/KhJlQLLOLkNiPmkMzWrxfn+qMoIrAvq+rSqtFNd36q9J8rICumgvEi3GqtVoVTUErDh0sYcpn9C0O03PQrS3dLVapdXzeUrRYl8ZyblNYjFkIpbN91bWAlWImw326UwSbTd9Vb9puTDnkoixHZbRN6sqiXWURlIJt+YVWhcTe9Af8TAZO7T3s3xi/Y3Twm17BmoCdrq2rxwIMwiEFka1Z8FgTg1mH4I3qG5Fbp9IER7Tnek0C68HDsu/Zbg/nZoztTOC4oH5E9m foHKkN3a 6IT3B X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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?