Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3153729rwb; Mon, 3 Oct 2022 10:24:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7uLE0kH0gZLJjo8xgNSMxUXasrF5WQx5qn75Hzv4bXpmzYBw2aq9q5ONd7wvrrACf48qlz X-Received: by 2002:a17:902:aa46:b0:178:9ee5:c7f1 with SMTP id c6-20020a170902aa4600b001789ee5c7f1mr23726855plr.69.1664817856762; Mon, 03 Oct 2022 10:24:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664817856; cv=none; d=google.com; s=arc-20160816; b=Wp/zik9sqTYYhLP+PE52ig4J4XQ/3ycBoqwmpEBPx07iVQg6Dd++SSgE2nfBn/pZ0j fPydek8cJ6TLo6OrrY+/zrDPK9lGvLLIcWqjquue9bOWpVtrPAD5k6YPU0I7CGWb5HPN 6ND5qH9COreQqyNxAe+kj6wG/HP1G+tg+L0HVkIkOOGKydyviTj8IgLVQFSpbPVBMAB3 Xo4ZDZPcfxe617dTiKAGxqdc2mHGkiljxdwQcHKOtvMmfMp4gBM6MdYxbKFqV56ymNNZ RW6hOCJKkuFwVkpr1gTTLhPa5e0cP4EZ5l02XOiOsaWjXsg7Aen+r1SLQIDWv3hCr2UC eByw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=uQT4qnLKBJikzcGjZm0d2fhOOnumfYfnoU0Yf3hAnto=; b=WQAaweOHX3IXy9tRWrF9TngTe4nZ+0DY59ybd/o2D+m/yVmYwgaNfBQwN5ZHZg/o0P 3016v20ovnbjJEMXOlBRnXp4UlN+0/5y2ohqGSaIa7GLGyETbh8+JrJQ0Gk11zm20k75 wuUv36l8NJWALTgL6W+m3q4Sbi7ca+gflkEtvklFELtGo3qRExP6m4JZ7zMdKMUWwFZ9 OpMK72bBc9kXBtCpVehEnJx5XjaIoZlvv5fvRZZ923quaf3h4F8aoqTLZHwYzKPRe5go a5HfjmvKHifJwDco+l+DO+tiBVbkBhbjZuZuo171cqDd1LEhjq2nHMQ4Fct0qz9TGIVW F0jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KgKRpsNO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j13-20020a170902da8d00b00174418919a6si12506551plx.513.2022.10.03.10.24.04; Mon, 03 Oct 2022 10:24:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KgKRpsNO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229647AbiJCREp (ORCPT + 99 others); Mon, 3 Oct 2022 13:04:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229545AbiJCREk (ORCPT ); Mon, 3 Oct 2022 13:04:40 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5553B9B for ; Mon, 3 Oct 2022 10:04:36 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id q9so10161307pgq.8 for ; Mon, 03 Oct 2022 10:04:36 -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=uQT4qnLKBJikzcGjZm0d2fhOOnumfYfnoU0Yf3hAnto=; b=KgKRpsNOzDQo80mo5n0UyA5HhDsXGXEctzVNgWtOidt+imVFWTZICu5gf8hdzG4IUA JY5jekbBlx1dl9djltqFs8u0VKvc4x76knyN34QdjpYOhhctoO/0gVxKQ8ZaHe2iq6HL D0Ikw0jBcyBtqc76lp91g1Hiu7upW4YVqAI4Q= 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=uQT4qnLKBJikzcGjZm0d2fhOOnumfYfnoU0Yf3hAnto=; b=7rF/fNd3sGh+XTeeNEEnnnQ5ivzTAXy7yWk1J0KKPelqfRJTzA7wdmHTdBJJNrhsU+ KB5i5dVowkVR8qoRe7bGSMoGHsOQ3wazhdMuJJkkmrMMinLez4wVMxs71hUOoVyGlkU3 gySAJKylAyjV/yZRfi/+OOFDkSSv0zssC46lxjdAw6aBaA3jQXxNzSHc6IfhUgFoTAnf QPD0PXedcTndvZGb+wlnyavscBT/GUCa+GEnjppnZuf1vTt96EoGBaIaBH6iCYKBkI3F AsjnOEA+9V1kyjqYmfIcOZCbtri3EIS/IAMbfzis+1lCn9BdcF5oJ0M2axTAVOdIMbhh SQ4A== X-Gm-Message-State: ACrzQf0Nih2li08t+V7qHB/LQVRMgsH32F3ATioNoBjfGOmLEyyMp6kR n1zBTyIjWnZzKsw2Y6ZhUQirGQ== X-Received: by 2002:a05:6a00:2289:b0:546:8fef:1bec with SMTP id f9-20020a056a00228900b005468fef1becmr23795216pfe.17.1664816675840; Mon, 03 Oct 2022 10:04:35 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id w35-20020a17090a6ba600b0020ab9b18896sm1192934pjj.42.2022.10.03.10.04.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 10:04:35 -0700 (PDT) Date: Mon, 3 Oct 2022 10:04:34 -0700 From: Kees Cook To: Rick Edgecombe Cc: 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" , Jann Horn , 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: <202210030946.CB90B94C11@keescook> References: <20220929222936.14584-1-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220929222936.14584-1-rick.p.edgecombe@intel.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? > [...] > Shadow stack signal format > -------------------------- > So to handle alt shadow stacks we need to push some data onto a stack. To > prevent SROP we need to push something to the shadow stack that the kernel can > [...] > shadow stack return address or a shadow stack tokens. To make sure it can’t be > used, data is pushed with the high bit (bit 63) set. This bit is a linear > address bit in both the token format and a normal return address, so it should > not conflict with anything. It puts any return address in the kernel half of > the address space, so would never be created naturally by a userspace program. > It will not be a valid restore token either, as the kernel address will never > be pointing to the previous frame in the shadow stack. > > When a signal hits, the format pushed to the stack that is handling the signal > is four 8 byte values (since we are 64 bit only): > |1...old SSP|1...alt stack size|1...alt stack base|0| Do these end up being non-canonical addresses? (To avoid confusion with "real" kernel addresses?) -Kees -- Kees Cook