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 D8DB4C76196 for ; Fri, 31 Mar 2023 13:38:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232182AbjCaNiw convert rfc822-to-8bit (ORCPT ); Fri, 31 Mar 2023 09:38:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231313AbjCaNiv (ORCPT ); Fri, 31 Mar 2023 09:38:51 -0400 Received: from gloria.sntech.de (gloria.sntech.de [185.11.138.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A3D6469A for ; Fri, 31 Mar 2023 06:38:49 -0700 (PDT) Received: from ip4d1634d3.dynamic.kabel-deutschland.de ([77.22.52.211] helo=diego.localnet) by gloria.sntech.de with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1piExm-0003vk-Sw; Fri, 31 Mar 2023 15:38:42 +0200 From: Heiko =?ISO-8859-1?Q?St=FCbner?= To: linux-riscv@lists.infradead.org, palmer@dabbelt.com, anup@brainfault.org, atishp@atishpatra.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org Cc: vineetg@rivosinc.com, greentime.hu@sifive.com, guoren@linux.alibaba.com, ShihPo Hung , Vincent Chen , Andy Chiu , Paul Walmsley , Albert Ou , Conor Dooley , Masahiro Yamada , Alexandre Ghiti , Guo Ren , Andy Chiu Subject: Re: [PATCH -next v17 16/20] riscv: prevent stack corruption by reserving task_pt_regs(p) early Date: Fri, 31 Mar 2023 15:38:41 +0200 Message-ID: <14872268.tv2OnDr8pf@diego> In-Reply-To: <20230327164941.20491-17-andy.chiu@sifive.com> References: <20230327164941.20491-1-andy.chiu@sifive.com> <20230327164941.20491-17-andy.chiu@sifive.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset="iso-8859-1" Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Am Montag, 27. März 2023, 18:49:36 CEST schrieb Andy Chiu: > From: Greentime Hu > > Early function calls, such as setup_vm(), relocate_enable_mmu(), > soc_early_init() etc, are free to operate on stack. However, > PT_SIZE_ON_STACK bytes at the head of the kernel stack are purposedly > reserved for the placement of per-task register context pointed by > task_pt_regs(p). Those functions may corrupt task_pt_regs if we overlap > the $sp with it. In fact, we had accidentally corrupted sstatus.VS in some > tests, treating the kernel to save V context before V was actually > allocated, resulting in a kernel panic. > > Thus, we should skip PT_SIZE_ON_STACK for $sp before making C function > calls from the top-level assembly. > > Co-developed-by: ShihPo Hung > Signed-off-by: ShihPo Hung > Co-developed-by: Vincent Chen > Signed-off-by: Vincent Chen > Signed-off-by: Greentime Hu > Signed-off-by: Andy Chiu > Reviewed-by: Conor Dooley Reviewed-by: Heiko Stuebner Tested-by: Heiko Stuebner