Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp964806imm; Fri, 8 Jun 2018 07:58:53 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLs/KKg0fCSCXTKDwwJVjXiBP2uqD61xtZ238MMmnLOeJWPI54/oyusJiKcpfTY57JZMTB4 X-Received: by 2002:a63:65c2:: with SMTP id z185-v6mr5589976pgb.163.1528469933006; Fri, 08 Jun 2018 07:58:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528469932; cv=none; d=google.com; s=arc-20160816; b=kANf3XUnbK4zGnhSncHSovkcrjGZudbvAdzo35yZRaNhtSpzJ2dh8u5gxLgRHyaSlU qB+hUv2wt0jM55/b3DZtiDcjLQPrEf13+c5pGoOvmsxldMeDR5TPQrBZ98yGPbtil0Y5 lAVI/WFt9O60B8AVaQ4q6GVRpRSVCLUsj1DvYrtVearXj2D2RD3AwhRlFTjyu60cXVph MNPeLtzTgXxzQsRo8X5zSGZ/jez+foIbBrvvbuCa7kikR4lAA2eZyLYpsDRV9y5saje/ SZmPZeF6Tgezhfdui0OWVGa2RFAUuhdMNWY4OkYmU6KoN8kqPQnU3DN8v6MUpvbWOCgZ pAsQ== 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=9tgqyiv9muSRrIvBmXuFUULs9FvWaInexPLi1tzwOLw=; b=vMENlMzSUYW2kUKEq3PAzLQng2gXOGXEH6P8vdjf4fL4b2NeR8P8gFReEZvetFhGm9 FV34fCJUXufMny7hypRqUppFQK7fJsY2ugjVMGKH8LWbFb4AbT69eMnLxDuGgC2tPxQf aeiMbVXQ5EuH19uNodcHUY+mVxmeWwfkixCzlR18BJsvpDzbWQwHijVeIQxhWnpMKqZr TXu8jwBDMxrh/C/LyRC+7GJQiAfesA+TkGgDFZzUb9Xfyumg4bkmwhgcD0tAILgbqdFu PIXlswDLaon4kc7ISFTk5ZvEIc1Km5o5+YJUmwjSqU3kgnvy0787LwAxeY5GXOeF1HSf 19Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hjIxmd5o; 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 x3-v6si17600526pgt.88.2018.06.08.07.58.38; Fri, 08 Jun 2018 07:58:52 -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=hjIxmd5o; 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 S1752910AbeFHO5j (ORCPT + 99 others); Fri, 8 Jun 2018 10:57:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:38858 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752774AbeFHO5i (ORCPT ); Fri, 8 Jun 2018 10:57:38 -0400 Received: from mail-wm0-f54.google.com (mail-wm0-f54.google.com [74.125.82.54]) (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 2E2A920896 for ; Fri, 8 Jun 2018 14:57:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1528469857; bh=6PHHvd5BH7Cl5TWX+A64ZoLEP/xRgqMqY7eFx+Mu+WI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=hjIxmd5orAm56smf+hfm/uMx/eD1cyMpVTeYAdbiiJ0O+M77vuviy8BFaS+55g1VQ YR93LMdhpNH1Jyfxu6x6r5VibvpYKPtrpcXkQt3yfT8476iqoPrF31t6e+Ub7rLzDH t89ZRrDj0PGUu0ZauikpNSdlka8ZgW7uonPmRWjc= Received: by mail-wm0-f54.google.com with SMTP id j15-v6so4336433wme.0 for ; Fri, 08 Jun 2018 07:57:37 -0700 (PDT) X-Gm-Message-State: APt69E0GB/PYu4Ez1VF02aAWyKBnog+xAqS2FjQc9JMG1r/q84G65T4T JIdXeDwjp9QXotbXj5XLN9MLG3vsBLOQSYe0Ba/NxQ== X-Received: by 2002:a1c:4a9d:: with SMTP id n29-v6mr1685075wmi.46.1528469855649; Fri, 08 Jun 2018 07:57: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: Fri, 8 Jun 2018 07:57:22 -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" , Cyrill Gorcunov , Dmitry Safonov 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 Fri, Jun 8, 2018 at 5:24 AM H.J. Lu wrote: > > On Thu, Jun 7, 2018 at 9:38 PM, Andy Lutomirski wrote: > > On Thu, Jun 7, 2018 at 9:10 PM H.J. Lu wrote: > >> > >> On Thu, Jun 7, 2018 at 4:01 PM, Andy Lutomirski wrote: > >> > > > > By the time malicious code issue its own syscalls, you've already lost > > the battle. I could probably be convinced that a lock-CET-on feature > > that applies *only* to the calling thread and is not inherited by > > clone() is a decent idea, but I'd want to see someone who understands > > the state of the art in exploit design justify it. You're also going > > to need to figure out how to make CRIU work if you allow locking CET > > on. > > > > A priori, I think we should just not provide a lock mechanism. > > We need a door for CET. But it is a very bad idea to leave it open > all the time. I don't know much about CRIU, If it is Checkpoint/Restore > In Userspace. Can you free any application with AVX512 on AVX512 > machine and restore it on non-AVX512 machine? Presumably not -- if the program uses AVX512 and AVX512 goes away, then the program won't be happy. Anyway, having thought about this, here's a straw man proposal. We add a lock flag like in these patches. The lock flag is set by arch_prctl(), inherited on clone, and cleared on exec(). ptrace() gains a new API to clear the lock flag and can modify the CET configuration regardless of the lock flag. (So ptrace() needs APIs to read and write SSP, to read and write the shadow stack itself, and to change the mode.) By the time an attacker has gotten enough control of a victim process to get it to use ptrace(), I don't think that trying to protect CET serves any purpose. As an aside, where are the latest CET docs? I've found the "CET technology preview 2.0", but it doesn't seem to be very clear or entirely complete. On Fri, Jun 8, 2018 at 5:17 AM H.J. Lu wrote: > > On Thu, Jun 7, 2018 at 9:35 PM, Andy Lutomirski wrote: > > Is there any reason you can't use LD_CET=force to do it for > > dynamically linked binaries? > > We need to enable shadow stack from the start. Otherwise function > return will fail when returning from callee with shadow stack to caller > without shadow stack. I don't see the problem. A CET-supporting ld.so will be started with CET on regardless of what the final binary says. If ld.so sees LD_CET=force, it can keep CET on regardless of the flags in the loaded binary. > > > I find it quite hard to believe that forcibly CET-ifying a legacy > > statically linked binary is a good idea. > > We'd like to provide protection as much as we can. > I agree that this is a nice sentiment, but I don't think that a simple "force CET on next exec()" flag is a good way to accomplish this. I've had the pleasure of using legacy binaries, and there are all kinds of gotchas. First, a bunch of them aren't binaries at all -- they're shell scripts. There's big_expensive_program that starts with #!/bin/bash and eventually execs /opt/blahblahblah/big_expensive_program_bin, and that involves two execs. (Heck, even Firefox is set up more or less like this.) Some programs can re-exec themselves. All of this is not to mention that it would be really annoying when your program crashes after you've been using it for hours because you finally triggered the code path that did longjmp() and CET kills it. And you don't really need kernel support for this anyway. It should be relatively straightforward to write a loader that opens and loads a static binary. I think that this entire CET-on-exec concept should be dropped from this patch series. If someone really wants it, make it a separate patch on top after everything has been merged, and we can poke holes in it them.