Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp11139678rwd; Thu, 22 Jun 2023 09:11:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5/hiasHhq3AfK5NhN2KPzefFpvvfsZclqcr/4A3L1QkwNAm3pwBr9oAEPOyVVs/srR1SEB X-Received: by 2002:a05:6a21:78a9:b0:110:6146:1020 with SMTP id bf41-20020a056a2178a900b0011061461020mr20987842pzc.53.1687450275095; Thu, 22 Jun 2023 09:11:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687450275; cv=none; d=google.com; s=arc-20160816; b=kaThbAaSsJv3fCzFOmURvmjEs93r2Ww6gwnduT8ZecRsabZZIyYfI8GrJKxgJ3cZF4 C6U3CTeTsf+mk+DD+mf34UTo7mviPMwJYp+CqwAazPmi/kmmnkFE75WXSNWrcpxLKv2a 7+VAC3hqGmRqJaw58VMVYTXKh7SnF0H/CKl8PZfRSfyDspki2NVIeH3wTzZEosJEcIDE 9byePPUeGFJSE5udI+zBmsmCSPl+4w76oZZd4O+i39q/QSil5HX1Wa82i1yi29WuPK/b A4Eh/yBa+rC+2OkNNffiL6kVfzeGEPXqNTm5JvB3OFvVPxFObpl0cu3Fe1y1F7hCAwDo Vkmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=CI6Z0S8b5O2++ayz6nzbvLrYXmyQnU5ouR738Nc0SUU=; b=H2pfSBgJsjsUzgvgucdp5jPXbuh5sbwXANJHFPJY5qrDeb3Wq11ZavziZzRCxMnSAN AWqFrAdT/IZnZygCS4GZcdinQnuySuYY1FLXrz9RIfjz69wrvZEdOlsRuGBoXh9xaIA9 7Obg0BhGNCXegzHeefcEUxVcrXO5W1nQvLZjdDSfxiqNfTMF6IhqN8DMTU04WmRv4V6Y D+ICAc4eHvuiOaGdcVZDAPSsQ8ucTIIt/l+RSAzTtHCzFZYRPY3tFCU+hrekEb5WCqqT lUB2L/cbl/cku4EKN8jmAquoK3c5RkZHXLPDYAo2LVkIgKkFFTMS0c9mSojWUvGLdUr2 bPiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LZ7tEs4Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h18-20020aa79f52000000b006645f87dbf2si1529076pfr.223.2023.06.22.09.10.59; Thu, 22 Jun 2023 09:11:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LZ7tEs4Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232431AbjFVP1G (ORCPT + 99 others); Thu, 22 Jun 2023 11:27:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232457AbjFVP05 (ORCPT ); Thu, 22 Jun 2023 11:26:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C3111FD2 for ; Thu, 22 Jun 2023 08:26:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DF2C4618A2 for ; Thu, 22 Jun 2023 15:26:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 499DFC43395 for ; Thu, 22 Jun 2023 15:26:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687447591; bh=B+Z7cw05eGhQpRQ1oXi2HuFt1eCXDFTqYg6Ryju6Ww0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=LZ7tEs4ZWYJsScvqQfOI0MJqNvT+rdMvPcTAIE4UwZNSeObjDDI5y4riNP6maJnnQ UJZZi/wpNjEXn1rrUM5aRrFpj64Ro85AR6U/PxjJow1JoM/wV3nsovzQcDLkPt6eix WBClZ7XlXh1RX6sJBx8PzBgar4nKV9TDmeDjjpXqdMR7aCXoMdN6EQkQ3FTbxjB0px tFhZtrdQ8U9TthS3luQGmPy1SSwXULmSn0g5k6CJghBmZxMKL7O6VYSzNOea0dqDOC jhVU18+EX5TXx41+uS8n0EURM23EYITY6QT17BM4xkNNQDuZrP1WXbjURukviJke2W dUBDT5ZLY9SyA== Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-51a324beca6so9268087a12.1 for ; Thu, 22 Jun 2023 08:26:31 -0700 (PDT) X-Gm-Message-State: AC+VfDz1Dl/T0jRW6ZPEFfW1LtFXQELD8P/BOJhPL1eDxiQTQOnNcteo NChnOuHxJVG1z9VYxL62Uw56RHQjavP+z8sF55b17A== X-Received: by 2002:aa7:c594:0:b0:51a:44b7:14c2 with SMTP id g20-20020aa7c594000000b0051a44b714c2mr9734462edq.40.1687447589330; Thu, 22 Jun 2023 08:26:29 -0700 (PDT) MIME-Version: 1.0 References: <64837d2af3ae39bafd025b3141a04f04f4323205.camel@intel.com> <5794e4024a01e9c25f0951a7386cac69310dbd0f.camel@intel.com> In-Reply-To: From: Andy Lutomirski Date: Thu, 22 Jun 2023 08:26:17 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v9 23/42] Documentation/x86: Add CET shadow stack description To: "szabolcs.nagy@arm.com" Cc: "Edgecombe, Rick P" , "broonie@kernel.org" , "Xu, Pengfei" , "tglx@linutronix.de" , "linux-arch@vger.kernel.org" , "kcc@google.com" , "Lutomirski, Andy" , "nadav.amit@gmail.com" , "kirill.shutemov@linux.intel.com" , "david@redhat.com" , "Schimpe, Christina" , "linux-doc@vger.kernel.org" , "peterz@infradead.org" , "corbet@lwn.net" , "nd@arm.com" , "dethoma@microsoft.com" , "jannh@google.com" , "linux-kernel@vger.kernel.org" , "debug@rivosinc.com" , "pavel@ucw.cz" , "bp@alien8.de" , "mike.kravetz@oracle.com" , "linux-api@vger.kernel.org" , "rppt@kernel.org" , "jamorris@linux.microsoft.com" , "arnd@arndb.de" , "john.allen@amd.com" , "rdunlap@infradead.org" , "bsingharora@gmail.com" , "oleg@redhat.com" , "andrew.cooper3@citrix.com" , "keescook@chromium.org" , "x86@kernel.org" , "gorcunov@gmail.com" , "Yu, Yu-cheng" , "fweimer@redhat.com" , "hpa@zytor.com" , "mingo@redhat.com" , "hjl.tools@gmail.com" , "linux-mm@kvack.org" , "Syromiatnikov, Eugene" , "Torvalds, Linus" , "akpm@linux-foundation.org" , "dave.hansen@linux.intel.com" , "Yang, Weijiang" , "Eranian, Stephane" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 22, 2023 at 2:28=E2=80=AFAM szabolcs.nagy@arm.com wrote: > > The 06/21/2023 18:54, Edgecombe, Rick P wrote: > > On Wed, 2023-06-21 at 12:36 +0100, szabolcs.nagy@arm.com wrote: > > > > The 06/20/2023 19:34, Edgecombe, Rick P wrote: > > > > > > I actually did a POC for this, but rejected it. The problem is, > > > > > > if > > > > > > there is a shadow stack overflow at that point then the kernel > > > > > > > > can't > > > > > > push the shadow stack token to the old stack. And shadow stack > > > > > > > > overflow > > > > > > is exactly the alt shadow stack use case. So it doesn't really > > > > > > > > solve > > > > > > the problem. > > > > > > > > the restore token in the alt shstk case does not regress anything > > > > but > > > > makes some use-cases work. > > > > > > > > alt shadow stack is important if code tries to jump in and out of > > > > signal handlers (dosemu does this with swapcontext) and for that a > > > > restore token is needed. > > > > > > > > alt shadow stack is important if the original shstk did not > > > > overflow > > > > but the signal handler would overflow it (small thread stack, huge > > > > sigaltstack case). > > > > > > > > alt shadow stack is also important for crash reporting on shstk > > > > overflow even if longjmp does not work then. longjmp to a > > > > makecontext > > > > stack would still work and longjmp back to the original stack can > > > > be > > > > made to mostly work by an altshstk option to overwrite the top > > > > entry > > > > with a restore token on overflow (this can break unwinding though). > > > > > > > > There was previously a request to create an alt shadow stack for the > > purpose of handling shadow stack overflow. So you are now suggesting to > > to exclude that and instead target a different use case for alt shadow > > stack? > > that is not what i said. > > > But I'm not sure how much we should change the ABI at this point since > > we are constrained by existing userspace. If you read the history, we > > may end up needing to deprecate the whole elf bit for this and other > > reasons. > > i'm not against deprecating the elf bit, but i think binary > marking will be difficult for this kind of feature no matter what > (code may be incompatible for complex runtime dependent reasons). > > > So should we struggle to find a way to grow the existing ABI without > > disturbing the existing userspace? Or should we start with something, > > finally, and see where we need to grow and maybe get a chance at a > > fresh start to grow it? > > > > Like, maybe 3 people will show up saying "hey, I *really* need to use > > shadow stack and longjmp from a ucontext stack", and no one says > > anything about shadow stack overflow. Then we know what to do. And > > maybe dosemu decides it doesn't need to implement shadow stack (highly > > likely I would think). Now that I think about it, AFAIU SS_AUTODISARM > > was created for dosemu, and the alt shadow stack patch adopted this > > behavior. So it's speculation that there is even a problem in that > > scenario. > > > > Or maybe people just enable WRSS for longjmp() and directly jump back > > to the setjmp() point. Do most people want fast setjmp/longjmp() at the > > cost of a little security? > > > > Even if, with enough discussion, we could optimize for all > > hypotheticals without real user feedback, I don't see how it helps > > users to hold shadow stack. So I think we should move forward with the > > current ABI. > > you may not get a second chance to fix a security feature. > it will be just disabled if it causes problems. *I* would use altshadowstack. I run a production system (that cares about correctness *and* performance, but that's not really relevant here -- SHSTK ought to be fast). And, if it crashes, I want to know why. So I handle SIGSEGV, etc so I have good logs if it crashes. And I want those same logs if I overflow the stack. That being said, I have no need for longjmp or siglongjmp for this. I use exit(2) to escape. For what it's worth, setjmp/longjmp is a bad API. The actual pattern that ought to work well (and that could be supported well by fancy compilers and non-C languages, as I understand it) is more like a function call that has two ways out. Like this (pseudo-C): void function(struct better_jmp_buf &buf, args...) { ... if (condition) better_long_jump(buf); // long jumps out! // could also pass buf to another function ... // could also return normally } better_call_with_jmp_buf(function, args); *This* could support altshadowstack just fine. And many users might be okay with the understanding that, if altshadowstack is on, you have to use a better long jump to get out (or a normal sigreturn or _exit). No one is getting an altshadowstack signal handler without code changes. siglongjmp() could support altshadowstack with help from the kernel, but we probably don't want to go there. --Andy