From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on archive.lwn.net X-Spam-Level: X-Spam-Status: No, score=-5.9 required=5.0 tests=DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by archive.lwn.net (Postfix) with ESMTP id 469157D048 for ; Mon, 18 Jun 2018 22:04:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755408AbeFRWEE (ORCPT ); Mon, 18 Jun 2018 18:04:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:43260 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755344AbeFRWEC (ORCPT ); Mon, 18 Jun 2018 18:04:02 -0400 Received: from mail-wm0-f41.google.com (mail-wm0-f41.google.com [74.125.82.41]) (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 AA2F5208B7 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-f41.google.com with SMTP id 69-v6so18342315wmf.3 for ; Mon, 18 Jun 2018 15:04:01 -0700 (PDT) X-Gm-Message-State: APt69E2SezL0xY1tRUkDZs7M2k4PVHYG0G/x1OB4epQw4jW5z8cAn3mq p7F9KCRW5k/yvNpJZ93jqnXU5avZ1dDajO06Hfyyng== X-Google-Smtp-Source: ADUXVKJE5TBUk6GBto2ujStmxmBQTLmkrI2HejpsnH4zvQphIX7MFVYLIYx5krYDUNHV4/g1mGBWX/ejSuauKL+yOyg= 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-doc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-doc@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 -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html