Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp208378pxu; Wed, 2 Dec 2020 20:09:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJyS6Bjtn0hJCEfqrwyMs3192NdJRCGqzk39u9tOVpwVgsOadlz2Bpujs+23saw02MM+TmO2 X-Received: by 2002:a17:906:5293:: with SMTP id c19mr918330ejm.72.1606968571078; Wed, 02 Dec 2020 20:09:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606968571; cv=none; d=google.com; s=arc-20160816; b=jWvw8hpMYU4iaZaAmxo/LtLsR+OHwRodKXvO2MdRiUqdE35CzlEhCHz6AwB82hUyZP 45l4M6X2OTk3zGAA6i4fY4F+9PETIUdqhmUkGjlXrmd3K/dqo4nEHL7w2l1AwBP0ZTeD 6KWlocoflF/ylZ2K4iJwnOMyxYGxGWA+H67sO/hwlulJ2Z6JbxDGyuAG80dsf7BR1UEa /DhmaNk2qLhuteWpzKPqojK07oI5U3qGBhxysX8H16SG4nIjWC1vALg3IYZ2iLoBnrdo L2/Fc7Nk5ajm2mJHNBjT1xLlIAHy5NsFpB+NsK0gSp6BDxknl8cbU326EIksRJohFAHP SSdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature:ai-spam-status:dkim-signature; bh=U9sxXxIAfA523QUwqR3rxpP+FdX/LDBL1ISKYFPzvHs=; b=mpeujdmx9/9kS7WfY+WxEniD3JYguYSXXtMM4eq6tAAeCKReXTId30iBDJFF2AdlzN zP3nlnjVHyGL1Bjyl0nVtHihhDBhNygPnS/miqe1mC/t/6cryOSdxMtpLXziSsw78YrK JItE2Wo7igOrNfi8jubxaOP9E9j/pakWB8mF0Ky1BwNWvJq5chQqHmVSzNGHo/jWRoFH FYg0PcLSQx0VdnXZ4jeexqjcz5x5ocudUI8FiuhH1ocJyEbsmnGEqP2E0/0FCpqaayld zlsTZw3Gq53kXNJ27/JdbHsdPT995ZlQ2Yzqf8vmvKYnQ63Bp2aaC7XmRElK9s8DQu/f qR3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mymailcheap.com header.s=default header.b=ZJRjrmtN; dkim=fail header.i=@flygoat.com header.s=default header.b=otLco1Ht; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=flygoat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hd41si493726ejc.168.2020.12.02.20.09.08; Wed, 02 Dec 2020 20:09:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@mymailcheap.com header.s=default header.b=ZJRjrmtN; dkim=fail header.i=@flygoat.com header.s=default header.b=otLco1Ht; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=flygoat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727077AbgLCEHq (ORCPT + 99 others); Wed, 2 Dec 2020 23:07:46 -0500 Received: from relay5.mymailcheap.com ([159.100.248.207]:55203 "EHLO relay5.mymailcheap.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726071AbgLCEHp (ORCPT ); Wed, 2 Dec 2020 23:07:45 -0500 Received: from relay4.mymailcheap.com (relay4.mymailcheap.com [137.74.199.117]) by relay5.mymailcheap.com (Postfix) with ESMTPS id 4B95D260EC; Thu, 3 Dec 2020 04:06:53 +0000 (UTC) Received: from filter2.mymailcheap.com (filter2.mymailcheap.com [91.134.140.82]) by relay4.mymailcheap.com (Postfix) with ESMTPS id EF6743F1D0; Thu, 3 Dec 2020 05:05:20 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by filter2.mymailcheap.com (Postfix) with ESMTP id C0BBE2A6DF; Thu, 3 Dec 2020 05:05:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mymailcheap.com; s=default; t=1606968320; bh=XX5cAZ6ApL04S+ctlPnZeQ2tjelEaYSXcOgkF4c+I1E=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=ZJRjrmtN8q80lF9OWzDAlXzgYBuUfK+AIHzfpvC028z+xoUNuRFsEdrPDS+hh8ezN a2XlGxsfB52Jik0yR7zVaNHuweeN+rEXypbM/FrO3aSRQZ8fNlb8BLS/tvO6eVyRl2 Z55Q/B4BmppqifbdlqAklzfI3TU9Y36Ep8/uFonc= X-Virus-Scanned: Debian amavisd-new at filter2.mymailcheap.com Received: from filter2.mymailcheap.com ([127.0.0.1]) by localhost (filter2.mymailcheap.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QSXg-aTgmLXV; Thu, 3 Dec 2020 05:05:19 +0100 (CET) Received: from mail20.mymailcheap.com (mail20.mymailcheap.com [51.83.111.147]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by filter2.mymailcheap.com (Postfix) with ESMTPS; Thu, 3 Dec 2020 05:05:19 +0100 (CET) Received: from [148.251.23.173] (ml.mymailcheap.com [148.251.23.173]) by mail20.mymailcheap.com (Postfix) with ESMTP id 25CFF42237; Thu, 3 Dec 2020 04:05:19 +0000 (UTC) Authentication-Results: mail20.mymailcheap.com; dkim=pass (1024-bit key; unprotected) header.d=flygoat.com header.i=@flygoat.com header.b="otLco1Ht"; dkim-atps=neutral AI-Spam-Status: Not processed Received: from [0.0.0.0] (li1861-199.members.linode.com [172.105.207.199]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by mail20.mymailcheap.com (Postfix) with ESMTPSA id C8BC44100D; Thu, 3 Dec 2020 04:05:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=flygoat.com; s=default; t=1606968316; bh=XX5cAZ6ApL04S+ctlPnZeQ2tjelEaYSXcOgkF4c+I1E=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=otLco1HtBp7RnkPms9lDxmEc9TURYAfmI3YU7eI8g43jkGzermOXEA+i1KkXO2t9A qwEe3kjF8ierr/FWXQrn6mvpJpkayr/rDUV0zZItCpnfDw8KwRq9DDeraeFejlrkTe BvCCnzfEZtOUfGj8rEc08WzxvzOuG30FfzOiR2LM= Subject: Re: [PATCH v2 2/2] MIPS: Loongson64: Add KASLR support To: Jinyang He , Thomas Bogendoerfer , Huacai Chen Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org References: <1606298866-7086-1-git-send-email-hejinyang@loongson.cn> From: Jiaxun Yang Message-ID: Date: Thu, 3 Dec 2020 12:05:10 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.3 MIME-Version: 1.0 In-Reply-To: <1606298866-7086-1-git-send-email-hejinyang@loongson.cn> Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Rspamd-Queue-Id: 25CFF42237 X-Spamd-Result: default: False [2.90 / 10.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; RECEIVED_SPAMHAUS_XBL(3.00)[172.105.207.199:received]; R_DKIM_ALLOW(0.00)[flygoat.com:s=default]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; R_SPF_SOFTFAIL(0.00)[~all]; RCPT_COUNT_FIVE(0.00)[5]; ML_SERVERS(-3.10)[148.251.23.173]; DKIM_TRACE(0.00)[flygoat.com:+]; DMARC_POLICY_ALLOW(0.00)[flygoat.com,none]; DMARC_POLICY_ALLOW_WITH_FAILURES(0.00)[]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:24940, ipnet:148.251.0.0/16, country:DE]; RCVD_COUNT_TWO(0.00)[2]; MID_RHS_MATCH_FROM(0.00)[]; HFILTER_HELO_BAREIP(3.00)[148.251.23.173,1] X-Rspamd-Server: mail20.mymailcheap.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ?? 2020/11/25 ????6:07, Jinyang He ะด??: > Provide a weak plat_get_fdt() in relocate.c in case some platform enable > USE_OF while plat_get_fdt() is useless. > > 1MB RELOCATION_TABLE_SIZE is small for Loongson64 because too many > instructions should be relocated. 2MB is enough in present. > > Add KASLR support for Loongson64. > > KASLR(kernel address space layout randomization) > > To enable KASLR on Loongson64: > First, make loongson3_defconfig. > Then, enable CONFIG_RELOCATABLE and CONFIG_RANDOMIZE_BASE. > Finally, compile the kernel. > > To test KASLR on Loongson64: > Start machine with KASLR kernel. > > The first time: > # cat /proc/iomem > 00200000-0effffff : System RAM > 02f30000-03895e9f : Kernel code > 03895ea0-03bc7fff : Kernel data > 03e30000-04f43f7f : Kernel bss > > The second time: > # cat /proc/iomem > 00200000-0effffff : System RAM > 022f0000-02c55e9f : Kernel code > 02c55ea0-02f87fff : Kernel data > 031f0000-04303f7f : Kernel bss > > We see that code, data and bss sections become randomize. > > Signed-off-by: Jinyang He > --- > > v2: > - Define weak plat_get_fdt() in relocate.c > - Add default RELOCATION_TABLE_SIZE for Loongson64 > > arch/mips/Kconfig | 5 ++++- > arch/mips/kernel/relocate.c | 7 +++++++ > 2 files changed, 11 insertions(+), 1 deletion(-) > > diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig > index 0f638bf..44a47ad 100644 > --- a/arch/mips/Kconfig > +++ b/arch/mips/Kconfig > @@ -488,6 +488,7 @@ config MACH_LOONGSON64 > select SYS_SUPPORTS_HIGHMEM > select SYS_SUPPORTS_LITTLE_ENDIAN > select SYS_SUPPORTS_ZBOOT > + select SYS_SUPPORTS_RELOCATABLE > select ZONE_DMA32 > select NUMA > select SMP > @@ -2778,7 +2779,8 @@ config RELOCATABLE > depends on CPU_MIPS32_R2 || CPU_MIPS64_R2 || \ > CPU_MIPS32_R5 || CPU_MIPS64_R5 || \ > CPU_MIPS32_R6 || CPU_MIPS64_R6 || \ > - CPU_P5600 || CAVIUM_OCTEON_SOC > + CPU_P5600 || CAVIUM_OCTEON_SOC || \ > + CPU_LOONGSON64 > help > This builds a kernel image that retains relocation information > so it can be loaded someplace besides the default 1MB. > @@ -2789,6 +2791,7 @@ config RELOCATION_TABLE_SIZE > hex "Relocation table size" > depends on RELOCATABLE > range 0x0 0x01000000 > + default "0x00200000" if CPU_LOONGSON64 > default "0x00100000" Not relevant to the patch but how would we now if the reloc table is to small? Is it possible to have a kind of checking script? Thanks. - Jiaxun > help > A table of relocation data will be appended to the kernel binary > diff --git a/arch/mips/kernel/relocate.c b/arch/mips/kernel/relocate.c > index 8561c7a..57bdd276 100644 > --- a/arch/mips/kernel/relocate.c > +++ b/arch/mips/kernel/relocate.c > @@ -294,6 +294,13 @@ static inline int __init relocation_addr_valid(void *loc_new) > return 1; > } > > +#if defined(CONFIG_USE_OF) > +void __weak *plat_get_fdt(void) > +{ > + return NULL; > +} > +#endif > + > void *__init relocate_kernel(void) > { > void *loc_new;