Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1127589rdg; Wed, 11 Oct 2023 15:44:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFcoFWZ25q3HkMGAHXUpp8rasW7hUYG3C70lhTCay2Ht7uThP3Wj81MtKWDXbRLi34mh5aD X-Received: by 2002:a17:902:e54a:b0:1b5:674d:2aa5 with SMTP id n10-20020a170902e54a00b001b5674d2aa5mr29992714plf.13.1697064278276; Wed, 11 Oct 2023 15:44:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697064278; cv=none; d=google.com; s=arc-20160816; b=FYMg5m+ejkOWNLoXtR3sHqCFdlVuxQkB+Vd47XmKAks1VdZEoEYsoOtTq0iNpdpQKV dutBzZcLtknyOULagxE0DpLSkJOqGg3e8pUu9dVEN9vD7ZmZfN6LFa9lvLRtmAhFD/uO sx3yV3J5yXwqbuZWMcbiDZbx3akCoOnFJwP6YALbN2htOVlSGmfWJ+q7Q9G7DP29Xhtm SRjFFfNNx8Yydp8tC0+mIemES14f7sFrKYEL/9iemIWT8ilUCLty0OEq2Z2Ez0u8y7zU JWvgG94O1uzmfo8bvIFOHk3uy72Vxq8UEWl0VD4a7Ot5r8Jm6A9A/pGA2j3xq/aHMKZZ maSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HZGveJLgwifDwKHvj2/VHQXDCqoTe78KUSxE+lNTdAg=; fh=WGM1QZbt/SlLWUT0E34ZDX9cK40FItT/GbeLHeozOhU=; b=LMom3iDZWcLCL4qoG8TYEsIS814HpaL0WaLU3Df/f8jIYCrf8a2lWsw0FwupOJJ/Nx 0PbAjCImr5DOLtV0DcK9GDcKy74CF7xUrNxHWS5ws3bPXLnZ2mNgWgb856Pf01DT+s0E sGs8L7q1wcyOqkJwla0WsODRq9gW4b6aV4XtjHruizL7v8MUhbWOQRmsYSb71+TjqkPA Q3WYBOAVQ8DUy+QYDtU8aZGrGzAI6yRc2NbgJQ2En4kMazdHYx44TcnCBN91pG6I+XD1 rc/m+D1qtitbol6RY4jWmZytso//zfOmrqFCCxUuUS+LBl4yFN2FgVFSOwIdg8GFnz6p OKzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="awxtAks/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id b1-20020a170902d50100b001c3a05b0b58si802863plg.500.2023.10.11.15.44.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:44:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="awxtAks/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 886AA80A1482; Wed, 11 Oct 2023 15:44:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376558AbjJKWoH (ORCPT + 99 others); Wed, 11 Oct 2023 18:44:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376550AbjJKWn7 (ORCPT ); Wed, 11 Oct 2023 18:43:59 -0400 Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D73E7A9 for ; Wed, 11 Oct 2023 15:43:57 -0700 (PDT) Received: by mail-qv1-xf31.google.com with SMTP id 6a1803df08f44-66d0760cd20so2713416d6.0 for ; Wed, 11 Oct 2023 15:43:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697064236; x=1697669036; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HZGveJLgwifDwKHvj2/VHQXDCqoTe78KUSxE+lNTdAg=; b=awxtAks/9WVVH+7UeadSsBtLZKhKfCMVMsAsRl3L+7hg0BEKvqf0e0lcM1RPdJvM5Y JR316hc6OGz15ouCEDPgwA7i5lq8MkMKBdv5v94NkEpMQSvzgU9eu6AH2WM/HFzFerr3 5KHXna0S1grvnPNdQZ1BLpiEor3mjjbxiGKP4HrCQFCoFn4Am55c/CbT9kjpMlZpRrM2 Xhanru37wXgbAGIZOqbLlBffUsQR8xhcEEj/2EQZvRKpRvHv4c0N39UJMTMiFvXHl06K lJ5K1ojAAWG/f2fMU0/OjSrcsv4H7NmvrDvpknm9tOXT4ICADSgqr/5LUpt+1lP5x8RV cgKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697064236; x=1697669036; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HZGveJLgwifDwKHvj2/VHQXDCqoTe78KUSxE+lNTdAg=; b=T3ccQmZKmzQxvo7DA/iABj37ITHFYRjf2zp5OSwpFy3ZVzPUEi9rphHKRrvT8Je7UQ +5f/AwGIk0x5+7NsBP6sO+QGrzcMUcfAHg+a+MwNFKgSUZS+EFbGqHveXYVi89Ot4pO2 opq9xXQPb7aJmNYA4LoNzIAh1l6bS1QdNla0dfuT6R8MUlkeMtklqKftI8sZM3Er/yzY psAU5GXaorP+c8wAfv/RQTM2i+MgeA6FQ/qJBrhOmn3Rxul972+uOsTBypE5YkcRvu6N v4pPTHFvmt4gou+IjFse8+U/PLDfYfiz4bYRGTW6enLN1eUoOq7r3xtn2zPccUjHySlG oUag== X-Gm-Message-State: AOJu0Yzlj0TvpJ8PcodkIB6ptoddSZiVGo4PTINGNiNsMhvHqd0EbkMp MTk70oaGAFPOmEhJVqi8EzdJRJQuIA== X-Received: by 2002:a05:6214:21ea:b0:66d:1103:3286 with SMTP id p10-20020a05621421ea00b0066d11033286mr2709612qvj.12.1697064236600; Wed, 11 Oct 2023 15:43:56 -0700 (PDT) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id o10-20020a0cf4ca000000b0065b129ec0e8sm6132871qvm.57.2023.10.11.15.43.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:43:56 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Andy Lutomirski , Brian Gerst Subject: [PATCH v3 2/3] x86/entry/64: Use TASK_SIZE_MAX for canonical RIP test Date: Wed, 11 Oct 2023 18:43:50 -0400 Message-ID: <20231011224351.130935-3-brgerst@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231011224351.130935-1-brgerst@gmail.com> References: <20231011224351.130935-1-brgerst@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Wed, 11 Oct 2023 15:44:35 -0700 (PDT) X-Spam-Level: ** 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 --- 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 207149a0a9b3..e3d6f255379f 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 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; /* -- 2.41.0