Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp4893515rwb; Tue, 20 Sep 2022 23:28:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7vTYmbXWKqSZKjEE71EmdlBNTrSm7RUNfDTxarzvrQdfCemKXz+Y8k1CjBMpMKtQsg9asQ X-Received: by 2002:a17:902:d50b:b0:178:3ea4:2945 with SMTP id b11-20020a170902d50b00b001783ea42945mr3199477plg.67.1663741686889; Tue, 20 Sep 2022 23:28:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663741686; cv=none; d=google.com; s=arc-20160816; b=XKebiowbwhhdveXEQ5B0AcQ7C4MTviy/6M6+t4Leo7KyvWb4R+CWhdsFMy6Jkhj/DI j1d6kczBV+Q47StWyNnEgLnwCOwZHiO/eDJgNkhzQ1WdBGiN0xl+kcuaAQgGB68Wedd3 f8Ux9GDWtdV+kJaUysCnewlFXl+iFojSGrBuO6IkHM5mnbPfAb5lzYMDq1ITbUO2WYi6 Q8O7bAjpRFG6COQq4OyaPz9F78HKS/DIuJ0SiwUyUu2i1yQLxWtz65KU7Gdap+frLk9a 5D6HR9aUYuyrAlBwUi57cB8VTzconGhzbfkic3e9FH5ev3XG4QyopPAw3IN3Cj4EiBYP OZZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=UNktt/PlP8+uFm/qsQSWW2wju+pQ4vV5gaSEJWCWApU=; b=qcXEYiQkUeDTzQyw1dmcXwwHbMUBrCcmFE9E/6ohfHfH41UmCL4cMweA6jI275wL5l F9f7xZb8f8edPTDqFns6EV1qNj6UMhmZjQcenF0KxwGnjYfu1iTEECF4GN0zwuR9Es0s AH76PwfDSnIJfz4Up331CXy41JJK84ynGwiVMzDdWCSvm25f7zLd2GR2A3H2qd1SDIuH 5LRLmF/5rQqWtsnwdMln26PnFpeT4alEbewxYwQNy39KjCQUuc7ge15375JPJX67FDtW N66avPcqI9dTCDU/7/8rZOUP3e/6LqGvLvUaSLpAyQqEhgLcSvQ/Lz4tH22i6wtxFJoy 4mYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="rb9o1/w9"; 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 u16-20020a17090ae01000b0020078b1be88si1725343pjy.23.2022.09.20.23.27.54; Tue, 20 Sep 2022 23:28:06 -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="rb9o1/w9"; 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 S229751AbiIUGQT (ORCPT + 99 others); Wed, 21 Sep 2022 02:16:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229606AbiIUGQR (ORCPT ); Wed, 21 Sep 2022 02:16:17 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E7117FE7E; Tue, 20 Sep 2022 23:16:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C6FAE6237F; Wed, 21 Sep 2022 06:16:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D2A9C43143; Wed, 21 Sep 2022 06:16:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663740976; bh=cNqXuM4/r1oFK58tkWe1aNJ1OBze/WTcp9aFMeMbeMM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=rb9o1/w9KyR+0qq4bAv7Ys8e0MjLjiM6hglaayZCV1n9XdVdl71DqeurYgYuHEr7m llwnKslrNGyuuSxETwvf1PlnAsJpgsHutrQBlSly53VjIMroowyLF038KEInV8RsS0 cjUfbD6+PwMrbJHfeIQQg2RkyS1RTOySgXb54zQxmko3GF56TQzqIFqM+8nXBsDrqO AIljj2ZKCDcF6hZzxAD6ePG0i1AEnV1y89pAy99Y5aqTeFdbvF1Wec8LjEPx8hovKH etpbY9XAFA2BfR+SRV6ZQWm2Rfm4BABhc7Mb5ed3i5Exa9uSPT6XzfG0BoNHhMttPz ylp2+gTDiPTTA== Received: by mail-oa1-f51.google.com with SMTP id 586e51a60fabf-127dca21a7dso7590331fac.12; Tue, 20 Sep 2022 23:16:16 -0700 (PDT) X-Gm-Message-State: ACrzQf00tqoMbLWmkypMdxbovx/EU96VxvimeUWroBdoWrnj2XM98McI ciz3eIIUGXKZwUJJeVndVwhejQh5oAIaah6PtkI= X-Received: by 2002:a05:6870:5803:b0:12c:c3e0:99dc with SMTP id r3-20020a056870580300b0012cc3e099dcmr3993282oap.19.1663740975257; Tue, 20 Sep 2022 23:16:15 -0700 (PDT) MIME-Version: 1.0 References: <20220918155246.1203293-1-guoren@kernel.org> <20220918155246.1203293-9-guoren@kernel.org> In-Reply-To: From: Guo Ren Date: Wed, 21 Sep 2022 14:16:03 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH V5 08/11] riscv: Support HAVE_IRQ_EXIT_ON_IRQ_STACK To: Peter Zijlstra Cc: arnd@arndb.de, palmer@rivosinc.com, tglx@linutronix.de, luto@kernel.org, conor.dooley@microchip.com, heiko@sntech.de, jszhang@kernel.org, lazyparser@gmail.com, falcon@tinylab.org, chenhuacai@kernel.org, apatel@ventanamicro.com, atishp@atishpatra.org, palmer@dabbelt.com, paul.walmsley@sifive.com, mark.rutland@arm.com, zouyipeng@huawei.com, bigeasy@linutronix.de, David.Laight@aculab.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Guo Ren , keescook@chromium.org Content-Type: text/plain; charset="UTF-8" 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 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 Tue, Sep 20, 2022 at 3:34 PM Peter Zijlstra wrote: > > On Tue, Sep 20, 2022 at 09:27:51AM +0200, Peter Zijlstra wrote: > > On Tue, Sep 20, 2022 at 02:08:55PM +0800, Guo Ren wrote: > > > On Mon, Sep 19, 2022 at 9:45 PM Peter Zijlstra wrote: > > > > > > > > On Sun, Sep 18, 2022 at 11:52:43AM -0400, guoren@kernel.org wrote: > > > > > > > > > +ENTRY(call_on_stack) > > > > > + /* Create a frame record to save our ra and fp */ > > > > > + addi sp, sp, -RISCV_SZPTR > > > > > + REG_S ra, (sp) > > > > > + addi sp, sp, -RISCV_SZPTR > > > > > + REG_S fp, (sp) > > > > > + > > > > > + /* Save sp in fp */ > > > > > + move fp, sp > > > > > + > > > > > + /* Move to the new stack and call the function there */ > > > > > + li a3, IRQ_STACK_SIZE > > > > > + add sp, a1, a3 > > > > > + jalr a2 > > > > > + > > > > > + /* > > > > > + * Restore sp from prev fp, and fp, ra from the frame > > > > > + */ > > > > > + move sp, fp > > > > > + REG_L fp, (sp) > > > > > + addi sp, sp, RISCV_SZPTR > > > > > + REG_L ra, (sp) > > > > > + addi sp, sp, RISCV_SZPTR > > > > > + ret > > > > > +ENDPROC(call_on_stack) > > > > > > > > IIRC x86_64 moved away from a stack-switch function like this because it > > > > presents a convenient exploit gadget. > > > I found: > > > https://lore.kernel.org/all/20210204204903.350275743@linutronix.de/ > > > > > > - The fact that the stack switching code ended up being an easy to find > > > exploit gadget. > > > > > > What's the exploit gadget? Do you have a ref link? Thx. > > > > Sadly no, I do not. Kees might. But basically it boils down to this > > function taking both a stack pointer and a function pointer as > > arguments (@a1 and @a2 resp. if I'm not reading this wrong). > > > > If an attacker can call this with arguments of its choice then it gains > > full control of subsequent execution. > > If you inline it the hope is that the function pointers go away or at > least the encompassing function doesn't have quite such a 'convenient' > signature to hijack control flow. Thanks for mentioning it. I would change to an inline style. -- Best Regards Guo Ren