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 X-Spam-Level: X-Spam-Status: No, score=-11.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BCE8C433E0 for ; Thu, 11 Feb 2021 02:07:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0378664EBC for ; Thu, 11 Feb 2021 02:07:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229729AbhBKCHY (ORCPT ); Wed, 10 Feb 2021 21:07:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229717AbhBKCGb (ORCPT ); Wed, 10 Feb 2021 21:06:31 -0500 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 156E1C0613D6 for ; Wed, 10 Feb 2021 18:05:51 -0800 (PST) Received: by mail-pg1-x52c.google.com with SMTP id j5so2632222pgb.11 for ; Wed, 10 Feb 2021 18:05:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=GWehHpPBiIbtAUGV973qzMbhfGOacu1gexxk5hpereM=; b=VkI1vNchcTfqZMT8TdeTKNunPyydlTDpaduc777AZXErfTUw+IoNoowB3buQXwB7D2 HM2cW4ajkZGMEI9fbbyaG+QS01IhsQO2IvFJRs0rrcX6Aw2nR/Sd0VcHmSULgTNW1OGQ OrJ32pm7uzcNVvPSKZDo8yzfQ3HtJKHFRkXZY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=GWehHpPBiIbtAUGV973qzMbhfGOacu1gexxk5hpereM=; b=VTfsYbEpqAxt9wp9SKGbTE/Z0xMjGCI9IacZ1AZg7Rel1pH5gTsWpT2+satZFImgTa sPSNvVkJiIki03sBzst7sw+UFQHcjS2T97WJzYwyx7xWpSE1ASHdMkat1pO1jYyrcSdw 1Qt5D+W93zDOmwFiwxaUIwPXOK3FKYd5NwuWgABXzCNfngqcMnQCLt6ktjdyBt4LKyBX PLTA5SZVD2dWz4yWPtXPX0YBREsH+V0gfrp3vVzkJl7N80tmmEhGUimubibPu+AveQNE 0ROOCnZ+W0BbH17m0aXQG8ce6iJMCtsTXKshF6uSwR3KIX4+sBWcWscwM7+Y2De9g+6E mseQ== X-Gm-Message-State: AOAM530MlkOilj41OYZi2yXmmg3azsseDeLpjOwCiGSx6zE35QwPNe6F PnYSA9+i1ke9JPAqYrPHpX/ZoA== X-Google-Smtp-Source: ABdhPJzsWXbn1Ou/vFtG4NQUWw149O4AAHSFlrE0lP7i2j/RD0O7x0LK3DLeL8X3j84QUwiX06AIsg== X-Received: by 2002:a63:6381:: with SMTP id x123mr1570843pgb.177.1613009150490; Wed, 10 Feb 2021 18:05:50 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id h8sm3286360pfv.154.2021.02.10.18.05.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Feb 2021 18:05:49 -0800 (PST) Date: Wed, 10 Feb 2021 18:05:48 -0800 From: Kees Cook To: "Yu, Yu-cheng" 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" , Vedvyas Shanbhogue , Dave Martin , Weijiang Yang , Pengfei Xu , haitao.huang@intel.com Subject: Re: [PATCH v20 21/25] x86/cet/shstk: Handle signals for shadow stack Message-ID: <202102101805.0B98ACA743@keescook> References: <20210210175703.12492-1-yu-cheng.yu@intel.com> <20210210175703.12492-22-yu-cheng.yu@intel.com> <202102101154.CEF2606E@keescook> <57dcc827-052a-94cd-31d4-286675f9d506@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <57dcc827-052a-94cd-31d4-286675f9d506@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 10, 2021 at 01:38:10PM -0800, Yu, Yu-cheng wrote: > On 2/10/2021 11:58 AM, Kees Cook wrote: > > On Wed, Feb 10, 2021 at 09:56:59AM -0800, Yu-cheng Yu wrote: > > > To deliver a signal, create a shadow stack restore token and put the token > > > and the signal restorer address on the shadow stack. For sigreturn, verify > > > the token and restore from it the shadow stack pointer. > > > > > > A shadow stack restore token marks a restore point of the shadow stack. > > > The token is distinctively different from any shadow stack address. > > > > How is it different? It seems like it just has the last 2 bits > > masked/set? > > > > For example, for 64-bit apps, > > A shadow stack pointer value (*ssp) has to be in some code area, but for a > token, (*ptr_of_token) = (ptr_of_token + 8), which has to be within the same > shadow stack area. In cet_verify_rstor_token(), this is checked. > > > > In sigreturn, restoring from a token ensures the target address is the > > > location pointed by the token. > > > > As in, a token (real stack address with 2-bit mask) is checked against > > the real stack address? I don't see a comparison -- it only checks that > > it is < TASK_SIZE. > > > > How does cet_restore_signal() figure into this? (As in, the MSR writes?) > > > > The kernel takes the restore address from the token. It will not mistakenly > take a wrong address from the shadow stack. I will put this in my commit > logs. Ah-ha, okay, got it now. Thank you! Reviewed-by: Kees Cook -- Kees Cook