From patchwork Fri Oct 13 11:18:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 152504 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1815174vqb; Fri, 13 Oct 2023 04:18:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGPeBpHnko2zGb8yjydzfno5XbmNy/uALX5Us6+J1ZT+5QMdJp0eThjQn8+O0bdhxjL3/Ds X-Received: by 2002:a17:90b:3a8c:b0:27d:4d4d:3b19 with SMTP id om12-20020a17090b3a8c00b0027d4d4d3b19mr223464pjb.0.1697195937396; Fri, 13 Oct 2023 04:18:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697195937; cv=none; d=google.com; s=arc-20160816; b=vVP3UTZBX2CxSPbKyjxpJXWYzHXuXqpeL/c8URJvyqleCizia1zw6PKB3hD5C5rGLn LtE2BxNKgyJfelrueKGe0VjbmTfsSmo/uTfZvs22ia1LuJEjX+V2A+nKnensYwvpNczE L/iQ1Dqiz03z845xItIySMdDeT2q36sWB41J3wUnbWTefa9eX3SH0WWRLRq+pxGnzoB4 TZjL0mD3d5G+RL8ERMuo+GijciWyPQda2qhAnYZs/7/lUAhWQO9OaOj5FJR83casR+78 zoAYivRmz9k6JZKalS8jXJBvdPpkFCZt20z4u/nNrfHIxr7vXfqnf9c9jmbte0XC+lvJ 6AlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=ihpIi2zGpV5iO/jJMKvvrWvIgzFRX85SMyep/niyOVw=; fh=rgFuo364X/bMod36etsfjmew4T/qgY2GNOeHFq2LY2k=; b=qID+jH+rvgPabIqV3pNo9+ue/23eLHfMXPs+C+CYElZBgnT2ybV6I87Va1N0I/87fP WK6gio1N/wW2Xt51anx9cM7IxWmJuvwP+WWbT7NTIbDSTczmzcHh2HUu3sYrJAEGbiW6 fL4YOMKiQ/VfzKU7AtPzR4e6kW6Sy8sXgOPt7+msb3sAnEaLKSXL5dHk0APxrhUVJ+Q4 n4wfQkcRYC19G8iqQXdoyaEMXgNNd/UxUhovfFo5XS34241GP2wPtsb6WQAKdjnb6epY ve/4Sj6wHThYCLCCPHNVWnfHicKBT9GqD1Vt/jDbrK2v6/LtML+ztBXmETHKj0VgIEqn dmeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=VveKxmNq; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id p20-20020a17090b011400b00277387bc11dsi4282905pjz.188.2023.10.13.04.18.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 04:18:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=VveKxmNq; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 3F14B8217A4F; Fri, 13 Oct 2023 04:18:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231167AbjJMLSh (ORCPT + 19 others); Fri, 13 Oct 2023 07:18:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231124AbjJMLSd (ORCPT ); Fri, 13 Oct 2023 07:18:33 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFA43C0; Fri, 13 Oct 2023 04:18:29 -0700 (PDT) Date: Fri, 13 Oct 2023 11:18:27 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697195907; h=from:from:sender:sender:reply-to: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ihpIi2zGpV5iO/jJMKvvrWvIgzFRX85SMyep/niyOVw=; b=VveKxmNqOx7pw67Y8bqrI1W0+budg++VYzA6N/TVK1zRbilqaVLpaQRDUCG+CZ/DST9fwt 1T/2QW5pmt0FdYVtSu8OuGNnVY25UR9oRbBVMAWIkDonAAmDCB0lDyCOvVsMTSEYZ18+H5 RtYydfb7Ti7ydrDqHG8+EGVClvJ4CIqjs/jDzSbOALLhoRCmyTpGpfW7P27swMmH7U9u3X oV9Ahehk+cKsurYoEdAOrA3xqvWUbaKmZs+l0uq2tOBDWnMU/VjNI+rPS1ipMffA1/3QXa U4Dw7Eg83a3VWRc/M7E/GiT8ccAR1g1biPajS3h0b+mtF8SD0Wd5it6fY7Br2g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697195907; h=from:from:sender:sender:reply-to: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ihpIi2zGpV5iO/jJMKvvrWvIgzFRX85SMyep/niyOVw=; b=Q5fTleJKNiHeF1s0R7vK/nO0PDS6X07j7xhaUw56bYEBmZW9c26wwnDJVFUb7js4jlzOe6 7ZUf7F/8o9+ZNKBQ== From: "tip-bot2 for Brian Gerst" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/entry] x86/entry/64: Use TASK_SIZE_MAX for canonical RIP test Cc: Brian Gerst , Ingo Molnar , Andy Lutomirski , Borislav Petkov , Denys Vlasenko , "H. Peter Anvin" , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , Josh Poimboeuf , Uros Bizjak , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231011224351.130935-3-brgerst@gmail.com> References: <20231011224351.130935-3-brgerst@gmail.com> MIME-Version: 1.0 Message-ID: <169719590716.3135.10309736631158969894.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 13 Oct 2023 04:18:55 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779500860287471718 X-GMAIL-MSGID: 1779638927625828037 The following commit has been merged into the x86/entry branch of tip: Commit-ID: 58978b44df7276f7c75a2c6aad6c201421cd4daa Gitweb: https://git.kernel.org/tip/58978b44df7276f7c75a2c6aad6c201421cd4daa Author: Brian Gerst AuthorDate: Wed, 11 Oct 2023 18:43:50 -04:00 Committer: Ingo Molnar CommitterDate: Fri, 13 Oct 2023 13:05:28 +02:00 x86/entry/64: Use TASK_SIZE_MAX for canonical RIP test Using shifts to determine if an address is canonical is difficult for the compiler to optimize when the virtual address width is variable (LA57 feature) without using inline assembly. Instead, compare RIP against TASK_SIZE_MAX. The only user executable address outside of that range is the deprecated vsyscall page, which can fall back to using IRET. Signed-off-by: Brian Gerst Signed-off-by: Ingo Molnar Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Josh Poimboeuf Cc: Uros Bizjak Link: https://lore.kernel.org/r/20231011224351.130935-3-brgerst@gmail.com --- arch/x86/entry/common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c index 9021465..4c7154d 100644 --- a/arch/x86/entry/common.c +++ b/arch/x86/entry/common.c @@ -110,10 +110,10 @@ __visible noinstr bool do_syscall_64(struct pt_regs *regs, int nr) * in kernel space. This essentially lets the user take over * the kernel, since userspace controls RSP. * - * Change top bits to match the most significant bit (47th or 56th bit - * depending on paging mode) in the address. + * TASK_SIZE_MAX covers all user-accessible addresses other than + * the deprecated vsyscall page. */ - if (unlikely(!__is_canonical_address(regs->ip, __VIRTUAL_MASK_SHIFT + 1))) + if (unlikely(regs->ip >= TASK_SIZE_MAX)) return false; /*