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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 A72EDC432BE for ; Thu, 26 Aug 2021 16:24:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 67A576117A for ; Thu, 26 Aug 2021 16:24:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 67A576117A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=alien8.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id A74C98D0002; Thu, 26 Aug 2021 12:24:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A254C8D0001; Thu, 26 Aug 2021 12:24:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 913618D0002; Thu, 26 Aug 2021 12:24:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0183.hostedemail.com [216.40.44.183]) by kanga.kvack.org (Postfix) with ESMTP id 763F68D0001 for ; Thu, 26 Aug 2021 12:24:54 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 0EF971CB2E for ; Thu, 26 Aug 2021 16:24:54 +0000 (UTC) X-FDA: 78517755708.04.A308611 Received: from mail.skyhub.de (mail.skyhub.de [5.9.137.197]) by imf04.hostedemail.com (Postfix) with ESMTP id A8E4450000B4 for ; Thu, 26 Aug 2021 16:24:45 +0000 (UTC) Received: from zn.tnic (p200300ec2f131000dba9b80c472eda01.dip0.t-ipconnect.de [IPv6:2003:ec:2f13:1000:dba9:b80c:472e:da01]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id B1D801EC05A0; Thu, 26 Aug 2021 18:24:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1629995079; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=nAR7I+RvkkR/CrtB9Lh5jb8RkckwGTFjzOTKJm0aJng=; b=Fv5in2D0HjkccNSYDhG+FSvC/iX9cjzHUQdJQToLlOkfDP7a/N8oTZciIY7S/3bDe82h3m ix8Spe+M056b1gjhQeLRDPPZPBWO3+W2s6SQcOAvtunECnZo8gqH1zzVBzzJnCvo/M8jNy 9fPksymjuHyNGHV1LbVz3DmW57apopg= Date: Thu, 26 Aug 2021 18:25:17 +0200 From: Borislav Petkov 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 , 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" , Dave Martin , Weijiang Yang , Pengfei Xu , Haitao Huang , Rick P Edgecombe Subject: Re: [PATCH v29 23/32] x86/cet/shstk: Add user-mode shadow stack support Message-ID: References: <20210820181201.31490-1-yu-cheng.yu@intel.com> <20210820181201.31490-24-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210820181201.31490-24-yu-cheng.yu@intel.com> Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=alien8.de header.s=dkim header.b=Fv5in2D0; spf=temperror (imf04.hostedemail.com: error in processing during lookup of bp@alien8.de: DNS error) smtp.mailfrom=bp@alien8.de; dmarc=temperror reason="query timed out" header.from=alien8.de (policy=temperror) X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: A8E4450000B4 X-Stat-Signature: c37durbo3twjxgqwpwrrhc7jpant6cax X-HE-Tag: 1629995085-259804 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 Fri, Aug 20, 2021 at 11:11:52AM -0700, Yu-cheng Yu wrote: > diff --git a/arch/x86/include/asm/cet.h b/arch/x86/include/asm/cet.h > new file mode 100644 > index 000000000000..6432baf4de1f > --- /dev/null > +++ b/arch/x86/include/asm/cet.h > @@ -0,0 +1,30 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_X86_CET_H > +#define _ASM_X86_CET_H > + > +#ifndef __ASSEMBLY__ > +#include > + > +struct task_struct; > + > +/* > + * Per-thread CET status > + */ That comment is superfluous and wrong now. The struct name says exactly what that thing is. > +static unsigned long alloc_shstk(unsigned long size) > +{ > + int flags = MAP_ANONYMOUS | MAP_PRIVATE; > + struct mm_struct *mm = current->mm; > + unsigned long addr, populate; s/populate/unused/ > + > + mmap_write_lock(mm); > + addr = do_mmap(NULL, 0, size, PROT_READ, flags, VM_SHADOW_STACK, 0, > + &populate, NULL); > + mmap_write_unlock(mm); > + > + return addr; > +} > + > +int shstk_setup(void) > +{ > + struct thread_shstk *shstk = ¤t->thread.shstk; > + unsigned long addr, size; > + int err; > + > + if (!cpu_feature_enabled(X86_FEATURE_SHSTK)) > + return 0; > + > + size = round_up(min_t(unsigned long long, rlimit(RLIMIT_STACK), SZ_4G), PAGE_SIZE); > + addr = alloc_shstk(size); > + if (IS_ERR_VALUE(addr)) > + return PTR_ERR((void *)addr); > + > + start_update_msrs(); You're setting CET_U with the MSR writes below. Why do you need to do XRSTOR here? To zero out PL[012]_SSP? If so, you can WRMSR those too - no need for a full XRSTOR... > + err = wrmsrl_safe(MSR_IA32_PL3_SSP, addr + size); > + if (!err) > + wrmsrl_safe(MSR_IA32_U_CET, CET_SHSTK_EN); > + end_update_msrs(); > + > + if (!err) { > + shstk->base = addr; > + shstk->size = size; > + } > + > + return err; > +} -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette