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 7229AC47089 for ; Sat, 3 Dec 2022 02:46:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235237AbiLCCqd (ORCPT ); Fri, 2 Dec 2022 21:46:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234893AbiLCCqc (ORCPT ); Fri, 2 Dec 2022 21:46:32 -0500 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5BD5C4634 for ; Fri, 2 Dec 2022 18:46:31 -0800 (PST) Received: by mail-pg1-x532.google.com with SMTP id r18so5833817pgr.12 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=rE+GO65UQy/XQJ5pdRWe5bPv7yREwgwOEltv1oaHbB0fZ9kFW7MvJivQeElN8tnyUm yEZuaXH06fQXwkBq+tO2oHMcvoZBmGrIYUnaepeaST10nunfvxIzj7KENrl8TJgAYkpj VAxkRml/0EMOPgl7TfstsSXgq0YdeuWt651tUKRQz42GW39vt92juEKVYDoegMnBRXkO XwZ+Tf3kplCphQlzDQf2YMocOTVSPgItOKCtA3YtfMbI5G7SmNsOF0r/F92Dg8BcKyYN vRYymmyySUxfGJPAT4JD2oh06aRZB02DXDTGLuzqEr2gCNex0SMBehq2r7iDcBjdIugD ImzA== X-Gm-Message-State: ANoB5pmnbtbCm7bYIvOvi3JSzWsqW2pEN3dwdcOF+5JNBE/fUpNBHAcI 1OUFSQhU5mC3t8rNVCbBeQjv0w== 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> Precedence: bulk List-ID: X-Mailing-List: linux-api@vger.kernel.org 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