Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4398562rwd; Tue, 30 May 2023 05:05:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6v6stnvr6y+kMS70z+FE9ZZEOo3NgD7F4Zj/n+SSnDIcseyW6fm53w6sFuYUJ/PO3Rqa4w X-Received: by 2002:a17:90a:7527:b0:255:69e5:2f6c with SMTP id q36-20020a17090a752700b0025569e52f6cmr2315676pjk.26.1685448304157; Tue, 30 May 2023 05:05:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685448304; cv=none; d=google.com; s=arc-20160816; b=LCOE9IfrXD5xmewkqEC53dvs333OJTrLwK4MizpgFQS3xD5zN23JRpti06vIM7P0Vq W28XFWp6KFUvSs1Rjv/u+zItwgeYQsRkbr2OBWWgHC9oSSrpiba4NpYjcxd5klsueGCH Bketoh+1wQigroCKY1NfueZtKzfVsNzNvZoODxBK+d2BfBQkrZ0ynnIiMDk44o3vqDVu f7LFEwm/kmvnQd3yu4Xuswq34Miq4nlw9pCxRpKQURlBSeW1TP2IaHk/U/d2Q7ej/1GF GuZI09n9iZpx8/R9HGGOPpJDu28xt6WT2Y8/vt5YQk9xqHdkV7HnVTPLetNZjsarefSW stxQ== 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:to:from :dkim-signature; bh=BcxK3Vk4KJNf2O3ND9UBZ/UaiGU80IHXaw6xJMJNi3I=; b=I5m08uc97LO+f/D+7tLtqpnKCiALlK0kup+rFpJ8885Asm417hWTaJolevd6HwOsuZ zAi8OGipjneBBgE7+S1+BowF/qG9K3NbDUKAWAXPqUmL1RSYSeuUqmmctCeEMtUv16q6 FgX25O24lq9aXS+7Nc3T6A72rkAdLeyg7AdrvgF9dEO8AU8QsDOOj3iQwKwWf/PPmDxm vXzc274VcgO9tdH72JN30YItH5hsVRqweGfCw+KrKz3erB+uZTNvroTRZ4l13itXpLbV hceKH7PpM/kxosP12MpIuu8V9iVRVWKIjLGyY0I98PEf6/7IRSrWF91//lonPrSYWvxl BQoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=H2bphBMG; 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 k73-20020a636f4c000000b0053faf4483fasi1441568pgc.143.2023.05.30.05.04.49; Tue, 30 May 2023 05:05:04 -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=H2bphBMG; 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 S229639AbjE3LoZ (ORCPT + 99 others); Tue, 30 May 2023 07:44:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230232AbjE3Lns (ORCPT ); Tue, 30 May 2023 07:43:48 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5C6311B for ; Tue, 30 May 2023 04:43:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685447020; x=1716983020; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=gJdayHg+koRv5FcILR4JuhFJIV7z9Em6QaF1NhwHxqk=; b=H2bphBMGWXq11X9J5aJP9+m6RxJhlZKA11XvATuLGuntT7myq03yy2lD 9KBdZsFs9dFkDsfvV2mCTw92d98ALksJth1mPmIF6nViKrsRwfJlMdTkH vtmgTf3P0qKbSiTu/WA99nNk7ZvwNMbmGjlVavKGOtMQTVGHMAkXKfjB8 yikVtdZlTyK1OC7frSWYm8c4h61Kc69uU6NBVkw+EVLxo7NrGtibINx1u Ykrdnn1Nzf+HltXTadHND1lraDvMcukTgYYlkyQCJVHdpOCxnVDm/0w48 nEqldB1TK5KsI5eALcL1s//LS2VgKzO3nUVuz5Gb7D6Id9wKpJ4vHP+5a A==; X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="383145382" X-IronPort-AV: E=Sophos;i="6.00,204,1681196400"; d="scan'208";a="383145382" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 May 2023 04:43:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="700588742" X-IronPort-AV: E=Sophos;i="6.00,204,1681196400"; d="scan'208";a="700588742" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by orsmga007.jf.intel.com with ESMTP; 30 May 2023 04:43:15 -0700 From: Alexander Shishkin To: linux-kernel@vger.kernel.org, x86@kernel.org, Andy Lutomirski , Dave Hansen , Ravi Shankar , Tony Luck , Sohil Mehta , Paul Lai Subject: [PATCH v2 08/12] x86/vsyscall: Add vsyscall emulation for #GP Date: Tue, 30 May 2023 14:42:43 +0300 Message-Id: <20230530114247.21821-9-alexander.shishkin@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230530114247.21821-1-alexander.shishkin@linux.intel.com> References: <20230530114247.21821-1-alexander.shishkin@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 --- 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