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 3C272C4321E for ; Sat, 3 Dec 2022 02:46:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D3FBB6B0073; Fri, 2 Dec 2022 21:46:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CEF046B0074; Fri, 2 Dec 2022 21:46:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB6F56B007B; Fri, 2 Dec 2022 21:46:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id ACF0A6B0074 for ; Fri, 2 Dec 2022 21:46:32 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 82C64C0930 for ; Sat, 3 Dec 2022 02:46:32 +0000 (UTC) X-FDA: 80199456624.30.4DDDFFA Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by imf03.hostedemail.com (Postfix) with ESMTP id 3C0A620010 for ; Sat, 3 Dec 2022 02:46:32 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="KLzTo/tj"; spf=pass (imf03.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.172 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=1670035592; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=x+iLzqLDRY8UcQo0kKaaiN6ym6n/piiBIem/JqSdM8A=; b=YfNv8dxgb9FeUxD+zyc1ihGshKwq/BH1FJKQwWEWfLLMaQovfbbMF2MtGg95KVf8HN0nba syQpzO6cgrozdi5A3h27xPl5CJl16+hBzznefVCPw/Fgu2ZvS1FFAppz1O3nCzdj7yHrhn Nj/NisVtkT5DLkXekCenM+oG9rxQVlQ= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="KLzTo/tj"; spf=pass (imf03.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.172 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670035592; a=rsa-sha256; cv=none; b=pdXtobUEsu4H/sx928CMSnrgXZbeymxLBnFp/wx7R2nkwqmxAAOmuAKM3INlkFXw+iMlno cLRvQgk6hijhDneCcTULHMxbN+Ra+BLwfBODs7A/fyy4TLS5Q29bNuUrl7ja+NdOIYGz65 RFIxQTwcvyXp6UolaqDk7PxOfIk27II= Received: by mail-pg1-f172.google.com with SMTP id 6so5847902pgm.6 for ; Fri, 02 Dec 2022 18:46:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=x+iLzqLDRY8UcQo0kKaaiN6ym6n/piiBIem/JqSdM8A=; b=KLzTo/tj7fIZeyP6gGrmfwf7X2IIEHGD1jltxx9K7xaNqkJIEo2ao0fIlZ0ZxDmUiC qF7c/md/lqiCB6dbfTfOl/Y48oTUdStOp/fhv7niMr2q7sE+u3nPThEVD2d3zq2laFom Y1V+fLsh83W1YJqts6oUwQvUVC6YqhrwGtB4g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=x+iLzqLDRY8UcQo0kKaaiN6ym6n/piiBIem/JqSdM8A=; b=RSbQqgN36dW+QcOOwQTlOBKloobb91wUfsiKMGh7yBkcIG5fx0I+U106jYa6uXH4AV lS+epDItCyP6Ew7xycY/TW+JywoYAR6zAm7kfshAmjF6T4t0DMIx6pkH54tyUm7nyRAq wClOOr5vfa0Z8k1oF6Z9N4BntMvgWrztq4KMVKXVv0r7UPA9bSav5bluBe6IahaAFddQ G3OE/cm65PGuvYuNqewViijzWOp2p5Vqub7QvQfszU+O1gBQ9hdl+FjDexoIA/pgNVzf MZokN0G6f9M7cTsNZzUc+kWUFHXi/xhsc4P3zAZGLsUIRVNfwJs9PLv40xzNxQDkY8kX wTPQ== X-Gm-Message-State: ANoB5pmjnz96oWPQxcUGJv0gTE3zXUGmK+6PrLJ+esqZrXGlgdrULFun Ey9tHGdJ3W70WscEIBTcpNC1QA== X-Google-Smtp-Source: AA0mqf6oAj6h5qu6AVbtVOXDQ0T/xnbet5XcclolXxVNuIuRy36+i9HcF8uT5nTMG4W5pJqoQv8dyw== X-Received: by 2002:a62:ea0e:0:b0:575:7bb:d6fc with SMTP id t14-20020a62ea0e000000b0057507bbd6fcmr31612264pfh.79.1670035591199; Fri, 02 Dec 2022 18:46:31 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id p2-20020a1709027ec200b0017da2798025sm6153534plb.295.2022.12.02.18.46.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 18:46:30 -0800 (PST) Date: Fri, 2 Dec 2022 18:46:29 -0800 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 , Weijiang Yang , "Kirill A . Shutemov" , John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, akpm@linux-foundation.org, Andrew.Cooper3@citrix.com, christina.schimpe@intel.com, Yu-cheng Yu Subject: Re: [PATCH v4 29/39] x86/shstk: Handle signals for shadow stack Message-ID: <202212021846.AECD42F51@keescook> References: <20221203003606.6838-1-rick.p.edgecombe@intel.com> <20221203003606.6838-30-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221203003606.6838-30-rick.p.edgecombe@intel.com> X-Spamd-Result: default: False [5.10 / 9.00]; SORBS_IRL_BL(3.00)[209.85.215.172:from]; SUSPICIOUS_RECIPS(1.50)[]; MID_RHS_NOT_FQDN(0.50)[]; RCVD_NO_TLS_LAST(0.10)[]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; BAYES_HAM(-0.00)[40.78%]; DKIM_TRACE(0.00)[chromium.org:+]; RCPT_COUNT_TWELVE(0.00)[39]; FROM_EQ_ENVFROM(0.00)[]; DMARC_POLICY_ALLOW(0.00)[chromium.org,none]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; PREVIOUSLY_DELIVERED(0.00)[linux-mm@kvack.org]; R_DKIM_ALLOW(0.00)[chromium.org:s=google]; ARC_NA(0.00)[]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:209.85.128.0/17]; TO_DN_SOME(0.00)[]; TAGGED_RCPT(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3C0A620010 X-Stat-Signature: 4q3abeew3ar5gbcek3bxuwuthz61fych X-HE-Tag: 1670035592-389126 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 Fri, Dec 02, 2022 at 04:35:56PM -0800, Rick Edgecombe wrote: > From: Yu-cheng Yu > > When a signal is handled normally the context is pushed to the stack > before handling it. For shadow stacks, since the shadow stack only track's > return addresses, there isn't any state that needs to be pushed. However, > there are still a few things that need to be done. These things are > userspace visible and which will be kernel ABI for shadow stacks. > > One is to make sure the restorer address is written to shadow stack, since > the signal handler (if not changing ucontext) returns to the restorer, and > the restorer calls sigreturn. So add the restorer on the shadow stack > before handling the signal, so there is not a conflict when the signal > handler returns to the restorer. > > The other thing to do is to place some type of checkable token on the > thread's shadow stack before handling the signal and check it during > sigreturn. This is an extra layer of protection to hamper attackers > calling sigreturn manually as in SROP-like attacks. > > For this token we can use the shadow stack data format defined earlier. > Have the data pushed be the previous SSP. In the future the sigreturn > might want to return back to a different stack. Storing the SSP (instead > of a restore offset or something) allows for future functionality that > may want to restore to a different stack. > > So, when handling a signal push > - the SSP pointing in the shadow stack data format > - the restorer address below the restore token. > > In sigreturn, verify SSP is stored in the data format and pop the shadow > stack. > > Tested-by: Pengfei Xu > Tested-by: John Allen > Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook -- Kees Cook