Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4433601imm; Mon, 18 Jun 2018 15:06:07 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIEEcGBJZhch2urn8QgPTQ1ax9K3UIZ6Bwuph2A5+wP94t70fX3e4eFshOrKGnHxnwXzVkF X-Received: by 2002:a17:902:6f0f:: with SMTP id w15-v6mr15546190plk.216.1529359567848; Mon, 18 Jun 2018 15:06:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529359567; cv=none; d=google.com; s=arc-20160816; b=Rt+dry4HokpBI1K0T5/6N3hcgSc/GIfS6PvsUOK7HcBsoziAMNwj4vxfZRI8iAP00t i26S3KzurTBU4GwK6f3HfsrRkJyy3lBlErYJprt2iDqg9Bo/5KtvMsu2RBWOeSITd18a vht1/TfuiSU7HAWEhmtW5NBVo5e8kcjIQ4aCQSV6F/VVzNVuh3+p10MNz+kIH0A264r8 h3zAXZ7da6UTE01U/4E4nOMb2L8ZrY25iqZVDocp81yJDJJ9OpbD4MGdpPDSD2/jX0wd cuqlt5TUm5kFPNhtL657ZFhNPsDFjQsOKuE06jhSNd4BslhD6ZfWgtRLHlayolOBkvUo IyxQ== 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=i1abpwxjnRPkjKFZ1R6KQvAMOifrs8f+yLtUROMoJyk=; b=JVsdBbJ1vNoE93fsCfVwJUFPl/MMHGjbdSv3MiXxyrXLb3I/Z/0xNMiI2ASGw0+TKx a1NIJmXRXKLy+ZARK+vS3c38NdkGpfSZuduiGKpVoL60n5Z1XqVM76COur0kuWHPKRds gIHrtL36ch/9KI7E/duE05v4jhuC5NwoOISVu4PBitBhLSsXVNdpCCMIh98FnsWZ5fsR 9r3PMT88iXS/jbLHAgy+4BTPchcy6UOmGzJdbmN4g/2OAz+yyo2fyUeOZcTrJynzWwLq g3xYP3TAC61oG4MWXiBeEPjPyv8zNYjPz8slF+A+wIIKnHvXyAiGAo/QOY+B5kInyagq zFxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="xviTRG/o"; 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 l13-v6si14670474pff.261.2018.06.18.15.05.53; Mon, 18 Jun 2018 15:06:07 -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="xviTRG/o"; 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 S935610AbeFRWEF (ORCPT + 99 others); Mon, 18 Jun 2018 18:04:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:43262 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755347AbeFRWEC (ORCPT ); Mon, 18 Jun 2018 18:04:02 -0400 Received: from mail-wm0-f44.google.com (mail-wm0-f44.google.com [74.125.82.44]) (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 ABDAC208B9 for ; Mon, 18 Jun 2018 22:04:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1529359442; bh=EgMUHLSiJ4/XpvIZGrIqYv8hCWRH6gxKr0Dd3LaUnx4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=xviTRG/o+1lvnwrUfjTKvdXhaIibw+YBMMPZT7dGST20FCItAhfxPUHgznhp6YvPf zRtqfTAp0RsEP+KhQ4nUhsnbnlS7p4AM74tWSF3zq9R/57geVTgHXVGv6NerF+ggi9 H0E+hHl9E9MzI6iTZOKaRX8oqNdleEAzOZGtX3ZQ= Received: by mail-wm0-f44.google.com with SMTP id j15-v6so18431128wme.0 for ; Mon, 18 Jun 2018 15:04:01 -0700 (PDT) X-Gm-Message-State: APt69E1dNmf8G0upOOTp6mjAFGqOgHrhKZSFWbefEcIaVyDxGoXUhh3f dCc6EN+HBpeazV0gXEBhv5iB+PEvW4DWnAKIHrKO/Q== X-Received: by 2002:a1c:34c9:: with SMTP id b192-v6mr10383654wma.21.1529359439972; Mon, 18 Jun 2018 15:03:59 -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: Mon, 18 Jun 2018 15:03:48 -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" , Kees Cook Cc: Thomas Gleixner , Andrew Lutomirski , Yu-cheng Yu , LKML , linux-doc@vger.kernel.org, Linux-MM , linux-arch , X86 ML , "H. Peter Anvin" , 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 Tue, Jun 12, 2018 at 12:34 PM H.J. Lu wrote: > > On Tue, Jun 12, 2018 at 11:59 AM, Thomas Gleixner wrote: > > On Tue, 12 Jun 2018, H.J. Lu wrote: > >> On Tue, Jun 12, 2018 at 9:34 AM, Andy Lutomirski wrote: > >> > On Tue, Jun 12, 2018 at 9:05 AM H.J. Lu wrote: > >> >> On Tue, Jun 12, 2018 at 9:01 AM, Andy Lutomirski wrote: > >> >> > On Tue, Jun 12, 2018 at 4:43 AM H.J. Lu wrote: > >> >> >> On Tue, Jun 12, 2018 at 3:03 AM, Thomas Gleixner wrote: > >> >> >> > That works for stuff which loads all libraries at start time, but what > >> >> >> > happens if the program uses dlopen() later on? If CET is force locked and > >> >> >> > the library is not CET enabled, it will fail. > >> >> >> > >> >> >> That is to prevent disabling CET by dlopening a legacy shared library. > >> >> >> > >> >> >> > I don't see the point of trying to support CET by magic. It adds complexity > >> >> >> > and you'll never be able to handle all corner cases correctly. dlopen() is > >> >> >> > not even a corner case. > >> >> >> > >> >> >> That is a price we pay for security. To enable CET, especially shadow > >> >> >> shack, the program and all of shared libraries it uses should be CET > >> >> >> enabled. Most of programs can be enabled with CET by compiling them > >> >> >> with -fcf-protection. > >> >> > > >> >> > If you charge too high a price for security, people may turn it off. > >> >> > I think we're going to need a mode where a program says "I want to use > >> >> > the CET, but turn it off if I dlopen an unsupported library". There > >> >> > are programs that load binary-only plugins. > >> >> > >> >> You can do > >> >> > >> >> # export GLIBC_TUNABLES=glibc.tune.hwcaps=-SHSTK > >> >> > >> >> which turns off shadow stack. > >> >> > >> > > >> > Which exactly illustrates my point. By making your security story too > >> > absolute, you'll force people to turn it off when they don't need to. > >> > If I'm using a fully CET-ified distro and I'm using a CET-aware > >> > program that loads binary plugins, and I may or may not have an old > >> > (binary-only, perhaps) plugin that doesn't support CET, then the > >> > behavior I want is for CET to be on until I dlopen() a program that > >> > doesn't support it. Unless there's some ABI reason why that can't be > >> > done, but I don't think there is. > >> > >> We can make it opt-in via GLIBC_TUNABLES. But by default, the legacy > >> shared object is disallowed when CET is enabled. > > > > That's a bad idea. Stuff has launchers which people might not be able to > > change. So they will simply turn of CET completely or it makes them hack > > horrible crap into init, e.g. the above export. > > > > Give them sane kernel options: > > > > cet = off, relaxed, forced > > > > where relaxed allows to run binary plugins. Then let dlopen() call into the > > kernel with the filepath of the library to check for CET and that will tell > > you whether its ok or or not and do the necessary magic in the kernel when > > CET has to be disabled due to a !CET library/application. > > > > That's also making the whole thing independent of magic glibc environment > > options and allows it to be used all over the place in the same way. > > This is very similar to our ARCH_CET_EXEC proposal which controls how > CET should be enforced. But Andy thinks it is a bad idea. > I do think it's a bad idea to have a new piece of state that survives across exec(). It's going to have nasty usability problems and nasty security problems. We may need a mode by which glibc can turn CET *back off* even after a program had it on if it dlopens() an old binary. Or maybe there won't be demand. I can certainly understand why the CET_LOCK feature is there, although I think we need a way to override it using something like ptrace(). I'm not convinced that CET_LOCK is really needed, but someone who understand the thread model should chime in. Kees, do you know anyone who has a good enough understanding of usermode exploits and how they'll interact with CET? --Andy