From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE066C35E0E for ; Tue, 25 Feb 2020 21:10:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AE8622176D for ; Tue, 25 Feb 2020 21:10:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="h+pDnoGO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AE8622176D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 363D46B0003; Tue, 25 Feb 2020 16:10:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2EBF46B0005; Tue, 25 Feb 2020 16:10:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B3686B0006; Tue, 25 Feb 2020 16:10:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0067.hostedemail.com [216.40.44.67]) by kanga.kvack.org (Postfix) with ESMTP id F3E1E6B0003 for ; Tue, 25 Feb 2020 16:10:18 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 9A33B181AC9BF for ; Tue, 25 Feb 2020 21:10:18 +0000 (UTC) X-FDA: 76529892516.24.roll06_2a4129be3533 X-HE-Tag: roll06_2a4129be3533 X-Filterd-Recvd-Size: 5713 Received: from mail-pj1-f68.google.com (mail-pj1-f68.google.com [209.85.216.68]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Tue, 25 Feb 2020 21:10:18 +0000 (UTC) Received: by mail-pj1-f68.google.com with SMTP id e9so270223pjr.4 for ; Tue, 25 Feb 2020 13:10:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=RJKpOOFGEfUAGGLqO1NUhiGzKjVzNOK2IgBZIyJHxc0=; b=h+pDnoGOYsk+E8Wt6TpmxUxdwV6kjF4atGpRldLId/Yw8w9WfMNnrM8XJReblD9SwC 8LeJhqiafUtArcvC4wLH1Ri6+yqFHMw0jvz4WTjgvML3xSZUD/c8wIZT5mi6IVRxMhSV aNZy8mj/AVPfjzspIlHT7j9dhhuOVWKWW+0mY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=RJKpOOFGEfUAGGLqO1NUhiGzKjVzNOK2IgBZIyJHxc0=; b=l3D7n0DuB72bXz/sFD5I7oEc4V2h+Ak0yMRAnaFUZ/HaIkLaoZApuvAbnSb7y64Eez XY37FmrcBW+5l9sVRN1NkqR8xO/7e0Gmxzn6pC/i7V1Mgs4dHBqDoTWYdM+8XcpmOBDb Gs8YFMnwcQIc7ox86WcElOwelEOx0TNEtXtzdmCj4xeHCvJ2mUIMC+iYSH1wKzv1Gxkc TraoZdm+sOQkliDBr5JAewWBybj6FDYauJyoAYMFwGR44dj9gnOej0ROM+yUj18qnDLf QcHos0fUBx4pZggpMht9vQM5d2bVgBjHawleP8FYxuR5odMPOGsw6x5/+BnBUIB/MpMp QYLQ== X-Gm-Message-State: APjAAAUlO2qt8Y9tfz8nI4nFjgBhZNeTihS7fytPLTPtFWa8SxS4GU3Q hLCNt36qZ8HeexJlzi11+pDPmg== X-Google-Smtp-Source: APXvYqzQAbfYXF5TtmiNKwyw9CCTemc+ykrjzmXEtfYjXSRlSbhEiGrlXLqSnZ/Ps0gefcUFE6oD5g== X-Received: by 2002:a17:902:bb93:: with SMTP id m19mr467640pls.310.1582665016973; Tue, 25 Feb 2020 13:10:16 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id w81sm18583961pff.95.2020.02.25.13.10.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 13:10:16 -0800 (PST) Date: Tue, 25 Feb 2020 13:10:14 -0800 From: Kees Cook To: Yu-cheng Yu Cc: 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 , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin , x86-patch-review@intel.com Subject: Re: [RFC PATCH v9 18/27] x86/cet/shstk: Introduce WRUSS instruction Message-ID: <202002251309.E238DFEEB4@keescook> References: <20200205181935.3712-1-yu-cheng.yu@intel.com> <20200205181935.3712-19-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200205181935.3712-19-yu-cheng.yu@intel.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Feb 05, 2020 at 10:19:26AM -0800, Yu-cheng Yu wrote: > WRUSS is a new kernel-mode instruction but writes directly to user Shadow > Stack (SHSTK) memory. This is used to construct a return address on SHSTK > for the signal handler. > > This instruction can fault if the user SHSTK is not valid SHSTK memory. > In that case, the kernel does a fixup. Since these functions aren't used in this patch, should this get merged with patch 19? -Kees > > v4: > - Change to asm goto. > > 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 6d37b8fcfc77..1b9b2e79c353 100644 > --- a/arch/x86/include/asm/special_insns.h > +++ b/arch/x86/include/asm/special_insns.h > @@ -222,6 +222,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.21.0 > -- Kees Cook