Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2511730imm; Thu, 7 Jun 2018 11:54:50 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJOh0/eTk5JdJDMo4wC/G6R6VaopdDDwBP5NVZ4V2VN53a6ARSybQJjWuxR9wVT7Yr+dMFI X-Received: by 2002:a62:3dca:: with SMTP id x71-v6mr2858698pfj.134.1528397690401; Thu, 07 Jun 2018 11:54:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528397690; cv=none; d=google.com; s=arc-20160816; b=Viy5EiFSNXHHSD/AhcXE/JaFmNyh7CUaHGwqQjBGNIvpNXcvih7uQn/b43rXKdPt8L sTM5g5RJgcv9cWiqgwNtH816DCRDzGi2wu+Mmmk0RZCsIliK4dEUVD7rbTnGrIOoLVHN VEku4p0TizdXhWIrrBa5eNTmvUlKDwH3aQaRUJA3feU7ZuEMU+1PuGQsB7FQiynWGAIV A4zTuObTS5MOUoRC5jppPhx84PIWk2Ja5Eln0e+z+4+7Z43GRPmGg3+QHaY9teGzRZwH Uu/DNpIr+3WrO9asEbvdEnjUJopTwTH9oi7tvAtfaTd8ky6CPe8InGyZqDS/5Tg5Z2u4 9a7A== 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=zPCFQ2pzKBWbjbEILvqOiVGH0PjbWg5GFmTe9kfxrIg=; b=I3EfkqYZIF6TP5gSTQHuZA2QwiVUdFBjlVQo4uroW7p3102vAE2CWY0/jitW8ikiMx gDPP8pYLrjw1VJDHQ060k8x/Yj/u9HfzfUC3H9y0KkrUSQQi1SjiaaK3msxHAnSVqW0u gzXWq1OIUKCQUYSv7QtCpw0Y1L8McyfJIjc/p76pNgXyYw78s0ixUIn4xO7l08PL8FVS dxAjbALKieuSOExeDJ56WTjfHuEF9ogdzxY8Q+Q1iDSHOjAw93a5sTHea2U83V98uUg1 w+2NLKWZz7wy14HowYT61Lkuo6XhMTsHyROCeyTmu29kmpFh0x9fZ8mwhRclWdweKBCm TvGQ== 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 w13-v6si4839291pgo.542.2018.06.07.11.54.36; Thu, 07 Jun 2018 11:54:50 -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 S934627AbeFGPo6 (ORCPT + 99 others); Thu, 7 Jun 2018 11:44:58 -0400 Received: from mga09.intel.com ([134.134.136.24]:36280 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934511AbeFGOkj (ORCPT ); Thu, 7 Jun 2018 10:40:39 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Jun 2018 07:40:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,486,1520924400"; d="scan'208";a="47542305" Received: from 2b52.sc.intel.com ([143.183.136.51]) by orsmga008.jf.intel.com with ESMTP; 07 Jun 2018 07:40:33 -0700 From: Yu-cheng Yu To: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , "H.J. Lu" , Vedvyas Shanbhogue , "Ravi V. Shankar" , Dave Hansen , Andy Lutomirski , Jonathan Corbet , Oleg Nesterov , Arnd Bergmann , Mike Kravetz Cc: Yu-cheng Yu Subject: [PATCH 7/9] x86/mm: Shadow stack page fault error checking Date: Thu, 7 Jun 2018 07:37:03 -0700 Message-Id: <20180607143705.3531-8-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180607143705.3531-1-yu-cheng.yu@intel.com> References: <20180607143705.3531-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 73bd8c95ac71..2b3b9170109c 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -1166,6 +1166,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.15.1