From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yu-cheng Yu Subject: Re: [RFC PATCH v2 27/27] x86/cet: Add arch_prctl functions for CET Date: Wed, 11 Jul 2018 13:55:44 -0700 Message-ID: <1531342544.15351.37.camel@intel.com> References: <20180710222639.8241-1-yu-cheng.yu@intel.com> <20180710222639.8241-28-yu-cheng.yu@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Return-path: In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org To: Jann Horn Cc: the arch/x86 maintainers , "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , kernel list , linux-doc@vger.kernel.org, Linux-MM , linux-arch , Linux API , Arnd Bergmann , Andy Lutomirski , bsingharora@gmail.com, Cyrill Gorcunov , Dave Hansen , Florian Weimer , hjl.tools@gmail.com, Jonathan Corbet , keescook@chromiun.org, Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek Pete List-Id: linux-api@vger.kernel.org On Wed, 2018-07-11 at 12:45 -0700, Jann Horn wrote: > On Tue, Jul 10, 2018 at 3:31 PM Yu-cheng Yu > wrote: > > > > > > arch_prctl(ARCH_CET_STATUS, unsigned long *addr) > >     Return CET feature status. > > > >     The parameter 'addr' is a pointer to a user buffer. > >     On returning to the caller, the kernel fills the following > >     information: > > > >     *addr = SHSTK/IBT status > >     *(addr + 1) = SHSTK base address > >     *(addr + 2) = SHSTK size > > > > arch_prctl(ARCH_CET_DISABLE, unsigned long features) > >     Disable SHSTK and/or IBT specified in 'features'.  Return > > -EPERM > >     if CET is locked out. > > > > arch_prctl(ARCH_CET_LOCK) > >     Lock out CET feature. > > > > arch_prctl(ARCH_CET_ALLOC_SHSTK, unsigned long *addr) > >     Allocate a new SHSTK. > > > >     The parameter 'addr' is a pointer to a user buffer and > > indicates > >     the desired SHSTK size to allocate.  On returning to the caller > >     the buffer contains the address of the new SHSTK. > > > > arch_prctl(ARCH_CET_LEGACY_BITMAP, unsigned long *addr) > >     Allocate an IBT legacy code bitmap if the current task does not > >     have one. > > > >     The parameter 'addr' is a pointer to a user buffer. > >     On returning to the caller, the kernel fills the following > >     information: > > > >     *addr = IBT bitmap base address > >     *(addr + 1) = IBT bitmap size > > > > Signed-off-by: H.J. Lu > > Signed-off-by: Yu-cheng Yu > [...] > > > > diff --git a/arch/x86/kernel/cet_prctl.c > > b/arch/x86/kernel/cet_prctl.c > > new file mode 100644 > > index 000000000000..86bb78ae656d > > --- /dev/null > > +++ b/arch/x86/kernel/cet_prctl.c > > @@ -0,0 +1,141 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +/* See Documentation/x86/intel_cet.txt. */ > > + > > +static int handle_get_status(unsigned long arg2) > > +{ > > +       unsigned int features = 0; > > +       unsigned long shstk_base, shstk_size; > > + > > +       if (current->thread.cet.shstk_enabled) > > +               features |= GNU_PROPERTY_X86_FEATURE_1_SHSTK; > > +       if (current->thread.cet.ibt_enabled) > > +               features |= GNU_PROPERTY_X86_FEATURE_1_IBT; > > + > > +       shstk_base = current->thread.cet.shstk_base; > > +       shstk_size = current->thread.cet.shstk_size; > > + > > +       if (in_ia32_syscall()) { > > +               unsigned int buf[3]; > > + > > +               buf[0] = features; > > +               buf[1] = (unsigned int)shstk_base; > > +               buf[2] = (unsigned int)shstk_size; > > +               return copy_to_user((unsigned int __user *)arg2, > > buf, > > +                                   sizeof(buf)); > > +       } else { > > +               unsigned long buf[3]; > > + > > +               buf[0] = (unsigned long)features; > > +               buf[1] = shstk_base; > > +               buf[2] = shstk_size; > > +               return copy_to_user((unsigned long __user *)arg2, > > buf, > > +                                   sizeof(buf)); > > +       } > Other places in the kernel (e.g. the BPF subsystem) just > unconditionally use u64 instead of unsigned long to avoid having to > switch between different sizes. I wonder whether that would make > sense > here? Yes, that simplifies the code.  I will make that change. Yu-cheng From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com ([192.55.52.120]:23333 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733021AbeGKVFd (ORCPT ); Wed, 11 Jul 2018 17:05:33 -0400 Message-ID: <1531342544.15351.37.camel@intel.com> Subject: Re: [RFC PATCH v2 27/27] x86/cet: Add arch_prctl functions for CET From: Yu-cheng Yu Date: Wed, 11 Jul 2018 13:55:44 -0700 In-Reply-To: References: <20180710222639.8241-1-yu-cheng.yu@intel.com> <20180710222639.8241-28-yu-cheng.yu@intel.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-arch-owner@vger.kernel.org List-ID: To: Jann Horn Cc: the arch/x86 maintainers , "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , kernel list , linux-doc@vger.kernel.org, Linux-MM , linux-arch , Linux API , Arnd Bergmann , Andy Lutomirski , bsingharora@gmail.com, Cyrill Gorcunov , Dave Hansen , Florian Weimer , hjl.tools@gmail.com, Jonathan Corbet , keescook@chromiun.org, Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , ravi.v.shankar@intel.com, vedvyas.shanbhogue@intel.com Message-ID: <20180711205544.h_nA3a7hPRkcr9kj8Ol4YU07HM7tdxfgSMdLIn_iDEk@z> On Wed, 2018-07-11 at 12:45 -0700, Jann Horn wrote: > On Tue, Jul 10, 2018 at 3:31 PM Yu-cheng Yu > wrote: > > > > > > arch_prctl(ARCH_CET_STATUS, unsigned long *addr) > >     Return CET feature status. > > > >     The parameter 'addr' is a pointer to a user buffer. > >     On returning to the caller, the kernel fills the following > >     information: > > > >     *addr = SHSTK/IBT status > >     *(addr + 1) = SHSTK base address > >     *(addr + 2) = SHSTK size > > > > arch_prctl(ARCH_CET_DISABLE, unsigned long features) > >     Disable SHSTK and/or IBT specified in 'features'.  Return > > -EPERM > >     if CET is locked out. > > > > arch_prctl(ARCH_CET_LOCK) > >     Lock out CET feature. > > > > arch_prctl(ARCH_CET_ALLOC_SHSTK, unsigned long *addr) > >     Allocate a new SHSTK. > > > >     The parameter 'addr' is a pointer to a user buffer and > > indicates > >     the desired SHSTK size to allocate.  On returning to the caller > >     the buffer contains the address of the new SHSTK. > > > > arch_prctl(ARCH_CET_LEGACY_BITMAP, unsigned long *addr) > >     Allocate an IBT legacy code bitmap if the current task does not > >     have one. > > > >     The parameter 'addr' is a pointer to a user buffer. > >     On returning to the caller, the kernel fills the following > >     information: > > > >     *addr = IBT bitmap base address > >     *(addr + 1) = IBT bitmap size > > > > Signed-off-by: H.J. Lu > > Signed-off-by: Yu-cheng Yu > [...] > > > > diff --git a/arch/x86/kernel/cet_prctl.c > > b/arch/x86/kernel/cet_prctl.c > > new file mode 100644 > > index 000000000000..86bb78ae656d > > --- /dev/null > > +++ b/arch/x86/kernel/cet_prctl.c > > @@ -0,0 +1,141 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +/* See Documentation/x86/intel_cet.txt. */ > > + > > +static int handle_get_status(unsigned long arg2) > > +{ > > +       unsigned int features = 0; > > +       unsigned long shstk_base, shstk_size; > > + > > +       if (current->thread.cet.shstk_enabled) > > +               features |= GNU_PROPERTY_X86_FEATURE_1_SHSTK; > > +       if (current->thread.cet.ibt_enabled) > > +               features |= GNU_PROPERTY_X86_FEATURE_1_IBT; > > + > > +       shstk_base = current->thread.cet.shstk_base; > > +       shstk_size = current->thread.cet.shstk_size; > > + > > +       if (in_ia32_syscall()) { > > +               unsigned int buf[3]; > > + > > +               buf[0] = features; > > +               buf[1] = (unsigned int)shstk_base; > > +               buf[2] = (unsigned int)shstk_size; > > +               return copy_to_user((unsigned int __user *)arg2, > > buf, > > +                                   sizeof(buf)); > > +       } else { > > +               unsigned long buf[3]; > > + > > +               buf[0] = (unsigned long)features; > > +               buf[1] = shstk_base; > > +               buf[2] = shstk_size; > > +               return copy_to_user((unsigned long __user *)arg2, > > buf, > > +                                   sizeof(buf)); > > +       } > Other places in the kernel (e.g. the BPF subsystem) just > unconditionally use u64 instead of unsigned long to avoid having to > switch between different sizes. I wonder whether that would make > sense > here? Yes, that simplifies the code.  I will make that change. Yu-cheng From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on archive.lwn.net X-Spam-Level: X-Spam-Status: No, score=-5.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham autolearn_force=no version=3.4.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by archive.lwn.net (Postfix) with ESMTP id BFE587D071 for ; Wed, 11 Jul 2018 20:59:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388299AbeGKVFd (ORCPT ); Wed, 11 Jul 2018 17:05:33 -0400 Received: from mga04.intel.com ([192.55.52.120]:23333 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733021AbeGKVFd (ORCPT ); Wed, 11 Jul 2018 17:05:33 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Jul 2018 13:59:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,339,1526367600"; d="scan'208";a="66205693" Received: from 2b52.sc.intel.com ([143.183.136.52]) by orsmga003.jf.intel.com with ESMTP; 11 Jul 2018 13:59:22 -0700 Message-ID: <1531342544.15351.37.camel@intel.com> Subject: Re: [RFC PATCH v2 27/27] x86/cet: Add arch_prctl functions for CET From: Yu-cheng Yu To: Jann Horn Cc: the arch/x86 maintainers , "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , kernel list , linux-doc@vger.kernel.org, Linux-MM , linux-arch , Linux API , Arnd Bergmann , Andy Lutomirski , bsingharora@gmail.com, Cyrill Gorcunov , Dave Hansen , Florian Weimer , hjl.tools@gmail.com, Jonathan Corbet , keescook@chromiun.org, Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , ravi.v.shankar@intel.com, vedvyas.shanbhogue@intel.com Date: Wed, 11 Jul 2018 13:55:44 -0700 In-Reply-To: References: <20180710222639.8241-1-yu-cheng.yu@intel.com> <20180710222639.8241-28-yu-cheng.yu@intel.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-doc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org On Wed, 2018-07-11 at 12:45 -0700, Jann Horn wrote: > On Tue, Jul 10, 2018 at 3:31 PM Yu-cheng Yu > wrote: > > > > > > arch_prctl(ARCH_CET_STATUS, unsigned long *addr) > >     Return CET feature status. > > > >     The parameter 'addr' is a pointer to a user buffer. > >     On returning to the caller, the kernel fills the following > >     information: > > > >     *addr = SHSTK/IBT status > >     *(addr + 1) = SHSTK base address > >     *(addr + 2) = SHSTK size > > > > arch_prctl(ARCH_CET_DISABLE, unsigned long features) > >     Disable SHSTK and/or IBT specified in 'features'.  Return > > -EPERM > >     if CET is locked out. > > > > arch_prctl(ARCH_CET_LOCK) > >     Lock out CET feature. > > > > arch_prctl(ARCH_CET_ALLOC_SHSTK, unsigned long *addr) > >     Allocate a new SHSTK. > > > >     The parameter 'addr' is a pointer to a user buffer and > > indicates > >     the desired SHSTK size to allocate.  On returning to the caller > >     the buffer contains the address of the new SHSTK. > > > > arch_prctl(ARCH_CET_LEGACY_BITMAP, unsigned long *addr) > >     Allocate an IBT legacy code bitmap if the current task does not > >     have one. > > > >     The parameter 'addr' is a pointer to a user buffer. > >     On returning to the caller, the kernel fills the following > >     information: > > > >     *addr = IBT bitmap base address > >     *(addr + 1) = IBT bitmap size > > > > Signed-off-by: H.J. Lu > > Signed-off-by: Yu-cheng Yu > [...] > > > > diff --git a/arch/x86/kernel/cet_prctl.c > > b/arch/x86/kernel/cet_prctl.c > > new file mode 100644 > > index 000000000000..86bb78ae656d > > --- /dev/null > > +++ b/arch/x86/kernel/cet_prctl.c > > @@ -0,0 +1,141 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +/* See Documentation/x86/intel_cet.txt. */ > > + > > +static int handle_get_status(unsigned long arg2) > > +{ > > +       unsigned int features = 0; > > +       unsigned long shstk_base, shstk_size; > > + > > +       if (current->thread.cet.shstk_enabled) > > +               features |= GNU_PROPERTY_X86_FEATURE_1_SHSTK; > > +       if (current->thread.cet.ibt_enabled) > > +               features |= GNU_PROPERTY_X86_FEATURE_1_IBT; > > + > > +       shstk_base = current->thread.cet.shstk_base; > > +       shstk_size = current->thread.cet.shstk_size; > > + > > +       if (in_ia32_syscall()) { > > +               unsigned int buf[3]; > > + > > +               buf[0] = features; > > +               buf[1] = (unsigned int)shstk_base; > > +               buf[2] = (unsigned int)shstk_size; > > +               return copy_to_user((unsigned int __user *)arg2, > > buf, > > +                                   sizeof(buf)); > > +       } else { > > +               unsigned long buf[3]; > > + > > +               buf[0] = (unsigned long)features; > > +               buf[1] = shstk_base; > > +               buf[2] = shstk_size; > > +               return copy_to_user((unsigned long __user *)arg2, > > buf, > > +                                   sizeof(buf)); > > +       } > Other places in the kernel (e.g. the BPF subsystem) just > unconditionally use u64 instead of unsigned long to avoid having to > switch between different sizes. I wonder whether that would make > sense > here? Yes, that simplifies the code.  I will make that change. Yu-cheng -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f199.google.com (mail-pf0-f199.google.com [209.85.192.199]) by kanga.kvack.org (Postfix) with ESMTP id 7F7226B0008 for ; Wed, 11 Jul 2018 16:59:24 -0400 (EDT) Received: by mail-pf0-f199.google.com with SMTP id j25-v6so17018812pfi.20 for ; Wed, 11 Jul 2018 13:59:24 -0700 (PDT) Received: from mga06.intel.com (mga06.intel.com. [134.134.136.31]) by mx.google.com with ESMTPS id j190-v6si20319012pfb.211.2018.07.11.13.59.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 13:59:23 -0700 (PDT) Message-ID: <1531342544.15351.37.camel@intel.com> Subject: Re: [RFC PATCH v2 27/27] x86/cet: Add arch_prctl functions for CET From: Yu-cheng Yu Date: Wed, 11 Jul 2018 13:55:44 -0700 In-Reply-To: References: <20180710222639.8241-1-yu-cheng.yu@intel.com> <20180710222639.8241-28-yu-cheng.yu@intel.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: owner-linux-mm@kvack.org List-ID: To: Jann Horn Cc: the arch/x86 maintainers , "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , kernel list , linux-doc@vger.kernel.org, Linux-MM , linux-arch , Linux API , Arnd Bergmann , Andy Lutomirski , bsingharora@gmail.com, Cyrill Gorcunov , Dave Hansen , Florian Weimer , hjl.tools@gmail.com, Jonathan Corbet , keescook@chromiun.org, Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , ravi.v.shankar@intel.com, vedvyas.shanbhogue@intel.com On Wed, 2018-07-11 at 12:45 -0700, Jann Horn wrote: > On Tue, Jul 10, 2018 at 3:31 PM Yu-cheng Yu > wrote: > > > > > > arch_prctl(ARCH_CET_STATUS, unsigned long *addr) > > A A A A Return CET feature status. > > > > A A A A The parameter 'addr' is a pointer to a user buffer. > > A A A A On returning to the caller, the kernel fills the following > > A A A A information: > > > > A A A A *addr = SHSTK/IBT status > > A A A A *(addr + 1) = SHSTK base address > > A A A A *(addr + 2) = SHSTK size > > > > arch_prctl(ARCH_CET_DISABLE, unsigned long features) > > A A A A Disable SHSTK and/or IBT specified in 'features'.A A Return > > -EPERM > > A A A A if CET is locked out. > > > > arch_prctl(ARCH_CET_LOCK) > > A A A A Lock out CET feature. > > > > arch_prctl(ARCH_CET_ALLOC_SHSTK, unsigned long *addr) > > A A A A Allocate a new SHSTK. > > > > A A A A The parameter 'addr' is a pointer to a user buffer and > > indicates > > A A A A the desired SHSTK size to allocate.A A On returning to the caller > > A A A A the buffer contains the address of the new SHSTK. > > > > arch_prctl(ARCH_CET_LEGACY_BITMAP, unsigned long *addr) > > A A A A Allocate an IBT legacy code bitmap if the current task does not > > A A A A have one. > > > > A A A A The parameter 'addr' is a pointer to a user buffer. > > A A A A On returning to the caller, the kernel fills the following > > A A A A information: > > > > A A A A *addr = IBT bitmap base address > > A A A A *(addr + 1) = IBT bitmap size > > > > Signed-off-by: H.J. Lu > > Signed-off-by: Yu-cheng Yu > [...] > > > > diff --git a/arch/x86/kernel/cet_prctl.c > > b/arch/x86/kernel/cet_prctl.c > > new file mode 100644 > > index 000000000000..86bb78ae656d > > --- /dev/null > > +++ b/arch/x86/kernel/cet_prctl.c > > @@ -0,0 +1,141 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +/* See Documentation/x86/intel_cet.txt. */ > > + > > +static int handle_get_status(unsigned long arg2) > > +{ > > +A A A A A A A unsigned int features = 0; > > +A A A A A A A unsigned long shstk_base, shstk_size; > > + > > +A A A A A A A if (current->thread.cet.shstk_enabled) > > +A A A A A A A A A A A A A A A features |= GNU_PROPERTY_X86_FEATURE_1_SHSTK; > > +A A A A A A A if (current->thread.cet.ibt_enabled) > > +A A A A A A A A A A A A A A A features |= GNU_PROPERTY_X86_FEATURE_1_IBT; > > + > > +A A A A A A A shstk_base = current->thread.cet.shstk_base; > > +A A A A A A A shstk_size = current->thread.cet.shstk_size; > > + > > +A A A A A A A if (in_ia32_syscall()) { > > +A A A A A A A A A A A A A A A unsigned int buf[3]; > > + > > +A A A A A A A A A A A A A A A buf[0] = features; > > +A A A A A A A A A A A A A A A buf[1] = (unsigned int)shstk_base; > > +A A A A A A A A A A A A A A A buf[2] = (unsigned int)shstk_size; > > +A A A A A A A A A A A A A A A return copy_to_user((unsigned int __user *)arg2, > > buf, > > +A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A sizeof(buf)); > > +A A A A A A A } else { > > +A A A A A A A A A A A A A A A unsigned long buf[3]; > > + > > +A A A A A A A A A A A A A A A buf[0] = (unsigned long)features; > > +A A A A A A A A A A A A A A A buf[1] = shstk_base; > > +A A A A A A A A A A A A A A A buf[2] = shstk_size; > > +A A A A A A A A A A A A A A A return copy_to_user((unsigned long __user *)arg2, > > buf, > > +A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A sizeof(buf)); > > +A A A A A A A } > Other places in the kernel (e.g. the BPF subsystem) just > unconditionally use u64 instead of unsigned long to avoid having to > switch between different sizes. I wonder whether that would make > sense > here? Yes, that simplifies the code. A I will make that change. Yu-cheng