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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82BFEC433FE for ; Mon, 3 Oct 2022 17:04:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C97E6B0071; Mon, 3 Oct 2022 13:04:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 07AD16B0073; Mon, 3 Oct 2022 13:04:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E5BAD8E0001; Mon, 3 Oct 2022 13:04:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D105A6B0071 for ; Mon, 3 Oct 2022 13:04:38 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9A8DE1A0316 for ; Mon, 3 Oct 2022 17:04:38 +0000 (UTC) X-FDA: 79980262236.01.A33C85D Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by imf21.hostedemail.com (Postfix) with ESMTP id 1C67B1C0005 for ; Mon, 3 Oct 2022 17:04:36 +0000 (UTC) Received: by mail-pg1-f173.google.com with SMTP id bh13so10175973pgb.4 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=5fe9Z4zu22cOL7waF6nW6lfNePvimyW/2s0aIXb+DbxvHxTNL33U21bUbIkhg0dfDr bKZmUfuo7EGyz+f+0dKqaorlHmfMr5f46CKmP9egLQ7wImlEGnhU5vuzvbLuFyYb9d37 waaWTsw1bOCUoqmEWXMxikv77/N8BspsgnigtO6Isq5RLlO3UOKftCOuVy4bvFlKVgSG 5puJjkuHqcwafBm8csibN8WF3mxhgIWCawnwFVVokKBeRVkZH+G/ygq3qYVj0YArU2Dc Xgkd27YUn/YXo6zJCWZnab/mRGK315NarPvJBcpRYEs+kkIaX6c+2566hZoIuVW6qRS5 jB6g== X-Gm-Message-State: ACrzQf2pv14CSvuv9QtS2zFZPRGRPpBpWQuSdlafpI85Xv2yZ5+gDoJ3 ZR2v0YG0TLdWhjkvrutqZmNHmg== X-Google-Smtp-Source: AMsMyM57eSSs465fKo/PIMCHt9O/y/zY3vmojOi8BFL8tAd04lj7nGKBQe3q5nr5qg+YdWb+SzoCtw== 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> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664816677; a=rsa-sha256; cv=none; b=H46Lfee64VrExBZezK2WooeXgyXpMzM9+SvHC7xYqWgWQgGpaJyoYdDPTMGZSVUBC9z6MJ 7TPlZqTR38jz3kPgC53/ishFQUc7d0H0dqyhBmhUyTcx8uEtY04FjvFz9xT2tZOv2cQzQs yYqnEMBMrwehrfXbzacdkne/i4Ac6vM= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=KgKRpsNO; spf=pass (imf21.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.173 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664816677; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=uQT4qnLKBJikzcGjZm0d2fhOOnumfYfnoU0Yf3hAnto=; b=SH4yYD32A8DmI4Mb5oLezDarbI30aZHnVVBwCPiksLoGtzgsgI1Vq4JX+n8SXCuKXiNVdu ZYCKr5dMi8UqjxkugtIsi2Pu08K09JFgKWt/P+jXq6BhIsgS14hZsSOiTH8MU2ay119n2n cJmZrXRe2Cd+MsHNFPMBgrgEDfyiwaM= X-Rspamd-Server: rspam08 X-Rspam-User: X-Rspamd-Queue-Id: 1C67B1C0005 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=KgKRpsNO; spf=pass (imf21.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.173 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Stat-Signature: ehicerxyjag7fzzbgzj13ir78h748mhz X-HE-Tag: 1664816676-481289 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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