Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp575746pxb; Thu, 26 Aug 2021 09:26:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBwEhydU9YdiDtGVC2QVdS8vonw9pgjdUaEtxVOmtRcdbBao8ye8K9DRMu2zHSDAd4k6aM X-Received: by 2002:a92:4a10:: with SMTP id m16mr3237618ilf.233.1629995207537; Thu, 26 Aug 2021 09:26:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629995207; cv=none; d=google.com; s=arc-20160816; b=YJOu5CbJAY3/N47uu0Ooz/xAUqqT0s8IfdTtWkILyGSBc/SuV+TkifaIE2ZJ5mW3kD i9oCm6/TFVkY0t1tQ8LdCBH2u3lMqjpNXU7aAYz5+FqyweHDjnZk/fOIJMRlO5ksY7nu W1veaHgzWrsy7sSDXfQGI/5mpSYFEXjsdYVb8CRjLcxMIaBqRkfBb+oVCivU9deSGu2m UcJDLvuoOWVRtkYVz5I2zoG3JG4kUbHos7TE35iALCbEBemg0ywaumCQ5MoDjOFreo5S HfeuOa1w1RvE0nSrNoIDwg/kg0D2RyRRVzVSU6JaXx5hV3W83jkOEUl7sdjG1Wkcif4r Ds9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=nAR7I+RvkkR/CrtB9Lh5jb8RkckwGTFjzOTKJm0aJng=; b=kTaPfMo9Sry+QJkOfW9LgJmmywRUXGtTfr9t7L6655BK0RwiH7vlVPUFz+Y4Cr1PE5 XiQHfMOXYvEXT+MjgAMp8ZBR3XTV/6tB1CPOlJLdlfvPZH53kjPOEaLs5B11GrizSt5K w4+NEFFoCMiWGLx0OD9/UM809tfYb7sNviD5J3fL0RHlWJpHCkhwRXcj6wFnJpAt75Em Z5N7PGNV0MhWX1Vwp/h47feB/uSaWibBidLyQo2j5t9CWZnPGJV5a+68H6JOAbs6PRtE 3DVpg2y+ZC7N5gGS5kC6Hm2ZhmFAyUch76Zc4wFWnTT42yHuLIFAzne3IX97JmTWpiWS Xe8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=Fv5in2D0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g4si3442060ilq.142.2021.08.26.09.26.11; Thu, 26 Aug 2021 09:26:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=Fv5in2D0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243076AbhHZQZk (ORCPT + 99 others); Thu, 26 Aug 2021 12:25:40 -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-kernel@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