Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3244504lfo; Sun, 22 May 2022 23:42:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuBZ2lNPyKtD1bCsbv0LD0FUdhlnauSo0+DIu5uON53Py/C7bSql9KXPzEvYd78HubH0ih X-Received: by 2002:a17:90a:d903:b0:1df:a0da:20f0 with SMTP id c3-20020a17090ad90300b001dfa0da20f0mr24456713pjv.182.1653288120190; Sun, 22 May 2022 23:42:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653288120; cv=none; d=google.com; s=arc-20160816; b=H9fUHLjq6muBliN4vfxgnMiVnzMKIbfdZgnmSt6+tDMipde1RlaHq/0u670hI53SLJ iIodizxNafrwXQyUDZPRt3nKC28Nr5xt3lZTT85ajAXG1q4l/EaKCydLMOkojOV0lz5l hBVk0o8CZVp0CHaei1Fth5rkrq52xe5fvv5CVIe4ZOS8NnudFG/neXvufeDvdSgXocfg wUxq0hDpP4rhYmqyBzwFnYf9OhXbrfttPUHg9ZVHRATrFUQDyFgCM7h7l4JQbncxxVIx bkNx4IXJ+pYppwKcowYdhElA9h6bq5FZmvWp/DG5PqCy8DQ6TU1jxtNFFJ6F1/Ay6IlL SKwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=+o3p51pqEerN7F+f1aDvvIt8ccaBMoAdWwg5Y8ORkNM=; b=h+nnmLtJ16ehxZYvQ11AtBY2hgHN7QHsS4xzun6CBSAp1jt9AaNg7aReDHYT8Of1kJ Ovk4K+7RlXWUnQ8DMfepshdz2mnScI4mYMG3vjV0pNoFMbVRxlu2dWtJ3Ip6obMWCg+H MTlw7fHPj9vgeuh92Z1g/3Hm2Yb3XKiA7nSomFXY77o/C2iHDWlYYqzEhjfu6SiTQ0Pt OJ4sIvvDD68hj2/m/YJOrjY+cT6EbIfuqHyFYFS20DTsYHOMI7qA25aZPUVKxixBtYr8 xpLkP+Ynax+FUdEbrXTgatnXp1LaCaHnhHinmCl00TH3HEixV47C6qkRKYxXluDrV9X8 Z78Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s187-20020a6377c4000000b003f5cfdbddadsi10298201pgc.396.2022.05.22.23.41.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 May 2022 23:42:00 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C35664EA3B; Sun, 22 May 2022 23:15:05 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233208AbiEWBSn (ORCPT + 99 others); Sun, 22 May 2022 21:18:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230072AbiEWBSm (ORCPT ); Sun, 22 May 2022 21:18:42 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E491B63; Sun, 22 May 2022 18:18:41 -0700 (PDT) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4L5zvX1KQDz1JC5q; Mon, 23 May 2022 09:17:12 +0800 (CST) Received: from dggpemm500014.china.huawei.com (7.185.36.153) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 23 May 2022 09:18:39 +0800 Received: from [10.174.178.120] (10.174.178.120) by dggpemm500014.china.huawei.com (7.185.36.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 23 May 2022 09:18:37 +0800 Message-ID: <7a1ce182-343a-75f9-5447-f7ca12cb0c36@huawei.com> Date: Mon, 23 May 2022 09:18:37 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH 0/2] Add support to relocate kernel image to mirrored region To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , References: <20220419070150.254377-1-mawupeng1@huawei.com> <7058b8d8-c0cb-108e-0db9-2fdf5fb154cf@huawei.com> From: mawupeng In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.178.120] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, 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 在 2022/5/20 14:52, Ard Biesheuvel 写道: > On Thu, 19 May 2022 at 13:09, mawupeng wrote: >> >> >> >> 在 2022/5/7 17:28, mawupeng 写道: >>> >>> >>> 在 2022/5/3 17:58, Ard Biesheuvel 写道: >>>> 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 > load the image into mirrored memory if it exists; >>> >>> In grub, memory for static image is allocated via the following path: >>> >>> grub_cmd_linux >>> kernel = grub_malloc(filelen) >>> kernel_alloc_addr = grub_efi_allocate_any_pages (kernel_alloc_pages) >>> 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) first? > .