From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-f65.google.com ([209.85.210.65]:43385 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726862AbeJCXgY (ORCPT ); Wed, 3 Oct 2018 19:36:24 -0400 Received: by mail-ot1-f65.google.com with SMTP id e21-v6so6223099otk.10 for ; Wed, 03 Oct 2018 09:47:13 -0700 (PDT) MIME-Version: 1.0 References: <20180921150351.20898-1-yu-cheng.yu@intel.com> <20180921150351.20898-21-yu-cheng.yu@intel.com> In-Reply-To: <20180921150351.20898-21-yu-cheng.yu@intel.com> From: Jann Horn Date: Wed, 3 Oct 2018 18:46:46 +0200 Message-ID: Subject: Re: [RFC PATCH v4 20/27] x86/cet/shstk: Signal handling for shadow stack Content-Type: text/plain; charset="UTF-8" Sender: linux-arch-owner@vger.kernel.org List-ID: To: yu-cheng.yu@intel.com 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 , Balbir Singh , Cyrill Gorcunov , Dave Hansen , Florian Weimer , hjl.tools@gmail.com, Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , rdunlap@infradead.org, ravi.v.shankar@intel.com, vedvyas.shanbhogue@intel.com Message-ID: <20181003164646.lOwj5Th9Ju6gX5FOlVEt3hU_-KYEfAM75wNZ_IKOAyY@z> On Fri, Sep 21, 2018 at 5:09 PM Yu-cheng Yu wrote: > When setting up a signal, the kernel creates a shadow stack > restore token at the current SHSTK address and then stores the > token's address in the signal frame, right after the FPU state. > Before restoring a signal, the kernel verifies and then uses the > restore token to set the SHSTK pointer. [...] > +#ifdef CONFIG_X86_64 > +static int copy_ext_from_user(struct sc_ext *ext, void __user *fpu) > +{ > + void __user *p; > + > + if (!fpu) > + return -EINVAL; > + > + p = fpu + fpu_user_xstate_size + FP_XSTATE_MAGIC2_SIZE; > + p = (void __user *)ALIGN((unsigned long)p, 8); > + > + if (!access_ok(VERIFY_READ, p, sizeof(*ext))) > + return -EFAULT; > + > + if (__copy_from_user(ext, p, sizeof(*ext))) > + return -EFAULT; Why do you first manually call access_ok(), then call __copy_from_user() with the same size? Just use "if (copy_from_user(ext, p, sizeof(*ext)))" (without underscores) and get rid of the access_ok(). > + if (ext->total_size != sizeof(*ext)) > + return -EINVAL; > + return 0; > +} > + > +static int copy_ext_to_user(void __user *fpu, struct sc_ext *ext) > +{ > + void __user *p; > + > + if (!fpu) > + return -EINVAL; > + > + if (ext->total_size != sizeof(*ext)) > + return -EINVAL; > + > + p = fpu + fpu_user_xstate_size + FP_XSTATE_MAGIC2_SIZE; > + p = (void __user *)ALIGN((unsigned long)p, 8); > + > + if (!access_ok(VERIFY_WRITE, p, sizeof(*ext))) > + return -EFAULT; > + > + if (__copy_to_user(p, ext, sizeof(*ext))) > + return -EFAULT; Same as above. > + return 0; > +}