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 3C619C4320E for ; Thu, 26 Aug 2021 16:24:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1C4B86117A for ; Thu, 26 Aug 2021 16:24:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233834AbhHZQZj (ORCPT ); Thu, 26 Aug 2021 12:25:39 -0400 Received: from mail.skyhub.de ([5.9.137.197]:56304 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243097AbhHZQZd (ORCPT ); Thu, 26 Aug 2021 12:25:33 -0400 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> Precedence: bulk List-ID: X-Mailing-List: linux-arch@vger.kernel.org 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