Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1989778ioo; Mon, 23 May 2022 07:43:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5rbo9gc59DTQ86LuVVIECA92LZX1B2SUTDifG3el0e37PRRk8Zk/wmkfd57YdxjshsLDM X-Received: by 2002:a17:902:728c:b0:161:f216:4f3c with SMTP id d12-20020a170902728c00b00161f2164f3cmr17036823pll.65.1653317029281; Mon, 23 May 2022 07:43:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653317029; cv=none; d=google.com; s=arc-20160816; b=FkCglqey1LHm918/zxqRQOugBNnAjAgUhfBd5zqZEVV8ovbBl1/NhGd6bsth9LxoQ4 114ucW5aGzeNkgBopOT2yp9Cvv8o3swePGTapLhDfZ62qzRy41KYc5SJSbXZgtC1GlpK aYjNNzFl6iv3uIxkOy9o8GjS+JoRXHAaRX3/gTCpDLAfkcO/69jmePVQjyfqm6A+/n1b GSmThNFcjPcnMVOGCxZO0fJBC6SVH6hsfOUThnVxhPW2U1tAJO3UDjMy3A9t4wINK+JA tiv65maeYhJMwEGhzXJJJVg/n9Vs5HC9X11mReKb9ofYPrW2+XY/Fv1Sf/OAXnjO1r75 0Tow== 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=Yrmacu8yCWCFVyeHkWWnlAqp+pBIZdBSBMzy7HatWxw=; b=fklYOQhNrriWveNQ2QCUVKSA5EU+HRchRWYCI6zFNeMDO4/3bb1CGU8MSJHk0XOeCY 57wi13ncq6YF4vD3fe14eUf6/MUHyr53iYVSxs9854oXvqoG5jMm0auaA3mV/92OkJnN sBKaR5JRCs8fV6LraUr1j0f5pNp+lXYU8DNBbcWdP3EIlS9xx6hVZfJmOvPtYQpskLnB n/oM4DU5FfB+UE0Ayn09Dy4m3LqK0qDP9QI2Jl3h1jpQbdjZnDI5MOPTrFYV0fewMvtR XehITWAvWxvmDE21hHM3E1I5o7B181o8f8av0V7DHUlE4LkNkjgmOkzxVvDK5fe9tgZg XmJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qjvyhsay; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m8-20020a654388000000b003f74c638f75si9645169pgp.857.2022.05.23.07.43.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 07:43:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qjvyhsay; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E264C2CDFF; Mon, 23 May 2022 07:42:22 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237284AbiEWOmQ (ORCPT + 99 others); Mon, 23 May 2022 10:42:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237280AbiEWOmO (ORCPT ); Mon, 23 May 2022 10:42:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FBB126AFB; Mon, 23 May 2022 07:42:12 -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 dfw.source.kernel.org (Postfix) with ESMTPS id CB989611E3; Mon, 23 May 2022 14:42:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36000C3411C; Mon, 23 May 2022 14:42:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653316931; bh=+pn/Aag3Y2GhS2+/HoXWr9nr1Lt0Lmr9+7jaO0VvYuo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=qjvyhsayW0yHC6C3Z5GhrrVaWktvr8ASpC9Olc1tkAMJAij5GQY58GuMcrLFNW/9A C1JZzzjUTOjbY5sZwjkUowiJxSLMFNh8CbOvLRCiPsdrZExkCaahITJqIt0MsC4cO/ 1/hPHMUppuqcI6KFdmdvfsBG2c9hwzCqjJdqHfbVf+moydsrWg3YUYScIS+3Uyv1Uc Q3hDIucWEQpEmvlFo04X8piythLawYiFP/yJrO/aaxOhChVzd6y4imeoZWXJ1DxRlM eUOJGB7+bFZF3nT+fChRSoQJ1/oUpWimV9wlZG4fjj+jC7LE9HsxVXxzAxxjPzV16V Jt4ogDhn+fSPQ== Received: by mail-oa1-f41.google.com with SMTP id 586e51a60fabf-e93bbb54f9so18680543fac.12; Mon, 23 May 2022 07:42:11 -0700 (PDT) X-Gm-Message-State: AOAM533d6axMe3YHv3xOX0YZqXF+RnCjcVqcWQuZKSg7mFdw5BHfT3Ey nFLHVHjaTbLmueRCe46iyG9BAPo3jt5wSQe0d9A= X-Received: by 2002:a05:6870:f112:b0:f1:f1e9:e8f1 with SMTP id k18-20020a056870f11200b000f1f1e9e8f1mr11327387oac.126.1653316930318; Mon, 23 May 2022 07:42:10 -0700 (PDT) MIME-Version: 1.0 References: <20220419070150.254377-1-mawupeng1@huawei.com> <7058b8d8-c0cb-108e-0db9-2fdf5fb154cf@huawei.com> <7a1ce182-343a-75f9-5447-f7ca12cb0c36@huawei.com> In-Reply-To: <7a1ce182-343a-75f9-5447-f7ca12cb0c36@huawei.com> From: Ard Biesheuvel Date: Mon, 23 May 2022 16:41:58 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 0/2] Add support to relocate kernel image to mirrored region To: mawupeng Cc: Andrew Morton , Catalin Marinas , Will Deacon , Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , X86 ML , Darren Hart , Andy Shevchenko , Mike Rapoport , "Paul E. McKenney" , Peter Zijlstra , Joerg Roedel , songmuchun@bytedance.com, macro@orcam.me.uk, Frederic Weisbecker , W_Armin@gmx.de, John Garry , Sean Christopherson , Thomas Bogendoerfer , Anshuman Khandual , chenhuacai@kernel.org, David Hildenbrand , gpiccoli@igalia.com, Mark Rutland , Kefeng Wang , Linux Doc Mailing List , Linux Kernel Mailing List , Linux ARM , linux-efi , linux-ia64@vger.kernel.org, platform-driver-x86@vger.kernel.org, Linux Memory Management List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 Mon, 23 May 2022 at 03:18, mawupeng wrote: > > > > =E5=9C=A8 2022/5/20 14:52, Ard Biesheuvel =E5=86=99=E9=81=93: > > On Thu, 19 May 2022 at 13:09, mawupeng wrote: > >> > >> > >> > >> =E5=9C=A8 2022/5/7 17:28, mawupeng =E5=86=99=E9=81=93: > >>> > >>> > >>> =E5=9C=A8 2022/5/3 17:58, Ard Biesheuvel =E5=86=99=E9=81=93: > >>>> On Tue, 19 Apr 2022 at 08:43, Wupeng Ma wrote= : > >>>>> > >>>>> From: Ma Wupeng > >>>>> > >>>>> Now system image will perfer to be located to mirrored regions both= KASLR > >>>>> on and off. > >>>>> > >>>> > >>>> Hello Ma Wupeng, > >>>> > >>>> I wonder if we could simplify this as follows: > >>>> - ignore the non-KASLR case for now, and rely on the bootloader > l= oad the image into mirrored memory if it exists; > >>> > >>> In grub, memory for static image is allocated via the following path: > >>> > >>> grub_cmd_linux > >>> kernel =3D grub_malloc(filelen) > >>> kernel_alloc_addr =3D grub_efi_allocate_any_pages (kernel_alloc_p= ages) > >>> grub_memcpy (kernel_addr, kernel, grub_min(filelen, kernel_size)) > >>> grub_loader_set (grub_linux_boot, grub_linux_unload, 0) > >>> > >>> Can we get memory from mirrored region by the following steps: > >>> 1. get memory map by calling grub_efi_get_memory_map() > >>> 2. iter all memory map to find a suitable mirrored memory area > >>> 3. locate kernel image to this area > >>> > >>> So, if kaslr is not enabled > >>> - grub will load kernel into mirrored region > >>> else > >>> - arm64-stub.c will relocate kernel image to mirrored region > >>> > >>> Is this feasible? > >> > >> Is this a feasible proposal to relocate the static kernel image itself > >> into more reliable memory? > >> > > > > I'm not sure, it all depends on the firmware. > > > > When GRUB calls LoadImage(), the firmware will reallocate the image > > and unpack it there. So it is really the firmware's job to ensure that > > the image is loaded into a suitable location. > > > > I have some code here that implements a EFI based decompressor, and > > which loads the kernel image into mirrored memory if it exists, > > without the need to move it again. It could trivially be modified to > > deal with non-randomized loads as well. > > > > But the bottom line is that UEFI should expose the ability to target > > mirrored memory, hacking around it like this is not a sustainable > > approach. > > Since firmware is responsible for put kernel static image into mirrored > region and kernel is responsible for relocate this image into mirrored > region if kaslr is enabled. There is no conflict between these two. > > Can we integrate the kernel part(introduce mirrored support to arm64) fir= st? > Yes. If you drop the changes related to fake memmap and rebase, please resend them after -rc1 is released.