Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2830464imm; Wed, 3 Oct 2018 09:47:35 -0700 (PDT) X-Google-Smtp-Source: ACcGV62O9liongP9BHPDwKQ26nHBzGcb7l3vG8e7YlkTHFCLBgsYBxaf+27S29WtVRW8efMl3lsD X-Received: by 2002:a62:1a92:: with SMTP id a140-v6mr2469566pfa.219.1538585255409; Wed, 03 Oct 2018 09:47:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538585255; cv=none; d=google.com; s=arc-20160816; b=KqFDslDGn4/HtG2bZ7gj6MXjOXTH+CR76P7kWClGe/Sk8q3NS9VmaOwjzHOADJOxWi cudLrvcmMY84v/Dl6Uax3WKujmu6c8kyVwdO4II0B1SGdd9tgr3e5pcp5Fou3uKUf0tw 4wYjRCpdrOFe4N//33hi0iuvB+DDQwVjcr/4jOlYP5f66lWgjOXm+JUR5QMjTlPGmow9 mWtTIVCIH4PT0tfq6FVVtJA1F9EKbtaxOG6n3pbUeW7LuWIyudj5XrGkYp7RMwbSsXGi nO+bSLzwGgaL1J7we3OHcEKw9zjmJEdLheOyIS3JVYdzm9+yJvGV0Up+gi8kK1Xti0j6 3jDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=ZCuVAz2UKWZbDQlj+DhBSHMUDTBtXWc3KclL+d5oEp8=; b=ECRXtJ3jpWtnAl9LA6QkkUk5PrZ357adIKhtHUfoKVnh43Ko6v2kGEjIq5+dViM2XR S/i35pTEKJuxGlJhykq6WPS8vYhE9S110YP8ZyJfZh3iGfkFcNlnsomjCT+6cczF7l1u ytl8SrkagsggfoGxsUeMOwAKgMxx/LbCWhjLH349oaUduNE0tsSGMpYYPSRiUmJbBA51 M5NL2GqiYbv9q7jQczbIEH/3ZPMlQ+xSYmHJSk0BcLLFHBG4qye4UJS150jgYdEZP5PL E0jwA2kqkAjrjxAtogt8Vlec/UNVw/G57z9PbqmirhWdk0wsjmunIrQUP5AaWC+w7oZN VB/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tWrNoA1A; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l22-v6si2128557pfj.188.2018.10.03.09.47.19; Wed, 03 Oct 2018 09:47:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tWrNoA1A; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727201AbeJCXgY (ORCPT + 99 others); Wed, 3 Oct 2018 19:36:24 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:35189 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726892AbeJCXgY (ORCPT ); Wed, 3 Oct 2018 19:36:24 -0400 Received: by mail-ot1-f67.google.com with SMTP id j9-v6so6239706otl.2 for ; Wed, 03 Oct 2018 09:47:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZCuVAz2UKWZbDQlj+DhBSHMUDTBtXWc3KclL+d5oEp8=; b=tWrNoA1AaCshsdvkFKfX3FkMtSN5/EZQqhuCMAnLR22viFAgUpiPNtaAiBvYNTVXoR chcjGN1214MorPx4YPkrsbZPCjP2niR1StJp8qmh41wxc3f3IVAwVHw1EobqJAU0pisZ NhZjIr5QMUMMZSw3bAe/QTPo4RHY9b0nn1QOl7+0bT6BPaTEsu2uRh+xRqI4wiNoweAk pUD0NCZBNDZUr0tp2W4NkJi0uX5A+hRgtZJE3pjMz1QT8lm9U9NrNC4K/HfNFkLscC47 iw8llBF8lkPbw+/7Dqf28uUFDK+gIylLalusP78BAsJYgWzxzLR0Kysqbw+3fbl/hzzM PigA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZCuVAz2UKWZbDQlj+DhBSHMUDTBtXWc3KclL+d5oEp8=; b=QqvUiwdTBiu3rluGzEHomZchInCEPgJmRH2u76qfCIIx+Ky3l+iGY4DDVwWA1I/0hr tbpGPwfpzpfIZsM0ni2IPwEEgP4vRZajqegMjvCjF7tQ5V/QyG/ge10OiYU3i3C8bu03 XFOTb+0jIEPU5Et0ugGy1PmLshW1nC3gbZIMOu760+ASS45RA7kKw8EOWmv3a5SF8xlY RWIPI3+YG3Xy3u2JaUMXR7BYWpEGVuNPKd+wQLJ1glJB9L7vJ5a0MH49B1AyOKUe8Kbr Z2bmILBp6OJzJdw8A/z9EIGq8j91OmalZ+97VAliQXVGG7JOnQV7X5OSGbrnBdYACJLe xgaw== X-Gm-Message-State: ABuFfohSbFVlAIxe8OJaPHIJ4ZYjKyhWfKbEF3QyZgzphmjJFwXluR93 P7ioBLEze+J2DsrBr3oW2w3fHzdtd4dH05IFZgroFg== X-Received: by 2002:a9d:5733:: with SMTP id p48mr1250542oth.292.1538585232481; Wed, 03 Oct 2018 09:47:12 -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 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; > +}