Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2212845imm; Tue, 10 Jul 2018 15:35:14 -0700 (PDT) X-Google-Smtp-Source: AAOMgpevwqIBEoWFff7oHtTSVok+wi42hKKwLy36195Ty/fpZYXn+JJ2K3LeFTFZcG4f51h4YoEs X-Received: by 2002:a63:107:: with SMTP id 7-v6mr23985966pgb.289.1531262114101; Tue, 10 Jul 2018 15:35:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531262114; cv=none; d=google.com; s=arc-20160816; b=eeeJD5w7r/J926Z4dJ/to4AEUjGbWsCVaP4zdW4b3tEwpkNieGBeFdBHvaU1llSLtl k/Kifj5s+WwzV9iJnNt4++TEhSBTTAjmyMkN4UOf1yPgimakEn3lNNE/NGhC8xFpzX5T Ea/5DywLl0FZAYbnTIDWMzayxOrsAlZeRDg8LU4i9BEFuE5VcD7QXNQa3wwj9DHutfSy UwtiL6zGM+jpE3D/dAhtYdrnQ2Rxa0OIHE6nopfo4JQhbp0uG/vcKTVV4p5Ud9h3iDwq jvPHaPIsgYEDWX2/MhVSv4NrkYprCiOTnKuoq8Qu/bh0VwN5LB1JsJLgnuR+l95b3aTB 6Osw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=vsWbAJ9dwtrANSA+1mry1OkwYd4ERwB0LycaMYYnhOk=; b=tc7pfZqaxh2DLAFLRWitpxjAZEhbuD3GaNd08J9rape3AwgjwNu0OZ5iUW6W7ajqax 3GjCOQCcm1qry6QSTYwjubZD394MK+Byso2kDDcNKLQvpPWQlYQ4ffDp6ELh4yNDuPl7 djqp8fWlNTsLyfCPLTia0r5mGufwqTJdh+PZMigRmxkugfR8uWDd7V8pZgnh4MIb9hgL iJKlkd9ssUJ4kfCkc/1WJlvnkNcgitcqqnPnQP5S5Wnpp9/HrduhIzZCnMPUKqFZLSNd qJFf2w5strvoBEN0UJ8yVyzUAqo4uAaKHLBQgBUa9wz6sX05vYy3PCH/fusq+k6yM/B1 LSSw== 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 9-v6si18016824pla.59.2018.07.10.15.34.58; Tue, 10 Jul 2018 15:35: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 S1732418AbeGJWcY (ORCPT + 99 others); Tue, 10 Jul 2018 18:32:24 -0400 Received: from mga12.intel.com ([192.55.52.136]:33776 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732385AbeGJWcX (ORCPT ); Tue, 10 Jul 2018 18:32:23 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jul 2018 15:31:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,335,1526367600"; d="scan'208";a="70305407" Received: from 2b52.sc.intel.com ([143.183.136.52]) by fmsmga004.fm.intel.com with ESMTP; 10 Jul 2018 15:31:12 -0700 From: Yu-cheng Yu To: x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Cyrill Gorcunov , Dave Hansen , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , "Ravi V. Shankar" , Vedvyas Shanbhogue Cc: Yu-cheng Yu Subject: [RFC PATCH v2 12/27] x86/mm: Shadow stack page fault error checking Date: Tue, 10 Jul 2018 15:26:24 -0700 Message-Id: <20180710222639.8241-13-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180710222639.8241-1-yu-cheng.yu@intel.com> References: <20180710222639.8241-1-yu-cheng.yu@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If a page fault is triggered by a shadow stack access (e.g. call/ret) or shadow stack management instructions (e.g. wrussq), then bit[6] of the page fault error code is set. In access_error(), we check if a shadow stack page fault is within a shadow stack memory area. Signed-off-by: Yu-cheng Yu --- arch/x86/include/asm/traps.h | 2 ++ arch/x86/mm/fault.c | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/arch/x86/include/asm/traps.h b/arch/x86/include/asm/traps.h index 5196050ff3d5..58ea2f5722e9 100644 --- a/arch/x86/include/asm/traps.h +++ b/arch/x86/include/asm/traps.h @@ -157,6 +157,7 @@ enum { * bit 3 == 1: use of reserved bit detected * bit 4 == 1: fault was an instruction fetch * bit 5 == 1: protection keys block access + * bit 6 == 1: shadow stack access fault */ enum x86_pf_error_code { X86_PF_PROT = 1 << 0, @@ -165,5 +166,6 @@ enum x86_pf_error_code { X86_PF_RSVD = 1 << 3, X86_PF_INSTR = 1 << 4, X86_PF_PK = 1 << 5, + X86_PF_SHSTK = 1 << 6, }; #endif /* _ASM_X86_TRAPS_H */ diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index 2aafa6ab6103..fcd5739151f9 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -1163,6 +1163,17 @@ access_error(unsigned long error_code, struct vm_area_struct *vma) (error_code & X86_PF_INSTR), foreign)) return 1; + /* + * Verify X86_PF_SHSTK is within a shadow stack VMA. + * It is always an error if there is a shadow stack + * fault outside a shadow stack VMA. + */ + if (error_code & X86_PF_SHSTK) { + if (!(vma->vm_flags & VM_SHSTK)) + return 1; + return 0; + } + if (error_code & X86_PF_WRITE) { /* write, present and write, not present: */ if (unlikely(!(vma->vm_flags & VM_WRITE))) -- 2.17.1