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 1A0CAC47089 for ; Sat, 3 Dec 2022 02:45:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235129AbiLCCpa (ORCPT ); Fri, 2 Dec 2022 21:45:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235019AbiLCCp3 (ORCPT ); Fri, 2 Dec 2022 21:45:29 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 684C07061C for ; Fri, 2 Dec 2022 18:45:28 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id q17-20020a17090aa01100b002194cba32e9so9977318pjp.1 for ; Fri, 02 Dec 2022 18:45:28 -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=sWPbe7F7je25IvRp5tTWOWJxp/+2tKAEeYAMwrnHX3I=; b=OeqW2Nqj7v6wmWLAIuXU1QUcVafcdaqj28BksV47DQWLlWr4PTt1J4XCOQ454A4bFG TnB8dB810gc+e0jB5mOvXEhdj0JUTzkaMInzsFyeboMhjJ0cJ/qcl4J0adKp4oQMBl4j MniyfBPyATrxtCbDMP4lUaT8Hxyueoc1+DkWw= 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=sWPbe7F7je25IvRp5tTWOWJxp/+2tKAEeYAMwrnHX3I=; b=xT1kCa7TyUzDl2W+blVRaE1GLq5+0ynr6QrLgtC7rRs47bwlcjAasv/H1rlR9KnMMi yDNITmofXr2O5UtXrpxnrUWGID+GEA7SL5/k8qbxVmyD40G9aW5125DLnplR+XStWuFr 1XyaiI/6+8528smt4M66iDnjUwoiWwfJEM1RsIr8ECK8x7gHYa0JPTaIHAahb1TC7Va/ S63l/pDsJtKz7qZMGrKYohxvJ019YnRqM/9IsSn5N2dHzNPRgJwDcUXr9aSfnvgxopMr tHiT0u6X+TWoqdGJRtyu1gYHTcknULzRlutR7W1Wu9OKrEhHOArhngBtpsgTkprQLaFu bzVg== X-Gm-Message-State: ANoB5pnmC2asXKDvd1bMqWPcXMwD6l+asdgzxSdWDu4ZgCuDA2AGSKOj U0v++1OWhOtpRcEG6Lhe3oD5kw== X-Google-Smtp-Source: AA0mqf7RDtFvAEvWe64RZK8PfilyOJ4dzXrwN63EljeiYQe8nUiUTNgCvUVRzgsKQzmQWH/Zqqmtvg== X-Received: by 2002:a17:902:ec8d:b0:188:59d2:33e with SMTP id x13-20020a170902ec8d00b0018859d2033emr53749396plg.142.1670035527895; Fri, 02 Dec 2022 18:45:27 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id w10-20020a170902e88a00b00183c67844aesm6288151plg.22.2022.12.02.18.45.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 18:45:27 -0800 (PST) Date: Fri, 2 Dec 2022 18:45:26 -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 28/39] x86/shstk: Introduce routines modifying shstk Message-ID: <202212021845.4A92DA95@keescook> References: <20221203003606.6838-1-rick.p.edgecombe@intel.com> <20221203003606.6838-29-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221203003606.6838-29-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:55PM -0800, Rick Edgecombe wrote: > From: Yu-cheng Yu > > Shadow stacks are normally written to via CALL/RET or specific CET > instuctions like RSTORSSP/SAVEPREVSSP. However during some Linux > operations the kernel will need to write to directly using the ring-0 only > WRUSS instruction. > > A shadow stack restore token marks a restore point of the shadow stack, and > the address in a token must point directly above the token, which is within > the same shadow stack. This is distinctively different from other pointers > on the shadow stack, since those pointers point to executable code area. > > Introduce token setup and verify routines. Also introduce WRUSS, which is > a kernel-mode instruction but writes directly to user shadow stack. > > In future patches that enable shadow stack to work with signals, the kernel > will need something to denote the point in the stack where sigreturn may be > called. This will prevent attackers calling sigreturn at arbitrary places > in the stack, in order to help prevent SROP attacks. > > To do this, something that can only be written by the kernel needs to be > placed on the shadow stack. This can be accomplished by setting bit 63 in > the frame written to the shadow stack. Userspace return addresses can't > have this bit set as it is in the kernel range. It is also can't be a > valid restore token. > > Tested-by: Pengfei Xu > Tested-by: John Allen > Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook -- Kees Cook