From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 582FBC4332F for ; Tue, 4 Oct 2022 05:01:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229513AbiJDFBM (ORCPT ); Tue, 4 Oct 2022 01:01:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbiJDFBL (ORCPT ); Tue, 4 Oct 2022 01:01:11 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCE2B16599 for ; Mon, 3 Oct 2022 22:01:09 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id b5so11748228pgb.6 for ; Mon, 03 Oct 2022 22:01:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date; bh=YCIEsQmqe2GU/op8ELVIz10eFCT8qx7jrOh827aE4ak=; b=fdSA9xmIbaXZOFK29VojFiNPE/Ng3cLgMgO04lzffde9cZ0Aj70ulu+cOZLSn4HMID ZcBnoO4BZD2KT85KEtfcmtPUO7G4u94DJbCG9gFWmQE4pvn0lIL6/Lc9NZX3JtjxD3+c pQ6fyzv5HBKm5oOgaBDxztjBkP/mkKSY/Ry5M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date; bh=YCIEsQmqe2GU/op8ELVIz10eFCT8qx7jrOh827aE4ak=; b=Yufm1rUB1JyReCqnnGFLP6G7m9lSyOQ7NnEu6UPfZzIKdKKZawCiyPf+lqwsZ68Ti1 2suuEjXo8ckBd3qq6Klf3Z8Mla2i+b065fFg2Gm77/eJCRezRM57uELeY0cdqyhLj304 SKebSZINXOcjBKGfstvM/ciW8MYMBkd3ZSC5grssZK4wq68eCkmVcmTJG1sJD8x+J5dM K68Z9c94SdHbmy6E5TfB32UReGEYWfqyfQZsrwoEybTMv0+K0w3L1HoyEBiQhv+rhAcn COyaXN/No+BF7tKzx3S+1St12jRL4Bq58Ue0zRhmdTsDuqwFD5dsACPnVyizOLnEK5NC E1Tw== X-Gm-Message-State: ACrzQf0BaFc+mUP7T228SFN9/rwnfMNw0xfRk2xf1FBiB4h5VHk0V6Uz 26kW4ZtrhBoOHcjq4Wg0/42Miw== X-Google-Smtp-Source: AMsMyM5PzL11modUqno6f/hvls5hZpn+KK4uhST+ROirabQr+EJiNbMAuTappoTzvGAyPi9jEbjxMQ== X-Received: by 2002:a63:da12:0:b0:43a:18ce:f959 with SMTP id c18-20020a63da12000000b0043a18cef959mr21506613pgh.386.1664859669373; Mon, 03 Oct 2022 22:01:09 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id y83-20020a626456000000b005386b58c8a3sm5814207pfb.100.2022.10.03.22.01.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 22:01:08 -0700 (PDT) Date: Mon, 3 Oct 2022 22:01:07 -0700 From: Kees Cook To: Jann Horn Cc: Rick Edgecombe , x86@kernel.org, "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H . J . Lu" , Jonathan Corbet , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V . Shankar" , Weijiang Yang , "Kirill A . Shutemov" , joao.moreira@intel.com, John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com Subject: Re: [PATCH v2 00/39] Shadowstacks for userspace Message-ID: <202210032158.CE0941C4D@keescook> References: <20220929222936.14584-1-rick.p.edgecombe@intel.com> <202210030946.CB90B94C11@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-api@vger.kernel.org On Mon, Oct 03, 2022 at 07:25:03PM +0200, Jann Horn wrote: > On Mon, Oct 3, 2022 at 7:04 PM Kees Cook wrote: > > On Thu, Sep 29, 2022 at 03:28:57PM -0700, Rick Edgecombe wrote: > > > This is an overdue followup to the “Shadow stacks for userspace” CET series. > > > Thanks for all the comments on the first version [0]. They drove a decent > > > amount of changes for v2. Since it has been awhile, I’ll try to summarize the > > > areas that got major changes since last time. Smaller changes are listed in > > > each patch. > > > > Thanks for the write-up! > > > > > [...] > > > GUP > > > --- > > > Shadow stack memory is generally treated as writable by the kernel, but > > > it behaves differently then other writable memory with respect to GUP. > > > FOLL_WRITE will not GUP shadow stack memory unless FOLL_FORCE is also > > > set. Shadow stack memory is writable from the perspective of being > > > changeable by userspace, but it is also protected memory from > > > userspace’s perspective. So preventing it from being writable via > > > FOLL_WRITE help’s make it harder for userspace to arbitrarily write to > > > it. However, like read-only memory, FOLL_FORCE can still write through > > > it. This means shadow stacks can be written to via things like > > > “/proc/self/mem”. Apps that want extra security will have to prevent > > > access to kernel features that can write with FOLL_FORCE. > > > > This seems like a problem to me -- the point of SS is that there cannot be > > a way to write to them without specific instruction sequences. The fact > > that /proc/self/mem bypasses memory protections was an old design mistake > > that keeps leading to surprising behaviors. It would be much nicer to > > draw the line somewhere and just say that FOLL_FORCE doesn't work on > > VM_SHADOW_STACK. Why must FOLL_FORCE be allowed to write to SS? > > But once you have FOLL_FORCE, you can also just write over stuff like > executable code instead of writing over the stack. I don't think > allowing FOLL_FORCE writes over shadow stacks from /proc/$pid/mem is > making things worse in any way, and it's probably helpful for stuff > like debuggers. > > If you don't want /proc/$pid/mem to be able to do stuff like that, > then IMO the way to go is to change when /proc/$pid/mem uses > FOLL_FORCE, or to limit overall write access to /proc/$pid/mem. Yeah, all reasonable. I just wish we could ditch FOLL_FORCE; it continues to weird me out how powerful that fd's side-effects are. -- Kees Cook