Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4057144yba; Wed, 17 Apr 2019 03:45:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqwifIJKB8YgXhGlM21StjKHMX7AMUwWhK6W1+KtGCJkxbscKoQfZKWJtjoXP7dj+xsiGt2/ X-Received: by 2002:a62:1215:: with SMTP id a21mr87721502pfj.126.1555497922049; Wed, 17 Apr 2019 03:45:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555497922; cv=none; d=google.com; s=arc-20160816; b=gsegw0bMzL4LNr4TwNU7B9Ze83u54K8HrP1Js1EzYzgg2SFpgLBg2qamaU2/UABybm pI9Fj7wRZ+mcEzLyG1hd0S2EPk8JvOeqLVdJeWL7luBTev3ihH0hsTNf9t0o1yP+1HRL PbmNMINmC5E4wMn2eA9x++9hm3ZnlEE2xw0z4qww3BsAI3fkR/6j8WfQfMi8jdFw9yBz 9XmgjbVT72tjMP2b35VPVgGUkb0vTl3RyMmg5HBQlbxmdK43qmRItVAGOztlTRd7BjQ2 5VD6jyZDlaBnEijgGIBTV7BPtvhJP8Bu+NdKO4ahgUVDVP71UEahbJV/BM+MZrqie1ao Oc6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=s2n3xqGVFZmgZ8CJ8sKXu0pSSWYrW3gpLPYociB77cM=; b=QmMs/Aip5i8nWgDgKcwihOCe9Rwb+DPOMa5tx0tN3wDI5tKVqjP/3XolSlTL7mHEdK aiedYX/G9FnQIWct20vHF1HGnNMkHn1gqvQlXL22yjGFv1eOFJBt16oGRWOv2UJJYT6U 61UmRDAvwQek3P0f34KG26Qa3IheIfFl410YVpxhEefErQ21Ry/ceEp7L0dn4oPk0bwH F5WJ0zLV8JHkXcjNv+2VYMiGNfC4idbS1zcuHgAhHds7CavXo35nklldqpgYTBo4kT2P ahBBRwlBqOjzY5q4Bd8MY9K1n7p6QwpZO+TzcpQcvYkc5n6kQ7g/qitgLjEYAAfe67iM d9Fw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g2si46702511pgi.19.2019.04.17.03.45.07; Wed, 17 Apr 2019 03:45:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732002AbfDQKm0 (ORCPT + 99 others); Wed, 17 Apr 2019 06:42:26 -0400 Received: from mga04.intel.com ([192.55.52.120]:54691 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731509AbfDQKmZ (ORCPT ); Wed, 17 Apr 2019 06:42:25 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Apr 2019 03:42:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,361,1549958400"; d="scan'208";a="132120218" Received: from jsakkine-mobl1.tm.intel.com (HELO localhost) ([10.237.50.189]) by orsmga007.jf.intel.com with ESMTP; 17 Apr 2019 03:42:18 -0700 From: Jarkko Sakkinen To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-sgx@vger.kernel.org Cc: akpm@linux-foundation.org, dave.hansen@intel.com, sean.j.christopherson@intel.com, nhorman@redhat.com, npmccallum@redhat.com, serge.ayoun@intel.com, shay.katz-zamir@intel.com, haitao.huang@intel.com, andriy.shevchenko@linux.intel.com, tglx@linutronix.de, kai.svahn@intel.com, bp@alien8.de, josh@joshtriplett.org, luto@kernel.org, kai.huang@intel.com, rientjes@google.com, Andy Lutomirski , Jarkko Sakkinen , Dave Hansen Subject: [PATCH v20 21/28] x86/fault: Attempt to fixup unhandled #PF in vDSO before signaling Date: Wed, 17 Apr 2019 13:39:31 +0300 Message-Id: <20190417103938.7762-22-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190417103938.7762-1-jarkko.sakkinen@linux.intel.com> References: <20190417103938.7762-1-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson vDSO functions can now leverage an exception fixup mechanism similar to kernel exception fixup. For vDSO exception fixup, the initial user is Intel's Software Guard Extensions (SGX), which will wrap the low-level transitions to/from the enclave, i.e. EENTER and ERESUME instructions, in a vDSO function and leverage fixup to intercept exceptions that would otherwise generate a signal. This allows the vDSO wrapper to return the fault information directly to its caller, obviating the need for SGX applications and libraries to juggle signal handlers. Attempt to fixup vDSO exceptions immediately prior to populating and sending signal information. Except for the delivery mechanism, an exception in a vDSO function should be treated like any other exception in userspace, e.g. any fault that is successfully handled by the kernel should not be directly visible to userspace. Suggested-by: Andy Lutomirski Cc: Andy Lutomirski Cc: Jarkko Sakkinen Cc: Dave Hansen Cc: Josh Triplett Signed-off-by: Sean Christopherson --- arch/x86/mm/fault.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index 5babd515f616..13be0c67379e 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -28,6 +28,7 @@ #include /* vma_pkey() */ #include /* efi_recover_from_page_fault()*/ #include /* store_idt(), ... */ +#include /* fixup_vdso_exception() */ #define CREATE_TRACE_POINTS #include @@ -936,6 +937,9 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code, sanitize_error_code(address, &error_code); + if (fixup_vdso_exception(regs, X86_TRAP_PF, error_code, address)) + return; + if (likely(show_unhandled_signals)) show_signal_msg(regs, error_code, address, tsk); @@ -1055,6 +1059,9 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address, sanitize_error_code(address, &error_code); + if (fixup_vdso_exception(regs, X86_TRAP_PF, error_code, address)) + return; + set_signal_archinfo(address, error_code); #ifdef CONFIG_MEMORY_FAILURE -- 2.19.1