Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp168398imm; Thu, 7 Jun 2018 16:02:19 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLqXfhId+GhoAscR9pv9eteDvvEo3fWHytMB3WwN07lf+9dQyYP+tCTEzppX+tKNvEFyKzr X-Received: by 2002:a62:859c:: with SMTP id m28-v6mr3516770pfk.42.1528412539518; Thu, 07 Jun 2018 16:02:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528412539; cv=none; d=google.com; s=arc-20160816; b=cDsCbTECTX08fiVFgbR+ny6XHPf1LoeI3EOpYssf4KRFoHObZH9GcorUjCvdy7jbC4 WCoYiyWol8aXCs6zv/JmVonhJrIgfpBVHc5cioP5tdo1YAA7vg88i2RsCdR/45mrhMFa JronTniShUKDDNPaJkktwsLixU8Fb3NTtxV2SF2pK5pRu4/mNCk8pRSUvyv448bXgxAn q9XA3beff9wAwM+14wedMrGlPhmhaLqLb65DuCQhE52UDmCI5Mo4tobzf1oh+ac2fdS1 TfjziRzgN3tc409HAP1T9nzFtW3Wmmt2OR3Cww8qRcY88q/NlIBYXLKF+c1nkyglmN4a KtLA== 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 :arc-authentication-results; bh=U9vx0viSjdmcLgpXn/FC0SrR4OX1nDIihM/mnlkZB+w=; b=RLDC/yLJsCmWgCQngRGll/u83wky9c0seUeDRGhvH1fsLoEeRsiqow8TuwByuswhzM uj9Pf1DTY7bBNbw8TjpD3FfR7WGfOpsAWS0PuNww3QSjXGxckSILmZKi9quo15JZfi8R EvNoSxA6qUBcbTZ6A5fJUb8s3x+hYUFeyuzvCe1YDDJtBhQWiHveqpu408ism5gAfjtJ CIC2Uxo3dydaM5ByDCkiEeSYxlkzZJkNHJDzjTzsWDF1xmTsPl1RErf/rn7/di10s5b+ 8D1ZgRVWpmuuVSvVSQ1AVYOXFlN9ubLOMUqi937nD09ObjlbAJm3PSe+mZstc2bBOW69 6RYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cMLV4XiB; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m39-v6si55221162plg.371.2018.06.07.16.02.05; Thu, 07 Jun 2018 16:02:19 -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=@kernel.org header.s=default header.b=cMLV4XiB; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752178AbeFGXBj (ORCPT + 99 others); Thu, 7 Jun 2018 19:01:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:33810 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751990AbeFGXBh (ORCPT ); Thu, 7 Jun 2018 19:01:37 -0400 Received: from mail-wr0-f169.google.com (mail-wr0-f169.google.com [209.85.128.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 07F35208A3 for ; Thu, 7 Jun 2018 23:01:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1528412497; bh=RRA6TxHfG0MrgJ9oyYoyxLRdoG+OMFsQ5PeUsRf7u9I=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=cMLV4XiBhqD7KSaifHoP+0aX7NomKAGLZsl26zYMJEMS77Xd34/L9hVPGDo4mMtWU 7i055cByUOohu1CXkhFl4bcoTP1lG25OLMs16CGH4C5ib4j9xKQ/RDaSpb/5HyO09v EOrPw9qO08x/kUfJTDD9AnFd7ZRBP9HmXS1exaBk= Received: by mail-wr0-f169.google.com with SMTP id v13-v6so11453469wrp.13 for ; Thu, 07 Jun 2018 16:01:36 -0700 (PDT) X-Gm-Message-State: APt69E39KQi8NYwPP8G1puN3yBZgtt3DHfbzAA4FsNwqE0B3HZbamyvF KUi5QEtzb05SyCpwUjkeIaPQyGdsDanUNxC8yzXzEA== X-Received: by 2002:adf:b1ca:: with SMTP id r10-v6mr2919455wra.221.1528412495562; Thu, 07 Jun 2018 16:01:35 -0700 (PDT) MIME-Version: 1.0 References: <20180607143807.3611-1-yu-cheng.yu@intel.com> <20180607143807.3611-7-yu-cheng.yu@intel.com> <1528403417.5265.35.camel@2b52.sc.intel.com> In-Reply-To: From: Andy Lutomirski Date: Thu, 7 Jun 2018 16:01:23 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 06/10] x86/cet: Add arch_prctl functions for shadow stack To: "H. J. Lu" Cc: Andrew Lutomirski , Yu-cheng Yu , LKML , linux-doc@vger.kernel.org, Linux-MM , linux-arch , X86 ML , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , "Shanbhogue, Vedvyas" , "Ravi V. Shankar" , Dave Hansen , Jonathan Corbet , Oleg Nesterov , Arnd Bergmann , mike.kravetz@oracle.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 Thu, Jun 7, 2018 at 3:02 PM H.J. Lu wrote: > > On Thu, Jun 7, 2018 at 2:01 PM, Andy Lutomirski wrote: > > On Thu, Jun 7, 2018 at 1:33 PM Yu-cheng Yu wrote: > >> > >> On Thu, 2018-06-07 at 11:48 -0700, Andy Lutomirski wrote: > >> > On Thu, Jun 7, 2018 at 7:41 AM Yu-cheng Yu wrote: > >> > > > >> > > The following operations are provided. > >> > > > >> > > ARCH_CET_STATUS: > >> > > return the current CET status > >> > > > >> > > ARCH_CET_DISABLE: > >> > > disable CET features > >> > > > >> > > ARCH_CET_LOCK: > >> > > lock out CET features > >> > > > >> > > ARCH_CET_EXEC: > >> > > set CET features for exec() > >> > > > >> > > ARCH_CET_ALLOC_SHSTK: > >> > > allocate a new shadow stack > >> > > > >> > > ARCH_CET_PUSH_SHSTK: > >> > > put a return address on shadow stack > >> > > > >> > > ARCH_CET_ALLOC_SHSTK and ARCH_CET_PUSH_SHSTK are intended only for > >> > > the implementation of GLIBC ucontext related APIs. > >> > > >> > Please document exactly what these all do and why. I don't understand > >> > what purpose ARCH_CET_LOCK and ARCH_CET_EXEC serve. CET is opt in for > >> > each ELF program, so I think there should be no need for a magic > >> > override. > >> > >> CET is initially enabled if the loader has CET capability. Then the > >> loader decides if the application can run with CET. If the application > >> cannot run with CET (e.g. a dependent library does not have CET), then > >> the loader turns off CET before passing to the application. When the > >> loader is done, it locks out CET and the feature cannot be turned off > >> anymore until the next exec() call. > > > > Why is the lockout necessary? If user code enables CET and tries to > > run code that doesn't support CET, it will crash. I don't see why we > > need special code in the kernel to prevent a user program from calling > > arch_prctl() and crashing itself. There are already plenty of ways to > > do that :) > > On CET enabled machine, not all programs nor shared libraries are > CET enabled. But since ld.so is CET enabled, all programs start > as CET enabled. ld.so will disable CET if a program or any of its shared > libraries aren't CET enabled. ld.so will lock up CET once it is done CET > checking so that CET can't no longer be disabled afterwards. Yeah, I got that. No one has explained *why*. (Also, shouldn't the vDSO itself be marked as supporting CET?)