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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D84F2C433F5 for ; Wed, 29 Sep 2021 15:00:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B9C12613D3 for ; Wed, 29 Sep 2021 15:00:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344932AbhI2PCe (ORCPT ); Wed, 29 Sep 2021 11:02:34 -0400 Received: from smtp-relay-internal-0.canonical.com ([185.125.188.122]:60814 "EHLO smtp-relay-internal-0.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344934AbhI2PC3 (ORCPT ); Wed, 29 Sep 2021 11:02:29 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 8016A40603 for ; Wed, 29 Sep 2021 15:00:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1632927647; bh=vJN7Ck0uNCFG+Ctq/qAp6lWVQYR8Vj2mrO3VtePHdDo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CdndsxOn2Q+HxgVi+RJAQYf0h3YtqonFisO24TFMTMd3xeuqhyo3398X6/Y2eYMZb t8+ZMLRPl2Y9rhk0n//d9ffe3YtUO1ugv5Cvy269sOglS5amFiITcl3ao9qNGghf57 lwVl87qvCCfyaWuSfgrjDRgGUr1r0VxwfpjagziSYPop+bgx6vjgWayvW0CrWLb7/q F66Lcb8ndK1Y/5vNQcr2b/y/XnOfNVBUMXRZ6x8VRCEg8qzgW1RM070HqkyUqPKApR lg1qksiVb4bpUcdQA0egCsdari18BmNoV2uyz3EH8urBTh96xN4FwVUlcgDYPyRtsL DS0LLVif79q9Q== Received: by mail-wm1-f71.google.com with SMTP id y23-20020a05600c365700b003015b277f98so950011wmq.2 for ; Wed, 29 Sep 2021 08:00:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vJN7Ck0uNCFG+Ctq/qAp6lWVQYR8Vj2mrO3VtePHdDo=; b=3hNAIBgnhDVUpSHrIub0WDfoYnw80bgkXPSxDiU738R3Pf/GtMvrBXuHVVW9FD2s2s PoPKzI9+loALlZ7c+/uGS9ULy6KvYBHsgyWapkB4MGZRHKnmCfN6dU55HesNfraJxyiF 5vY2YZWHPe9YM0XP8wJwVxE17kVTodYnuAEP4Tdz+wtM9qOPzYDzH8Qxcd1nE5LWVSDW xElEsMDRypRtDJpYKYuYg+jJIRg5QYIzNp3oTTP1HRULszwkt7MtW0fAs3I9n4Qkjn4W rhlEd3z7BACkEew/43q6f0Dwkb78gzxJ4s6xiX9R9xm2HqfM5+7xDGwLkTdbIxtvy9nu tPWg== X-Gm-Message-State: AOAM531DlPCfSkOZ2fRfPs2xVaYG3cSYlATnmZtU0AzJ7ltGR1YnRS+N F56z4DASds7EqsMuMDPUD2ATTNnK4Kao4ix1Jpg+GkjcxYI+u0JO6oiOw5UVQt783Mstne+Ydch 934AsExx9iXXIKMrLckMPFeQwxpyOJJhPcNhtI9xLOg== X-Received: by 2002:adf:d4cb:: with SMTP id w11mr327562wrk.125.1632927646707; Wed, 29 Sep 2021 08:00:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfXtNjTqRwTy6zB0yjO+6WDv1SXfe8fP/ut2QpPS8jTHw1twOX+D4X0+hshAyxExD632O4tw== X-Received: by 2002:adf:d4cb:: with SMTP id w11mr327526wrk.125.1632927646559; Wed, 29 Sep 2021 08:00:46 -0700 (PDT) Received: from alex.home (lfbn-lyo-1-470-249.w2-7.abo.wanadoo.fr. [2.7.60.249]) by smtp.gmail.com with ESMTPSA id e8sm142306wrr.42.2021.09.29.08.00.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Sep 2021 08:00:46 -0700 (PDT) From: Alexandre Ghiti To: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Zong Li , Anup Patel , Atish Patra , Christoph Hellwig , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Ard Biesheuvel , Arnd Bergmann , Kees Cook , Guo Ren , Heinrich Schuchardt , Mayuresh Chitale , linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-efi@vger.kernel.org, linux-arch@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH v2 09/10] riscv: Initialize thread pointer before calling C functions Date: Wed, 29 Sep 2021 16:51:12 +0200 Message-Id: <20210929145113.1935778-10-alexandre.ghiti@canonical.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210929145113.1935778-1-alexandre.ghiti@canonical.com> References: <20210929145113.1935778-1-alexandre.ghiti@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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 8f21ef339c68..892a25c6079d 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -301,6 +301,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.30.2 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07F05C433FE for ; Wed, 29 Sep 2021 15:01:41 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id CB782613A6 for ; Wed, 29 Sep 2021 15:01:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CB782613A6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IZC6GG3I/iBFkLvlgfYI3BAiLFSwo+6R9agJV9Ilbmk=; b=BYuPNjZH5k12Ye rnVSvnrizBSxTDSdQOX2RzpmkWOhHUZ5dDWpcy5PbkYsmNxOgWS62BDP552OBWjjX/aJ51cZtoOya mmxmN7R6iE6A1psWDtJquatb1YUOORKmPnhBPQqc7SI8SNeFyjs24sZWKre+aPQH2SbpPQJ7uOux6 SG4n5QqrXMN8xGy7cMq9l2NprEzTuPOm2wHBLY8QBKqVRLXzG0No8BaXEqra0K0OcclvWMEljtPJ4 8PSHcm9FX4F4xzbdcdHyzoBAHL5TzWOKcAc8vF9ViGaCq0ur1ROzTdrv/NY54JeNLofDe1nLk4BMd m0Y4s1PVude7CMis+06A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVb5R-00BSR7-He; Wed, 29 Sep 2021 15:01:33 +0000 Received: from smtp-relay-internal-0.canonical.com ([185.125.188.122]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVb4i-00BS5x-Qx for linux-riscv@lists.infradead.org; Wed, 29 Sep 2021 15:00:50 +0000 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 406FD40279 for ; Wed, 29 Sep 2021 15:00:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1632927647; bh=vJN7Ck0uNCFG+Ctq/qAp6lWVQYR8Vj2mrO3VtePHdDo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CdndsxOn2Q+HxgVi+RJAQYf0h3YtqonFisO24TFMTMd3xeuqhyo3398X6/Y2eYMZb t8+ZMLRPl2Y9rhk0n//d9ffe3YtUO1ugv5Cvy269sOglS5amFiITcl3ao9qNGghf57 lwVl87qvCCfyaWuSfgrjDRgGUr1r0VxwfpjagziSYPop+bgx6vjgWayvW0CrWLb7/q F66Lcb8ndK1Y/5vNQcr2b/y/XnOfNVBUMXRZ6x8VRCEg8qzgW1RM070HqkyUqPKApR lg1qksiVb4bpUcdQA0egCsdari18BmNoV2uyz3EH8urBTh96xN4FwVUlcgDYPyRtsL DS0LLVif79q9Q== Received: by mail-wr1-f71.google.com with SMTP id r15-20020adfce8f000000b0015df1098ccbso708212wrn.4 for ; Wed, 29 Sep 2021 08:00:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vJN7Ck0uNCFG+Ctq/qAp6lWVQYR8Vj2mrO3VtePHdDo=; b=hMlETfNL211/hloKC++zgWK+gqNGou7r0KXvDnUs/uqP8eVMfUsB1/Y5lJdhadKRqS PevZe3zIhL8/Nk9WOZ18nPPX/BwRxwbQQ58cLnPY+qpYkre6LcIlAEORke9kHmf+inny fZ6jsXm04mvZmhrVuCrUZcmOiiH+UWLvnAb8Qk1BaIjUxl/0QW9q5CiBnC9cXZ9/vpYI Wl4of5lpSb8nLTKWchKuwssU1g3QS+7b7c4Te8XWzNNnzbfrfZQJBZQVWAgP304DROVZ b0m3RCQ1D44e/7Aj6GRJCLPX5sblbTJeBKabrOkgf1pxZ/FP46grBk5rLj2znWrrILXV iq2Q== X-Gm-Message-State: AOAM5331h1CWtrBYYb2JdYeoErmVsLivCtNb1eQxj+mbd5kMkBG1OFC0 YQHqCEn1rNRScWxGFs4mqHGhHPVySDdfEPrnae5zkBRN1cbXTyyObeIu0Yjh/HgY5UizidfPPfp yPdNA+ythaseQy/9x4KmI3BJrmsxihVcXBWL0CTULls1YfA== X-Received: by 2002:adf:d4cb:: with SMTP id w11mr327561wrk.125.1632927646707; Wed, 29 Sep 2021 08:00:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfXtNjTqRwTy6zB0yjO+6WDv1SXfe8fP/ut2QpPS8jTHw1twOX+D4X0+hshAyxExD632O4tw== X-Received: by 2002:adf:d4cb:: with SMTP id w11mr327526wrk.125.1632927646559; Wed, 29 Sep 2021 08:00:46 -0700 (PDT) Received: from alex.home (lfbn-lyo-1-470-249.w2-7.abo.wanadoo.fr. [2.7.60.249]) by smtp.gmail.com with ESMTPSA id e8sm142306wrr.42.2021.09.29.08.00.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Sep 2021 08:00:46 -0700 (PDT) From: Alexandre Ghiti To: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Zong Li , Anup Patel , Atish Patra , Christoph Hellwig , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Ard Biesheuvel , Arnd Bergmann , Kees Cook , Guo Ren , Heinrich Schuchardt , Mayuresh Chitale , linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-efi@vger.kernel.org, linux-arch@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH v2 09/10] riscv: Initialize thread pointer before calling C functions Date: Wed, 29 Sep 2021 16:51:12 +0200 Message-Id: <20210929145113.1935778-10-alexandre.ghiti@canonical.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210929145113.1935778-1-alexandre.ghiti@canonical.com> References: <20210929145113.1935778-1-alexandre.ghiti@canonical.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210929_080049_042435_D39B02AF X-CRM114-Status: GOOD ( 12.78 ) 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 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 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 8f21ef339c68..892a25c6079d 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -301,6 +301,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.30.2 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv