Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2520296imm; Thu, 7 Jun 2018 12:02:55 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLT9lmfL6A2WVwE3JeMmd7iBkdJZqThUOSWlMEJNONMOMF3rRjkGwgEMVVvUvawquHmmtgk X-Received: by 2002:a17:902:4483:: with SMTP id l3-v6mr3251433pld.282.1528398175756; Thu, 07 Jun 2018 12:02:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528398175; cv=none; d=google.com; s=arc-20160816; b=kgqRjWMECx06HLWRhKp3eEMY+U5HknjOQJU1XfQ6V5ATfIXKw9fYFmy1pqbak1ue4j LngCkJXJlyGtMpbadY8iRgUDeAKSQ3gWVd5srCEGsP74C/S28gtDGxj6Ja50JX7lba5p ftGVvoo+AjGmchwrw/2DYB+na8CUGr97K0uxAuCrbL6QnnTxLavjF1tumHzCF0WMlq+u R06EP6ExmiVdScwSUpn8WNSoWBv9enwNVOOxpZ6udym5ztx2atZ5hRqG7i6gsyd0EmX3 tn/ai1Uf/jtmjB95i1pWUjy1eOynVL1aFVDIMmzzgUSAHktZZGwslmDxALZsaNdOLrTn w8wA== 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:date:cc:to:from:subject:message-id :arc-authentication-results; bh=izLTlcC7eaTKHovF41GXHKSiv59OdYPnf51TELEmufY=; b=Po16DC6taLnjAVPaHWDXuwexTt21euhs0jbLMXJjrSkxGQc2R37plvshsVF4VfAq3i 4+VF4w8Ajv2paKk9asLWoCbWhH4KODdWMk0dA/039ff5gSp+Zx9qwny+FH+ZLweV/tCm hJdLZqwLaVyoET8S1b+UgFak89iGWWXjWvZZXJCMu3oEiZ9C6TtsRepbWacgthsew4Eq igAgAm/7puRTjHVyu0/mM8NTIK0ixBtS6V0abrnTrWQKXMKOpwT0TZYMVu+GBHdBMKP0 7owYVZvTZVGatGn5hT4Kiu0xP+XJP93p6H0uKTyvDeO4KrjxucoI+EUV/30ZkD9r2MYA 4gZA== 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 bc12-v6si9305957plb.373.2018.06.07.12.02.40; Thu, 07 Jun 2018 12:02:55 -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 S934071AbeFGQyi (ORCPT + 99 others); Thu, 7 Jun 2018 12:54:38 -0400 Received: from mga11.intel.com ([192.55.52.93]:15917 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933743AbeFGQyf (ORCPT ); Thu, 7 Jun 2018 12:54:35 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Jun 2018 09:54:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,487,1520924400"; d="scan'208";a="206180057" Received: from 2b52.sc.intel.com (HELO [143.183.136.51]) ([143.183.136.51]) by orsmga004.jf.intel.com with ESMTP; 07 Jun 2018 09:54:24 -0700 Message-ID: <1528390273.4636.28.camel@2b52.sc.intel.com> Subject: Re: [PATCH 02/10] x86/cet: Introduce WRUSS instruction From: Yu-cheng Yu To: Andy Lutomirski Cc: Peter Zijlstra , LKML , linux-doc@vger.kernel.org, Linux-MM , linux-arch , X86 ML , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , "H. J. Lu" , "Shanbhogue, Vedvyas" , "Ravi V. Shankar" , Dave Hansen , Jonathan Corbet , Oleg Nesterov , Arnd Bergmann , mike.kravetz@oracle.com Date: Thu, 07 Jun 2018 09:51:13 -0700 In-Reply-To: References: <20180607143807.3611-1-yu-cheng.yu@intel.com> <20180607143807.3611-3-yu-cheng.yu@intel.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2018-06-07 at 09:40 -0700, Andy Lutomirski wrote: > On Thu, Jun 7, 2018 at 7:41 AM Yu-cheng Yu wrote: > > > > 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 > > fixup. > > > > Signed-off-by: Yu-cheng Yu > > --- > > arch/x86/include/asm/special_insns.h | 44 +++++++++++++++++++++++++++ > > arch/x86/lib/x86-opcode-map.txt | 2 +- > > arch/x86/mm/fault.c | 13 +++++++- > > tools/objtool/arch/x86/lib/x86-opcode-map.txt | 2 +- > > 4 files changed, 58 insertions(+), 3 deletions(-) > > > > diff --git a/arch/x86/include/asm/special_insns.h b/arch/x86/include/asm/special_insns.h > > index 317fc59b512c..8ce532fcc171 100644 > > --- a/arch/x86/include/asm/special_insns.h > > +++ b/arch/x86/include/asm/special_insns.h > > @@ -237,6 +237,50 @@ 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) > > +{ > > + int err; > > + > > Please add a comment indicating what exact opcode this is. I will fix it. > > Peterz, isn't there some fancy better way we're supposed to handle the > error return these days? > > > + asm volatile("1:.byte 0x66, 0x0f, 0x38, 0xf5, 0x37\n" > > + "xor %[err],%[err]\n" > > + "2:\n" > > + ".section .fixup,\"ax\"\n" > > + "3: mov $-1,%[err]; jmp 2b\n" > > + ".previous\n" > > + _ASM_EXTABLE(1b, 3b) > > + : [err] "=a" (err) > > + : [val] "S" (val), [addr] "D" (addr) > > + : "memory"); > > + return err; > > +} > > +#else > > +static inline int write_user_shstk_32(unsigned long addr, unsigned int val) > > +{ > > + return 0; > > BUG()? Or just omit the ifdef? It seems unhelpful to have a stub > function that does nothing. I will fix it. > > > +} > > +#endif > > + > > +static inline int write_user_shstk_64(unsigned long addr, unsigned long val) > > +{ > > + int err; > > + > > Comment here too, please. OK. > > > + asm volatile("1:.byte 0x66, 0x48, 0x0f, 0x38, 0xf5, 0x37\n" > > + "xor %[err],%[err]\n" > > + "2:\n" > > + ".section .fixup,\"ax\"\n" > > + "3: mov $-1,%[err]; jmp 2b\n" > > + ".previous\n" > > + _ASM_EXTABLE(1b, 3b) > > + : [err] "=a" (err) > > + : [val] "S" (val), [addr] "D" (addr) > > + : "memory"); > > + return err; > > +} > > +#endif /* CONFIG_X86_INTEL_CET */ > > + > > #define nop() asm volatile ("nop") > > > >