Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp72604imm; Thu, 7 Jun 2018 14:03:18 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ5tzO2sXSZuEGWIkcjReRr3PlGcqmW3bhcbLM8fFU384nrWCxNQEjqbXG0ktt1o7+l8SS2 X-Received: by 2002:a62:190d:: with SMTP id 13-v6mr3168644pfz.103.1528405398611; Thu, 07 Jun 2018 14:03:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528405398; cv=none; d=google.com; s=arc-20160816; b=tn2yYllMvil150HLNcKZS4pB6PRyAkylmdhRV1AGE6jd9Sgo4+bBgG/if+RhdJn5bU 2dmQMoSGYPhdkuKc1XHLA6jqmiQ1Vh4PydCSqFahS+zbgUlVBQXMX7PZivNIeakaHq9b 3XchLA9nlG5cg8k/aJoaIZB4OxfBcxGM1CX+37lMvp0+YgAElSAX+3EFRRcsvUqhtSOH DYAUFzP/tmxFsEGkMzDzwDWGEM0PiIO8rR1nBN2IqUKuLXEGlhnVjV4ZagrzlDkQZv49 Hi8HTsA8I/7ceHrSdgJX9MTN+2HW5liXLUc+bS5Vgoy4ehxwv+w3gFYyfmXf0BQeihsu vCaQ== 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=vZbCdh1pbVREWKLF3u+xSSMRPfjOR0Mc33n+52Raa8E=; b=uO65KAzfuoyzAv8r1Pw2pT+WlTmNF6B7zCPWkhabkkPxq9ntL4gXheuxDBXubWZJja cMmB6tUX9PH1xmm3lcVEd7/Rh6FsQoWhu/sKu3FtmGvUUZGo2o94VEWYy9aSFP4TuUKs L9acZGX915LwSy7VQW/JlAhUf7nO+DKe7ZXd9OXwsYy0WhvTBluksxPiQwKxQGXKUNvD TNnaSpFKXrUWBBk6UBL1D+Ow1SbE2QxNhXBCLJ2+gxsM//IrBUJDcZ7jS82TI2/iA4jM vjqAsrWSUUoHf+/MZQ6UJYCVbNgRAtwDJujtdf650mS5BlPenxuB/aI93QEJ+JC2EHuu QUfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vgV9IYMp; 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 p1-v6si22544762pgf.469.2018.06.07.14.03.04; Thu, 07 Jun 2018 14:03:18 -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=vgV9IYMp; 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 S933246AbeFGVBf (ORCPT + 99 others); Thu, 7 Jun 2018 17:01:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:42526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933084AbeFGVBd (ORCPT ); Thu, 7 Jun 2018 17:01:33 -0400 Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) (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 762FF208B3 for ; Thu, 7 Jun 2018 21:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1528405292; bh=LAzhCQsI78n3I2e+pOOBfSDxsZVMaMCiyQ5I3MvYQ6I=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=vgV9IYMp6wcnT1tkx3OXD61hL/5KDSBptIyqEcQr2DGoPso18cqgslJQQ1OT9GanJ ShLlvX/8QTb3eYUFxUeVmS95j3WrkBwqAFB+duvfXK8oRKUEDquAnsiQ+mVwIT1gEK +LJjvNInO1RNnuqWtGm2TUNdwDaXZImu5rovUrJg= Received: by mail-wm0-f46.google.com with SMTP id o13-v6so20320283wmf.4 for ; Thu, 07 Jun 2018 14:01:32 -0700 (PDT) X-Gm-Message-State: APt69E1UivAqp+VUFBSE1Rhxu88aKudFMp8gExzmxfWzfDnnQHVhDKrA blzhC9RVLhqHpQkrGd3op7CPb88czHWBpxY2apGYBg== X-Received: by 2002:a1c:4a9d:: with SMTP id n29-v6mr2454409wmi.46.1528405290631; Thu, 07 Jun 2018 14:01:30 -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: <1528403417.5265.35.camel@2b52.sc.intel.com> From: Andy Lutomirski Date: Thu, 7 Jun 2018 14:01:18 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 06/10] x86/cet: Add arch_prctl functions for shadow stack To: Yu-cheng Yu Cc: Andrew Lutomirski , LKML , linux-doc@vger.kernel.org, Linux-MM , linux-arch , X86 ML , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , "H. J. Lu" , "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 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 :) > When the next exec() is called, CET > feature is turned on/off based on the values set by ARCH_CET_EXEC. And why do we need ARCH_CET_EXEC? For background, I really really dislike adding new state that persists across exec(). It's nice to get as close to a clean slate as possible after exec() so that programs can run in a predictable environment. exec() is also a security boundary, and anything a task can do to affect itself after exec() needs to have its security implications considered very carefully. (As a trivial example, you should not be able to use cetcmd ... sudo [malicious options here] to cause sudo to run with CET off and then try to exploit it via the malicious options. If a shutoff is needed for testing, how about teaching ld.so to parse LD_CET=no or similar and protect it the same way as LD_PRELOAD is protected. Or just do LD_PRELOAD=/lib/libdoesntsupportcet.so. --Andy