Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2474610rwd; Fri, 9 Jun 2023 11:45:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6n0066vIdwHbv2zRryCQ4JtFzV3dGMJmDl+dFCamWD7a0ZNiGuv2R1WbtvckRL9QZOwhqR X-Received: by 2002:a17:902:d2c9:b0:1b2:3e9f:69d1 with SMTP id n9-20020a170902d2c900b001b23e9f69d1mr7228371plc.18.1686336330589; Fri, 09 Jun 2023 11:45:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686336330; cv=none; d=google.com; s=arc-20160816; b=Bex4+LbRjTkaPsf3avDdFn0sMOnrBzlnf4Rpa0UjvqdBvG3hG1xAjpTLPExLEHN+dk 6F8zvBxSvmesGuJcPMiLMcrXSdFI/jtx7FR0Nl3VkedCrzLL71ohnQ8qDi0BzVw5zuOq 6rxFfnizD9j0Sa4v8nfnVpSEhI4DC0Dzf6li6QN6vQIyOSPbQDw0YMTdx9iP50a5AkRe 46yiztJIcZ36MUAe/7DSaWTg1sE/iqVIxROfm72nkqGsYrhU5Zvaf+AK2loB9L/Mu/B/ +AE/XAClQ2EoJNTvAhcxPJZyOjLKosiDxr9RlND6LgaqNYRgf6eT3LB09qYfxSV1iLg1 3lRQ== 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=do+fN86CgzLVDY0L8qbbriwTCBlxAfhamcPrCCypCHY=; b=Q67q4mFpw4tHl/6qrf8rRA6U2x7MXc4ZF+kjQ8J+DKQhTiTWOCBrXPRHjbI7ocaYJD wvh8aESlTr81Ipc//2JITdxs9HofvY3knIx5o3e9nq4wInia4crej3adSjWkP+mT8Dps BVuEVvmQzYBVs5urFIyn8iJ9hbsSfe9gX2vKKOEpcskcz2WFCrZnftmLotl3ht7lcPrU RLTIUAAVhB443xweZ6PYm5owyA+edV2Ze2rkvPMoP5gixpN07Hgv8UiuC/o9gAhGdyYI bMJ7NQEsLjQcMPYVw+3Pa6IeGlvK474fxfI/mhWl2cIDV9Iv700i76QcQv/hUTuM77eB 8Myg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ehaSCjjr; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kx13-20020a170902f94d00b001a95b85b070si2888362plb.604.2023.06.09.11.45.18; Fri, 09 Jun 2023 11:45:30 -0700 (PDT) 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=@intel.com header.s=Intel header.b=ehaSCjjr; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231960AbjFIShm (ORCPT + 99 others); Fri, 9 Jun 2023 14:37:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231708AbjFISh1 (ORCPT ); Fri, 9 Jun 2023 14:37:27 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6B7E3C1B for ; Fri, 9 Jun 2023 11:37:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686335834; x=1717871834; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rt9yrRSSQctOLo3XiuDMAeXvCUu9OQR70n+HgxLIsZI=; b=ehaSCjjrMt2sXmmP8ykcWVHJorxI1ZJX9Wg1p4nbV+q3RD0OsBFw9iYD 8I03eGc0YAzEpojQIXFpyLZmeI5zTK/3N883ImZ1+hYuFdITMfWLRXXQi x45+KuIsqWnqISrSBCzmBLOiR6jnjim2fGgS8Xv2d8o6LKI9kWgWEehIM FpoDhfkWL7QaJuNRru8V14fwX2YMmbfRMZ0x5JhDDWN0jf4aT6/hNeQXv l1bTNjUCoTGRifdC2MbQYMG6RIc6F1tqAG5QFexj3ChRWH4mJvI19RIYS YtPRTFFKfoHNMieeQMNPQHdE0t+6bCnDBnfHefOI2g8gz46K89xgq7tCQ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10736"; a="338022183" X-IronPort-AV: E=Sophos;i="6.00,230,1681196400"; d="scan'208";a="338022183" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2023 11:37:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10736"; a="710444066" X-IronPort-AV: E=Sophos;i="6.00,230,1681196400"; d="scan'208";a="710444066" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 09 Jun 2023 11:37:12 -0700 From: Alexander Shishkin To: linux-kernel@vger.kernel.org, x86@kernel.org, Andy Lutomirski , Dave Hansen , Ravi Shankar , Tony Luck , Sohil Mehta Cc: Alexander Shishkin Subject: [PATCH v3 08/12] x86/vsyscall: Add vsyscall emulation for #GP Date: Fri, 9 Jun 2023 21:36:28 +0300 Message-Id: <20230609183632.48706-9-alexander.shishkin@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609183632.48706-1-alexander.shishkin@linux.intel.com> References: <20230609183632.48706-1-alexander.shishkin@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 From: Sohil Mehta The legacy vsyscall page is mapped at a fixed address in the kernel address range 0xffffffffff600000-0xffffffffff601000. Prior to LASS being introduced, a legacy vsyscall page access from userspace would always generate a page fault. The kernel emulates the execute (XONLY) accesses in the page fault handler and returns back to userspace with the appropriate register values. Since LASS intercepts these accesses before the paging structures are traversed it generates a general protection fault instead of a page fault. The #GP fault doesn't provide much information in terms of the error code. So, use the faulting RIP which is preserved in the user registers to emulate the vsyscall access without going through complex instruction decoding. Signed-off-by: Sohil Mehta Signed-off-by: Alexander Shishkin --- arch/x86/entry/vsyscall/vsyscall_64.c | 11 ++++++++++- arch/x86/include/asm/vsyscall.h | 6 ++++++ arch/x86/kernel/traps.c | 4 ++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/arch/x86/entry/vsyscall/vsyscall_64.c b/arch/x86/entry/vsyscall/vsyscall_64.c index dd112e538992..76e1344997d2 100644 --- a/arch/x86/entry/vsyscall/vsyscall_64.c +++ b/arch/x86/entry/vsyscall/vsyscall_64.c @@ -23,7 +23,7 @@ * soon be no new userspace code that will ever use a vsyscall. * * The code in this file emulates vsyscalls when notified of a page - * fault to a vsyscall address. + * fault or a general protection fault to a vsyscall address. */ #include @@ -309,6 +309,15 @@ bool emulate_vsyscall_pf(unsigned long error_code, struct pt_regs *regs, return __emulate_vsyscall(regs, address); } +bool emulate_vsyscall_gp(struct pt_regs *regs) +{ + /* Emulate only if the RIP points to the vsyscall address */ + if (!is_vsyscall_vaddr(regs->ip)) + return false; + + return __emulate_vsyscall(regs, regs->ip); +} + /* * A pseudo VMA to allow ptrace access for the vsyscall page. This only * covers the 64bit vsyscall page now. 32bit has a real VMA now and does diff --git a/arch/x86/include/asm/vsyscall.h b/arch/x86/include/asm/vsyscall.h index 667b280afc1a..7180a849143f 100644 --- a/arch/x86/include/asm/vsyscall.h +++ b/arch/x86/include/asm/vsyscall.h @@ -17,6 +17,7 @@ extern void set_vsyscall_pgtable_user_bits(pgd_t *root); */ extern bool emulate_vsyscall_pf(unsigned long error_code, struct pt_regs *regs, unsigned long address); +extern bool emulate_vsyscall_gp(struct pt_regs *regs); #else static inline void map_vsyscall(void) {} static inline bool emulate_vsyscall_pf(unsigned long error_code, @@ -24,6 +25,11 @@ static inline bool emulate_vsyscall_pf(unsigned long error_code, { return false; } + +static inline bool emulate_vsyscall_gp(struct pt_regs *regs) +{ + return false; +} #endif #endif /* _ASM_X86_VSYSCALL_H */ diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index f3e619ce9fbd..42d13e17e068 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -65,6 +65,7 @@ #include #include #include +#include #ifdef CONFIG_X86_64 #include @@ -753,6 +754,9 @@ DEFINE_IDTENTRY_ERRORCODE(exc_general_protection) if (cpu_feature_enabled(X86_FEATURE_UMIP) && fixup_umip_exception(regs)) goto exit; + if (cpu_feature_enabled(X86_FEATURE_LASS) && emulate_vsyscall_gp(regs)) + goto exit; + gp_user_force_sig_segv(regs, X86_TRAP_GP, error_code, desc); goto exit; } -- 2.39.2