Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5151475rwl; Tue, 28 Mar 2023 17:25:51 -0700 (PDT) X-Google-Smtp-Source: AKy350beE/lGbMrlF7FI/R6R0mGk4ctfdSlf2r9IKs/iBRJN34uL3zxye0Tj37Tm2C35En+weF8u X-Received: by 2002:a17:907:6d9b:b0:941:1cf6:dbea with SMTP id sb27-20020a1709076d9b00b009411cf6dbeamr14990201ejc.55.1680049551057; Tue, 28 Mar 2023 17:25:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680049551; cv=none; d=google.com; s=arc-20160816; b=FEZI+6dq2aR0Vu5M4oU1VH03x62n5ODdKWjZ4WYyioypOnSs1db7lhPopH8ckXi25E lz8G8ZcJBVjIZ8IBYH9iFcKtyEeqLu3MFO7XSDnM4jva1LU3fuqut3fsXLe5IUCOsghS Wm1DMdVp0D579vwe02AqqN2hOfPZWliY1qqmWLdj8J7PQl4wFWnnrS3Oi2xoR5cohKhs b4AeSKGNcCoveyFR8k8JHOM7F9b0i8ha7HK946nOJS6PyBxvOeZLe+DCSDgiGWmtQUOg Uj/vkbCsifcOHEyOHvwlZD85wppb716Wm3hX5fb1b05RMm7zPulqQP02KN1ZpsUCIqjC 8JFA== 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=gvRM19O0+ENuKqUmsDi/B/LiIIqhUnSvjpgPO4O58bI=; b=R2uXmibTujNPlapp4ZC4hpKbkDBkdpk/0mCCkPxZ4h6zPzAqWfa77RtnrqB/aej4lK K8X5TVljYiWIC9uxO5Cv5Nomr7wpgHwPg1ymtwNGuRHcs8tGi0/y0RnjmkyYhFxzNxFY 1sft41SG6oBaSTbfTwSDQkL43dn33tFWPi3FXM7gngBA4sW1Tm+c8Jg4mG0UjFUq25Lm 3uk3snM/AWuiIP0Dqrp+YHO3sgkG6SPJRKdfKQSr89d70Wm4PUXQyfeqtn8W4bLv7flQ uHWXQ6NgxusDrZF3tlF7Uowf9vEi4y8WPbbEkg0ctAQb0f3+ieuq+3BRcWL2nqdQMtUW svgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kohoHxDp; 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 vk6-20020a170907cbc600b00935ad387614si11256452ejc.376.2023.03.28.17.25.25; Tue, 28 Mar 2023 17:25:51 -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=kohoHxDp; 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 S229484AbjC2AW5 (ORCPT + 99 others); Tue, 28 Mar 2023 20:22:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229960AbjC2AWx (ORCPT ); Tue, 28 Mar 2023 20:22:53 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9654A1737; Tue, 28 Mar 2023 17:22:52 -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 ams.source.kernel.org (Postfix) with ESMTPS id 3492DB81F81; Wed, 29 Mar 2023 00:22:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C522CC433A7; Wed, 29 Mar 2023 00:22:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680049369; bh=LsCNXXpY1cFgoqXqOINeaOkusUqANiRdFYpk75Ep5Ko=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=kohoHxDpAa2IveHTr7jy9tKAbRaVBIuF6zCV3lP6pauXbsIULM4TR8vENRdV+sRxi s5iplqD8Kf9yZuUxFVFKtOP+MzK3P6mQ+plHNV3Pc1W+xW2+wDzKj3kn/InfhxPQsK qHF5hwPbzf6hYqCZkQ1qNCr6cCtoRhmaEbfCKecP408IxUMGZsGvYWXzz4Y1r4iFB1 9Xot0ltF4q/FhMB1xgQpe0vZApT+GQgGWH02F44s7TDcmGm8Vjo3ijDdx58KOHKl/9 OEFaINyEJDyfWI7phFuz82Mzxc6RoYHFMGbRoekUSjlXIBwyHNiIM0UvnH7TNu3E80 Jn7U1RHYAKRxg== Received: by mail-ed1-f46.google.com with SMTP id y4so56755915edo.2; Tue, 28 Mar 2023 17:22:49 -0700 (PDT) X-Gm-Message-State: AAQBX9eKHwss+occXoM9xv8EadPQtW26OeIzVN2XY2zjcsPsLwHPg0eK y/G3ub58DrCYd8a5V6KmxFzjsFUJHiznFPsRpnQ= X-Received: by 2002:a50:a444:0:b0:4fc:6494:81c3 with SMTP id v4-20020a50a444000000b004fc649481c3mr8371871edb.1.1680049367907; Tue, 28 Mar 2023 17:22:47 -0700 (PDT) MIME-Version: 1.0 References: <20230328111714.2056-1-zhangqing@loongson.cn> <9817aaa043e9f0ed964bd523773447bd64f6e2c0.camel@xry111.site> <1c231587-3b70-22ab-d554-ebe3de407909@loongson.cn> In-Reply-To: <1c231587-3b70-22ab-d554-ebe3de407909@loongson.cn> From: Huacai Chen Date: Wed, 29 Mar 2023 08:22:37 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] LoongArch: Add kernel address sanitizer support To: Qing Zhang Cc: Xi Ruoyao , Andrey Ryabinin , Jonathan Corbet , Andrew Morton , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , WANG Xuerui , Jiaxun Yang , kasan-dev@googlegroups.com, linux-doc@vger.kernel.org, linux-mm@kvack.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable 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, Mar 28, 2023 at 8:15=E2=80=AFPM Qing Zhang = wrote: > > Hi, Ruoyao > > On 2023/3/28 =E4=B8=8B=E5=8D=887:39, Xi Ruoyao wrote: > > On Tue, 2023-03-28 at 19:17 +0800, Qing Zhang wrote: > > > > /* snip */ > > > > > >> -void * __init relocate_kernel(void) > >> +unsigned long __init relocate_kernel(void) > > > > Why we must modify relocate_kernel for KASAN? > > When the CONFIG_RANDOMIZE_BASE is enabled, the kernel will be updated to > a random new address. > Kasan needs to call kasan_early_init before start_kernel. > There are two situations: > 1> After enabling CONFIG_RELOCATABLE, call kasan_early_init. > 2> After CONFIG_RELOCATABLE is not enabled, call kasan_early_init. > > In order to prevent code redundancy and semantic problems caused by > calling kasan_early_init (before jr a0) at the old PC. In my opinion, you can call kasan_early_init before relocate_kernel in head.S, then no redundancy. Huacai > > Thanks, > -Qing > > > >> { > >> unsigned long kernel_length; > >> unsigned long random_offset =3D 0; > >> void *location_new =3D _text; /* Default to original kernel s= tart */ > >> - void *kernel_entry =3D start_kernel; /* Default to original ke= rnel entry point */ > >> char *cmdline =3D early_ioremap(fw_arg1, COMMAND_LINE_SIZE); = /* Boot command line is passed in fw_arg1 */ > >> > >> strscpy(boot_command_line, cmdline, COMMAND_LINE_SIZE); > >> @@ -190,9 +189,6 @@ void * __init relocate_kernel(void) > >> > >> reloc_offset +=3D random_offset; > >> > >> - /* Return the new kernel's entry point */ > >> - kernel_entry =3D RELOCATED_KASLR(start_kernel); > >> - > >> /* The current thread is now within the relocated ker= nel */ > >> __current_thread_info =3D RELOCATED_KASLR(__current_t= hread_info); > >> > >> @@ -204,7 +200,7 @@ void * __init relocate_kernel(void) > >> > >> relocate_absolute(random_offset); > >> > >> - return kernel_entry; > >> + return random_offset; > > >