Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp721054img; Wed, 20 Mar 2019 09:27:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqwxVUJ35EcF2ua2+7SKG5fTTcKWVckjymfVVhnovlZ0NwaUt2SW8WHR0pgYvXUQ+Qhs21N+ X-Received: by 2002:a62:4299:: with SMTP id h25mr8496518pfd.165.1553099234023; Wed, 20 Mar 2019 09:27:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553099234; cv=none; d=google.com; s=arc-20160816; b=YUi+o3VfAfu2BQpeMHNC78xyJdensBhj2fNMF5tjd1q0GrZKRL8s8X1IJYVbVl9y9h lQRG5XCk/HpY5VSrGx2sXdGmAckafglxwE5InvJot5EZ2vtdf8GB20eCHc4NiiDl0hEb VUBY7u97wAxXrSHXzN++vZoWy0FsrqS3N88eqtWY8jX4NuLC+ydaluRtQ15PezVdCyad 2rTcmHCCSh9VtPtaPZD9CLS17lbk/nV5WSqNDspUPgzV24mTqf9aaMI6eGyWU7r8ObHh WmpUa7AbuKPBXj5c5vjbzr8YXg86ujzgm24Pxi4U5f38EkchX9Ilf63gEo2ndm3g2HHQ r34g== 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=O+b/Lmr7yqhZ76t86xyP3F/wNjRHbTpFL5UnErNW5WEXZw3+mavSfff8EjWIQ8Ir+A 2npRVOr0G09ZJswwSozD+PxxADsAgUtg5KvAn37ewjpAgMjgNGMKQNjrQ0tLoLBaDrEq 26gKKfDPGoKYrpO8kBfF2rZoozwZrTzLiRgMskAPWDiicx0Z+TYuH1ztXaiyuV7F2ojz 84nks9ETjo8T91Tsi/vOHAa2wD2JX7Qv/VdV8MSG+6calgfDWYqlo9ngg+tcpHTxhghS zMuBrv69j0ne9NPJ6irXDZnOYFKpUXTo/6ys2Qsv1mmV3afoo/AdElMjZUgET4xxolrO cDEA== 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 p12si2109097plo.206.2019.03.20.09.26.58; Wed, 20 Mar 2019 09:27:14 -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 S1727880AbfCTQZt (ORCPT + 99 others); Wed, 20 Mar 2019 12:25:49 -0400 Received: from mga01.intel.com ([192.55.52.88]:41564 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727089AbfCTQZs (ORCPT ); Wed, 20 Mar 2019 12:25:48 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Mar 2019 09:25:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,249,1549958400"; d="scan'208";a="135715824" Received: from sorenthe-mobl1.ger.corp.intel.com (HELO localhost) ([10.249.254.203]) by orsmga003.jf.intel.com with ESMTP; 20 Mar 2019 09:25:37 -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 v19,RESEND 22/27] x86/fault: Attempt to fixup unhandled #PF in vDSO before signaling Date: Wed, 20 Mar 2019 18:21:14 +0200 Message-Id: <20190320162119.4469-23-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190320162119.4469-1-jarkko.sakkinen@linux.intel.com> References: <20190320162119.4469-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