Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4562005imm; Mon, 18 Jun 2018 17:53:35 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIw19NtBB16Juic6KWTaeC8EpngVxZK+ttLC1KElQSlNsJaWvqY8pFEoNHUsyXiV5opiH11 X-Received: by 2002:a17:902:b28c:: with SMTP id u12-v6mr16117727plr.68.1529369615010; Mon, 18 Jun 2018 17:53:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529369614; cv=none; d=google.com; s=arc-20160816; b=kctrFUAYQkHQE1MsvxMsuJ9NWiTRQQx/MGjZMDdTSi1PdnTFy73ZvqP9TRfWsX4NMa oSdQ0aay50Wvu0zz17gs+UjXjHPmsuLuCwL8CaX0uhqeFEKre2eFHVwzNqAWcDpQ4z7g OMuxRk2SR4dcUH1AgBav3xxQOwlTOEsPwH/pMhE9N7ftD716Nh2s/vioyBQ9NQfHoRKC SbNkLuL7qhr5jFStt8iCdJ+1KWCSbubW6v1ZGoFyVWQEl/P6lf6ybD5TyKv9oCJgSyGk gHezCj7oeRSFj7d+odC6kclrnt15cENL2QRGhl2KATh/2uCZVpxavNcKPmcP7IWX9W1d 6c1g== 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:dkim-signature :arc-authentication-results; bh=H/DiTEMRqdssEpzUJiBr2tdwek6sh/YMggOPpeO9quQ=; b=bASfsb5RHIChawJEY58LMZJKDTspEb5jEIwr+gtuelzbKsTF22HxmMetTAaPKkspCu ZzEgU/hv8tcjtnqkQHBw6qbyPCFrI3RUwHNlyZ9NY3nGbio6ZRigS+HF8XtVT8hpyeUH 3OQ8bwBFfTPsHvUuFOm7QCo/xPY32xok8tKGCwJOeQBtxAxdsbQbjDF/ngXFJmMkb13Z eAgEq+23Y4pAMAhvYIiatBVvNLkI0Fc1KAYapxSWN3Iaa6MqNPxO2T+lKn6HqYwZSOWn OZ1psm3ikWe+9Tt5C9XEA9O64PJXfaMp5pJCjhI0tWi/KCc72QCKfPhcgyG/MgFokk/D 0EFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=AbfwXImO; dkim=fail header.i=@chromium.org header.s=google header.b=mZk7F++Z; 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=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d26-v6si13133524pge.330.2018.06.18.17.53.20; Mon, 18 Jun 2018 17:53:34 -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=fail header.i=@google.com header.s=20161025 header.b=AbfwXImO; dkim=fail header.i=@chromium.org header.s=google header.b=mZk7F++Z; 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=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S937153AbeFSAwg (ORCPT + 99 others); Mon, 18 Jun 2018 20:52:36 -0400 Received: from mail-yb0-f194.google.com ([209.85.213.194]:36164 "EHLO mail-yb0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S937115AbeFSAwb (ORCPT ); Mon, 18 Jun 2018 20:52:31 -0400 Received: by mail-yb0-f194.google.com with SMTP id x128-v6so6671596ybg.3 for ; Mon, 18 Jun 2018 17:52:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=H/DiTEMRqdssEpzUJiBr2tdwek6sh/YMggOPpeO9quQ=; b=AbfwXImOalCbEkZeRgEoEbzggiSQv5iPwZN1hIRqGfd93s/jLgVkXz3V/fIq91QUFR t8TOffKl/Iglde9H5kTQ6Rbe3IkBLpRDw30KNtFVYVkfc29eD0gMOeTqCkzKf3XiY3dY UBeqsWIuNJtNg48sMjDkV3EnN+hsie5o2z4lPrRBfwZ56SOytk22qg98XT07NDXDfr3u vkwgeW91X+Y4JwmhDYkuL+m6ZkMW1WWBSiTuLNl+Aegv9ta+y1nJRnbgFuG9GiwWEDBr JSsin/VWmcgAq2z4rBt+//4v79hMuAMjZhvgRsuDrFmVESeKw8DGUEf4B0q+RaCTzoX1 QP6w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=H/DiTEMRqdssEpzUJiBr2tdwek6sh/YMggOPpeO9quQ=; b=mZk7F++ZgH3eK0HuVqXwHbBiprN6ofWPLknwlqifYEgsC4aUC2jl9Xe6y//qp1b+Ot Up2R2J0YVWNsyAeZQwpfomsVkXa5oyZ+Tk+DganTxcgEkrgiEsm9/Cy9bEdLezQK0j3i GflP+cqDjc9YVWlf5mX8hRxFEO0aojDMjxZWI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=H/DiTEMRqdssEpzUJiBr2tdwek6sh/YMggOPpeO9quQ=; b=uVsWcpxgc2nwSVt5k58pRVGUzA/d7AUYpWU2QkQdYTqSBtylwwKIBfzfjHFb6Xq6zn RyDwLiUpgMW5PMIAQb0xXpDDjKMISZiMXaQ01L4XliazchPU5KkudiEn/YTki6MBj3kn /iyhScDqAVtwAN/st9TXa5dfw209Y77wDHElVYTEPs9PxfcPztgvOUJzyGv1y5I9e0Pd /rj1SVBrwTEDUYtqE9KZuGJMPeuJovxVgcE5DY5QgT5gA4M4EolL2VHURX9zCzwHH7gn q5xh7lHcSz4JfCesXyN6R739GOaa6XqIOREw+9rRcINcxLC9WIix+A8F4+DVe97YijI/ Webg== X-Gm-Message-State: APt69E1f06B6AbBE7AP5eIJB2gZD/SM0N7V81FmQh/9KcysLB1mZfLGP LnNqDrUw64WDnYnGoz8IhrxoNJnb9Iqu4tJ4AhTX00Sg X-Received: by 2002:a25:be41:: with SMTP id d1-v6mr7383677ybm.309.1529369550987; Mon, 18 Jun 2018 17:52:30 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a25:d6c5:0:0:0:0:0 with HTTP; Mon, 18 Jun 2018 17:52:29 -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: Kees Cook Date: Mon, 18 Jun 2018 17:52:29 -0700 X-Google-Sender-Auth: W3E9QM-W4iYEUT9vp0oMZ-XjsmE Message-ID: Subject: Re: [PATCH 06/10] x86/cet: Add arch_prctl functions for shadow stack To: Andy Lutomirski Cc: "H. J. Lu" , Thomas Gleixner , 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, Florian Weimer 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 Mon, Jun 18, 2018 at 3:03 PM, Andy Lutomirski wrote: > 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? Adding Florian to CC, but if something gets CET enabled, it really shouldn't have a way to turn it off. If there's a way to turn it off, all the ROP research will suddenly turn to exactly one gadget before doing the rest of the ROP: turning off CET. Right now ROP is: use stack-pivot gadget, do everything else. Allowed CET to turn off will just add one step: use CET-off gadget, use stack-pivot gadget, do everything else. :P Following Linus's request for "slow introduction" of new security features, likely the best approach is to default to "relaxed" (with a warning about down-grades), and allow distros/end-users to pick "forced" if they know their libraries are all CET-enabled. -Kees -- Kees Cook Pixel Security