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 DFD01C4332F for ; Mon, 20 Dec 2021 09:17:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231429AbhLTJRg (ORCPT ); Mon, 20 Dec 2021 04:17:36 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:34966 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229951AbhLTJRe (ORCPT ); Mon, 20 Dec 2021 04:17:34 -0500 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 3F23660F13; Mon, 20 Dec 2021 09:17:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96F05C36AF8; Mon, 20 Dec 2021 09:17:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639991853; bh=4+z4MVcPf/vwKLP5WpH1FLTAs/YDepAbppw8qxij2dk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=RORZ8FOw5XgCfTedf8Vy4x/Kl7XUma5ObTwalOH2cpItN6PusnsjAaknMoFb9TDJy Vn5HSAelSIcanbH9Z6LicVbjMkXhurbYiqRngLzWVpI/+VSU61pEtjwBO71Rjs/nAR /bnrwbg8l/6JHKBqbP/eov9VvGYmwwazgRY2h8GI8XJ19FbNP4MhaBoBfZH+TOrtWa n1vldrkZQL3PW2zxAV4xWDJh06uQHgnnkUY0HS/V24mZNsvpTT55bujoSNt25Kqqfn ceiu+JZ1RXYw23uIYkXwX9vLzsTf21ndZn0hkkMPkNntjcNVqIPvZTsH1S5WfLqVDz InAVWDfCognMA== Received: by mail-wm1-f49.google.com with SMTP id b186-20020a1c1bc3000000b00345734afe78so6212724wmb.0; Mon, 20 Dec 2021 01:17:33 -0800 (PST) X-Gm-Message-State: AOAM530sFjBLyawhk2EgADOIEtAMpRM8JwfXnWQOGF3hfg0iGHwYaqxe vVyy5ruQTokLcxrGsmiU2ZMC0FQld9SX/xyaKP8= X-Google-Smtp-Source: ABdhPJx5h88IXQvYmswzOZH9pshCavecGzDNWpi0p2Dn/d/bkKU5f+wXghRuyty1pglHInCAdE5taSAXaJWtpT1dxOs= X-Received: by 2002:a1c:1f93:: with SMTP id f141mr4145000wmf.56.1639991851853; Mon, 20 Dec 2021 01:17:31 -0800 (PST) MIME-Version: 1.0 References: <20211206104657.433304-1-alexandre.ghiti@canonical.com> <20211206104657.433304-13-alexandre.ghiti@canonical.com> In-Reply-To: From: Ard Biesheuvel Date: Mon, 20 Dec 2021 10:17:20 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 12/13] riscv: Initialize thread pointer before calling C functions To: Guo Ren Cc: Alexandre Ghiti , Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Zong Li , Anup Patel , Atish Patra , Christoph Hellwig , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Arnd Bergmann , Kees Cook , Guo Ren , Heinrich Schuchardt , Mayuresh Chitale , panqinglin2020@iscas.ac.cn, Linux Doc Mailing List , linux-riscv , Linux Kernel Mailing List , kasan-dev , linux-efi , linux-arch Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 20 Dec 2021 at 10:11, Guo Ren wrote: > > On Tue, Dec 7, 2021 at 11:55 AM Alexandre Ghiti > wrote: > > > > Because of the stack canary feature that reads from the current task > > structure the stack canary value, the thread pointer register "tp" must > > be set before calling any C function from head.S: by chance, setup_vm > Shall we disable -fstack-protector for setup_vm() with __attribute__? Don't use __attribute__((optimize())) for that: it is known to be broken, and documented as debug purposes only in the GCC info pages: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html > Actually, we've already init tp later. > > > and all the functions that it calls does not seem to be part of the > > functions where the canary check is done, but in the following commits, > > some functions will. > > > > Fixes: f2c9699f65557a31 ("riscv: Add STACKPROTECTOR supported") > > Signed-off-by: Alexandre Ghiti > > --- > > arch/riscv/kernel/head.S | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S > > index c3c0ed559770..86f7ee3d210d 100644 > > --- a/arch/riscv/kernel/head.S > > +++ b/arch/riscv/kernel/head.S > > @@ -302,6 +302,7 @@ clear_bss_done: > > REG_S a0, (a2) > > > > /* Initialize page tables and relocate to virtual addresses */ > > + la tp, init_task > > la sp, init_thread_union + THREAD_SIZE > > XIP_FIXUP_OFFSET sp > > #ifdef CONFIG_BUILTIN_DTB > > -- > > 2.32.0 > > > > > -- > Best Regards > Guo Ren > > ML: https://lore.kernel.org/linux-csky/ 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6E44BC433EF for ; Mon, 20 Dec 2021 09:17:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BmXcU42Y9J4JYr7LrsXuWks78jAzJXnCIsktYVNevoE=; b=j4UgXd/37J7BYi riDy4oGERwzbuYLgMj6Czvv9ULqwyWN+feGpOE2rSxiEJrSiJZkWFE2vWZrD1bKBqggWA2pheMd5k DpYf11g23d04zIRCDWsBsG0gGsMixCMSZl8lFU+bKCI78OIqr5em+f3n2HbA7O/5yz84JN/Cy02jx c4kLH0+1Pus/qvwGe3gzCT/xS+TESdqGZErF7O7YlztrXtFUivCkl83sbgV4tiisZoWb+V3Z9mKbq QSq9A4WhSylYvxzehsE2AYj/jnchE68vSSI6ckrwt6Rdfc6nZI62YNBXLfM8KeHbhnlg8WNr8qY5z WDJKIEfi7pc0kUck0Rrw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mzEnb-001NNw-Ry; Mon, 20 Dec 2021 09:17:39 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mzEnX-001NMe-KC for linux-riscv@lists.infradead.org; Mon, 20 Dec 2021 09:17:38 +0000 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 1804560EFF for ; Mon, 20 Dec 2021 09:17:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D6C8C36AEA for ; Mon, 20 Dec 2021 09:17:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639991853; bh=4+z4MVcPf/vwKLP5WpH1FLTAs/YDepAbppw8qxij2dk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=RORZ8FOw5XgCfTedf8Vy4x/Kl7XUma5ObTwalOH2cpItN6PusnsjAaknMoFb9TDJy Vn5HSAelSIcanbH9Z6LicVbjMkXhurbYiqRngLzWVpI/+VSU61pEtjwBO71Rjs/nAR /bnrwbg8l/6JHKBqbP/eov9VvGYmwwazgRY2h8GI8XJ19FbNP4MhaBoBfZH+TOrtWa n1vldrkZQL3PW2zxAV4xWDJh06uQHgnnkUY0HS/V24mZNsvpTT55bujoSNt25Kqqfn ceiu+JZ1RXYw23uIYkXwX9vLzsTf21ndZn0hkkMPkNntjcNVqIPvZTsH1S5WfLqVDz InAVWDfCognMA== Received: by mail-wm1-f42.google.com with SMTP id z206so6416174wmc.1 for ; Mon, 20 Dec 2021 01:17:33 -0800 (PST) X-Gm-Message-State: AOAM532NY6FSGT+GGNNFNjhj11DqDPyhptGL6MqkhFDSVv1DO+RDwIfv VxfF107Tvf0vMf+K+yhgLz3kAoq6NXAUJlUVjxE= X-Google-Smtp-Source: ABdhPJx5h88IXQvYmswzOZH9pshCavecGzDNWpi0p2Dn/d/bkKU5f+wXghRuyty1pglHInCAdE5taSAXaJWtpT1dxOs= X-Received: by 2002:a1c:1f93:: with SMTP id f141mr4145000wmf.56.1639991851853; Mon, 20 Dec 2021 01:17:31 -0800 (PST) MIME-Version: 1.0 References: <20211206104657.433304-1-alexandre.ghiti@canonical.com> <20211206104657.433304-13-alexandre.ghiti@canonical.com> In-Reply-To: From: Ard Biesheuvel Date: Mon, 20 Dec 2021 10:17:20 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 12/13] riscv: Initialize thread pointer before calling C functions To: Guo Ren Cc: Alexandre Ghiti , Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Zong Li , Anup Patel , Atish Patra , Christoph Hellwig , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Arnd Bergmann , Kees Cook , Guo Ren , Heinrich Schuchardt , Mayuresh Chitale , panqinglin2020@iscas.ac.cn, Linux Doc Mailing List , linux-riscv , Linux Kernel Mailing List , kasan-dev , linux-efi , linux-arch X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211220_011735_767500_EE351D6E X-CRM114-Status: GOOD ( 23.20 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Mon, 20 Dec 2021 at 10:11, Guo Ren wrote: > > On Tue, Dec 7, 2021 at 11:55 AM Alexandre Ghiti > wrote: > > > > Because of the stack canary feature that reads from the current task > > structure the stack canary value, the thread pointer register "tp" must > > be set before calling any C function from head.S: by chance, setup_vm > Shall we disable -fstack-protector for setup_vm() with __attribute__? Don't use __attribute__((optimize())) for that: it is known to be broken, and documented as debug purposes only in the GCC info pages: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html > Actually, we've already init tp later. > > > and all the functions that it calls does not seem to be part of the > > functions where the canary check is done, but in the following commits, > > some functions will. > > > > Fixes: f2c9699f65557a31 ("riscv: Add STACKPROTECTOR supported") > > Signed-off-by: Alexandre Ghiti > > --- > > arch/riscv/kernel/head.S | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S > > index c3c0ed559770..86f7ee3d210d 100644 > > --- a/arch/riscv/kernel/head.S > > +++ b/arch/riscv/kernel/head.S > > @@ -302,6 +302,7 @@ clear_bss_done: > > REG_S a0, (a2) > > > > /* Initialize page tables and relocate to virtual addresses */ > > + la tp, init_task > > la sp, init_thread_union + THREAD_SIZE > > XIP_FIXUP_OFFSET sp > > #ifdef CONFIG_BUILTIN_DTB > > -- > > 2.32.0 > > > > > -- > Best Regards > Guo Ren > > ML: https://lore.kernel.org/linux-csky/ _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv