Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1512906ybl; Tue, 13 Aug 2019 14:04:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqw23tXEGyAGYES8I+vzXo9An0bWbrEzF/AZix9xzZOJ0OXOXmwHIyFICpY/MZ3RZEgb9gwZ X-Received: by 2002:a62:b411:: with SMTP id h17mr41104357pfn.99.1565730250306; Tue, 13 Aug 2019 14:04:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565730250; cv=none; d=google.com; s=arc-20160816; b=OFsIP84D0Lu5/lfzuiUhb9FvAoGtWQhT1AAbeD9w32NaG+SRqzrodDIyPERdww2OhG Hzx81NVxBjV4gAK2fq0ESBEBgsKFht3jXjMoZFwU80C1yf8XV7a/USc63ScAI3S3NPKs Qyr6nDYlkZL0gTZhgr9cYCLgAZdAD6tAOGbFYNlhbrB6Z88CbSCnPs3IRZLSTlQTnthF BN85oRinKSOXfehUt2OPhswfhqCFTE5MADMuYrqjscP4wLpPcZvnSISaHRVBaNiCuS4I Tkiz4WlYycRI3kmrNo5YSCIUUfDkda7n1JwwwwtWeCm24D5ySvGl89BHnFe11HylBxIj FJTw== 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; bh=Bt7p717IlQVl27chUp3G+PIlJj/2o251K33/71OqPdE=; b=I+neEVmx7Jn/mcY8tWWIN54HnuDZUfGLhvuAkrUUtM96gOQoNSkij5jLLglAXMwhkE zmidKY7cBVLEFlIedf0F2GWV1TFX8XakzgXEsuWLd1Md9ODriJqmjH+1qbTZ3S+VzC9R ofx5YSgBZazAz4YgdCDOshtnqo3rrAaQUD0ce/VctEIslUkxjJ+k38b/MiPiq5if6Eho YynTUehH6e7nmMNo1w/UGyshFn40JgndaTsPqD7ykI75HZWgF7XQV1SOAe21nKYZ5qAk bVT/G8z884+xkKvjUnd/fsVEEkS6uDTqswWqRfPFlszlN+FZU9XqFqDpYfhhXm5cFy1p AlzQ== 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 j3si17043154pld.232.2019.08.13.14.03.54; Tue, 13 Aug 2019 14:04:10 -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 S1727003AbfHMVDF (ORCPT + 99 others); Tue, 13 Aug 2019 17:03:05 -0400 Received: from mga06.intel.com ([134.134.136.31]:16076 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726975AbfHMVDC (ORCPT ); Tue, 13 Aug 2019 17:03:02 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Aug 2019 14:03:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,382,1559545200"; d="scan'208";a="187901471" Received: from yyu32-desk1.sc.intel.com ([10.144.153.205]) by orsmga002.jf.intel.com with ESMTP; 13 Aug 2019 14:03:00 -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 , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin Cc: Yu-cheng Yu Subject: [PATCH v8 20/27] x86/cet/shstk: Introduce WRUSS instruction Date: Tue, 13 Aug 2019 13:52:18 -0700 Message-Id: <20190813205225.12032-21-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190813205225.12032-1-yu-cheng.yu@intel.com> References: <20190813205225.12032-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 WRUSS is a new kernel-mode instruction but writes directly to user shadow stack memory. This is used to construct a return address on the shadow stack for the signal handler. This instruction can fault if the user shadow stack is invalid shadow stack memory. In that case, the kernel does a fixup. Signed-off-by: Yu-cheng Yu --- arch/x86/include/asm/special_insns.h | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/arch/x86/include/asm/special_insns.h b/arch/x86/include/asm/special_insns.h index 219be88a59d2..10f821d6b469 100644 --- a/arch/x86/include/asm/special_insns.h +++ b/arch/x86/include/asm/special_insns.h @@ -246,6 +246,38 @@ static inline void clwb(volatile void *__p) : [pax] "a" (p)); } +#ifdef CONFIG_X86_INTEL_CET +#if defined(CONFIG_IA32_EMULATION) || defined(CONFIG_X86_X32) +static inline int write_user_shstk_32(unsigned long addr, unsigned int val) +{ + asm_volatile_goto("1: wrussd %1, (%0)\n" + _ASM_EXTABLE(1b, %l[fail]) + :: "r" (addr), "r" (val) + :: fail); + return 0; +fail: + return -EPERM; +} +#else +static inline int write_user_shstk_32(unsigned long addr, unsigned int val) +{ + WARN_ONCE(1, "%s used but not supported.\n", __func__); + return -EFAULT; +} +#endif + +static inline int write_user_shstk_64(unsigned long addr, unsigned long val) +{ + asm_volatile_goto("1: wrussq %1, (%0)\n" + _ASM_EXTABLE(1b, %l[fail]) + :: "r" (addr), "r" (val) + :: fail); + return 0; +fail: + return -EPERM; +} +#endif /* CONFIG_X86_INTEL_CET */ + #define nop() asm volatile ("nop") -- 2.17.1