Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp381425imm; Thu, 7 Jun 2018 21:10:49 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJNKSMcN9OhV+BqnyAnPriS/kJGe3foSL/9nSpApapvfk6UAUawFxp+MoZI2HFU/+lAUPa/ X-Received: by 2002:a17:902:3c5:: with SMTP id d63-v6mr4743109pld.163.1528431049414; Thu, 07 Jun 2018 21:10:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528431049; cv=none; d=google.com; s=arc-20160816; b=ptDq424m8gi3esSey2LvsVcW737k06W0X4bWqKvtYXht68FbOjPyR0J0d3tWvARrNK L8eEPzaSvq9o9jtATAeq6ugG2Glz5ygF3f90PFZ8rWOUV3RNHq44NUWY5Bmeit5SsNwJ TSPkjU9/osrTvZTuEcTCihlTn0w9QP5pqGKn2MrdzK2kyEZO5ZPvtMxE6ZOth7/ONm7+ HXT9vvkhpn9OHD71uvmisphDotXo1XhCE17DyNVNzOgUMn917f1YI9blJgiHu5XWEAXw 6Y42W8NNSnOO3Zt8DSZQw/AZrsIFt5SLgbwZY5Q2x0rc9tbFJwDY+4eB2MXyFrb1lvAw ZqJw== 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 :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=3YxVFb3V959wocR3NdoEsznAFl1SruV1TEp0gMLHw34=; b=mFtUvrcQfsRbZmGDHi+iHE2JL85LpGLHXxpjHWP5Wl+a73fKQP+Xhq5deNJqueeMex xwQrNpIW/01AiN4tUIWN48u7wCwOki6s1QF19pqJ9BM7PyS5EOXMaH9fTzb42b6eXnPb wMF8iB48JE2IXMJGEiCagdvAOCHJZFO48SDxPEG6/V+nvXvaI40ElPVJg/CBk4IU8xba qP8TwKtKhNoc1eSEzegnzx/smyY8WrbhhSUHvoxvT44V+ACA+5FgvvTlQMd+OPQ2yKPE lmzEIOkd0J6TFUZH7H9knS0hOldfCWFnv6RSEy9Rmcrpi4GgWpR02A2Ic4fovRc6ZR1x 4QWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=J/OmBTnO; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p14-v6si5175029pgv.255.2018.06.07.21.10.34; Thu, 07 Jun 2018 21:10:49 -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=@gmail.com header.s=20161025 header.b=J/OmBTnO; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751043AbeFHEKG (ORCPT + 99 others); Fri, 8 Jun 2018 00:10:06 -0400 Received: from mail-ot0-f193.google.com ([74.125.82.193]:41109 "EHLO mail-ot0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750773AbeFHEJ7 (ORCPT ); Fri, 8 Jun 2018 00:09:59 -0400 Received: by mail-ot0-f193.google.com with SMTP id d19-v6so8605144oti.8; Thu, 07 Jun 2018 21:09:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=3YxVFb3V959wocR3NdoEsznAFl1SruV1TEp0gMLHw34=; b=J/OmBTnOsI6EA82c9ZlA8BSibgI2emfj92vWvImiE1022bJBtzJ2+0HJaJ0aTrunZU 1LcO64PE9PTntTW+8ExaW+mpDUaLrVZqvwQd0/7h65Ao6Tz0DlUOHgmnT9E5u9I/7yMU yC+o7s/kf0DoA1CYz3VwIGciVXrbDEsg3fIMGEUXBpx49SmavRnMemGQF8rCfJ/6+GQV JzsmqOu7UI159/JW2qRsGFfPNAFZqhVQAEPOb951kXNiLUdI5Ejir1h8R3mQw/4hOhLl xE1dd8IVXIetnhCSCOfro7OMqAsV6x4xyN6dBDW+Z/Aah09f/6xdXuJYUwArl9sYyS6s MeUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=3YxVFb3V959wocR3NdoEsznAFl1SruV1TEp0gMLHw34=; b=HeWrr/MHSO4SVjKC0HBT1kZzAa85Ae1VIIOh3AxUM0UkjOvJf78E1k8+3TA+4QCsnD EMD32Tyi7pbjdmt0ig+Jmi2MethBEFMv2E/PP7GmzXnu1TufzJIH/rJjK1y9aW7JLYXv qOVJyxd8RuEv1QNv6mKZUNlTvHv1NVZl7jAAMN8Q49EwiHyK4hlEiErk1P6DUJzVb9Kl 2KWuKui9YuFCZc/z99M1gFzMuebos1YMevijpSFKoUzz71qWainKizjm0PPrKHM/5nRw /pETdX2UiBtv7QtSOdAnwtuwdPTe6Mvxr2yhGwtuieHiXMidfKErpn/xrlOPK7vuhpSV B89Q== X-Gm-Message-State: APt69E13RD3Q5hmKNFfFPbIe13vhg3sAOp5wOXX+BNvpADaWyDQrerdp fX2AkQQEW0c+Xef4yodb9vErNiwHe0tUJ4kPnIY= X-Received: by 2002:a9d:322f:: with SMTP id t47-v6mr2912567otc.7.1528430998903; Thu, 07 Jun 2018 21:09:58 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a4a:7019:0:0:0:0:0 with HTTP; Thu, 7 Jun 2018 21:09:58 -0700 (PDT) In-Reply-To: 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> From: "H.J. Lu" Date: Thu, 7 Jun 2018 21:09:58 -0700 Message-ID: Subject: Re: [PATCH 06/10] x86/cet: Add arch_prctl functions for shadow stack To: Andy Lutomirski Cc: 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 4:01 PM, Andy Lutomirski wrote: > 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*. It is to prevent malicious code from disabling CET. > (Also, shouldn't the vDSO itself be marked as supporting CET?) No. vDSO is loaded by kernel. vDSO in CET kernel is CET compatible. -- H.J.