Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp419537ybg; Tue, 22 Oct 2019 23:40:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/kpL1Sl0IAiDPFBq0Lnph+/GTlSundoaTNH0l9s2y9+9Jx4dDyimmTvdmQuBKZ2kf1eDb X-Received: by 2002:a17:906:35cb:: with SMTP id p11mr31866276ejb.128.1571812820205; Tue, 22 Oct 2019 23:40:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571812820; cv=none; d=google.com; s=arc-20160816; b=nWR0tY16Wgo9JDyz1zmTctX/jFKlrdz8bDrnJeFlF+XqwrA55qcq6AIc9XCMiz5rpK 3TXsC+sduh9sEIoCRiYmVCtRccNU6SNgkbhipzacjg9VoxD6lDj0w4a/r13Gx0UGOspb eFDuIX9WLa1eVm4xhChVtsjYBmOck3AzzdvdoP4jF3QRA/6vQ7RfPD+QaCHckPk5c5xC m1ZwQ6wL9Eq080tLGtE7xW8Rz3ew0vb7yAmuRHMsQfqCYR4Df6tsyE8c7xRg965MFe/d eD623C6cG0K3/HVtFpG/UBAG6GVmgMT+m0UFp9pZLV/gzNtdJrBMbMmjNYrFRZ1YnsNl LKpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=rZiwgaG4Q2oxKOaeX7bWyobeJyJbNtWOopUfWLYGvao=; b=Qw9XV6vDYEIPN9oul7GSD7TABmOU0TkHexV7ffYIVxsFm5jZgYorumiJVp1+k6RTWt YDMlnApIXd6HTpKrKXW8UE0op3U/C8ZDeGJGw1UgTCfzuThLLjxS2AE7j5gn22UOXGfJ anr4k+KAxpQ9SyCv9JMojQC/YBGuyiTzwc1+urIntGSa9eXj/OHsN4lNckhTnOWXs0Cg LKXC2Jj4L+yLe2wYY47cJ14uES4PKg1M63H9u/eWD6nDQyGA9voi/SS4jabS9NzQ8CHy WjSAj4I5oPb39Y2GRZ7GHGTv7RC5ZgpepIuWxEIJrPtS1rP82IjJpTFbTSHkuhBZadLc aHWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ci21si12443293ejb.320.2019.10.22.23.39.56; Tue, 22 Oct 2019 23:40:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388927AbfJWGiF (ORCPT + 99 others); Wed, 23 Oct 2019 02:38:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18149 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728697AbfJWGiF (ORCPT ); Wed, 23 Oct 2019 02:38:05 -0400 Received: from mail-il1-f200.google.com (mail-il1-f200.google.com [209.85.166.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9D0192A09B9 for ; Wed, 23 Oct 2019 06:38:04 +0000 (UTC) Received: by mail-il1-f200.google.com with SMTP id h22so11704056ild.19 for ; Tue, 22 Oct 2019 23:38:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rZiwgaG4Q2oxKOaeX7bWyobeJyJbNtWOopUfWLYGvao=; b=KdufJYhgRdZjPM70R5CN06RzKtxw6Istw9iiD7Pjy1gqphIBvanwmwvUkYouRDIOuv uBccLWW6Sx4eoaiSw630teRJDS76zi/o3D7YsKwgjSbxy2sdVq72FmYNfkuRAOKB1Nt1 a3JOZ7NYFqrO6VTOwxKCtJPzcyPB5XYEYuj6V3amUaVv0eUQfHWnmtOlv2qmv18g4DD+ 0Uhzfjd6DiwlegCF08ffhabmIFeXLpUG5g987HxNu0bQVQy2hqW0TtnNZmtTC0WN9Xyh 2aCy0Uh3Gwu6ZtdRCJhANnazSvb/cRCifaK44gbqj5MoHAGKmgTfOh2mw5yZZiXNgz9U nHGQ== X-Gm-Message-State: APjAAAXuuAWCDSJez55FNkwjzK/E4XhiBaH9raqIAXW3wYvmOCeCQaM8 wZm9+IOaiwRh89rlIi22aaBglyJatJPm8+wcaVeKN9UoBEHHI+Sz5YW2TWoe3Pre8DT98xvbAnS ZlLkpEjNrlNaVKOl9ptyob6alClupYOw32fMWgmUk X-Received: by 2002:a6b:c701:: with SMTP id x1mr1787394iof.162.1571812683951; Tue, 22 Oct 2019 23:38:03 -0700 (PDT) X-Received: by 2002:a6b:c701:: with SMTP id x1mr1787376iof.162.1571812683643; Tue, 22 Oct 2019 23:38:03 -0700 (PDT) MIME-Version: 1.0 References: <20191017093020.28658-1-kasong@redhat.com> <20191022074422.GA31700@zn.tnic> In-Reply-To: From: Kairui Song Date: Wed, 23 Oct 2019 14:37:51 +0800 Message-ID: Subject: Re: [PATCH v4] x86, efi: never relocate kernel below lowest acceptable address To: Ard Biesheuvel Cc: Borislav Petkov , Linux Kernel Mailing List , Thomas Gleixner , Ingo Molnar , Matthew Garrett , Jarkko Sakkinen , Baoquan He , Dave Young , "the arch/x86 maintainers" , linux-efi Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 22, 2019 at 6:15 PM Ard Biesheuvel wrote: > > On Tue, 22 Oct 2019 at 09:45, Borislav Petkov wrote: > > > > On Tue, Oct 22, 2019 at 08:13:56AM +0200, Ard Biesheuvel wrote: > > > On Thu, 17 Oct 2019 at 11:30, Kairui Song wrote: > > > > > > > > Currently, kernel fails to boot on some HyperV VMs when using EFI. > > > > And it's a potential issue on all platforms. > > > > > > > > It's caused by broken kernel relocation on EFI systems, when below three > > > > conditions are met: > > > > > > > > 1. Kernel image is not loaded to the default address (LOAD_PHYSICAL_ADDR) > > > > by the loader. > > > > 2. There isn't enough room to contain the kernel, starting from the > > > > default load address (eg. something else occupied part the region). > > > > 3. In the memmap provided by EFI firmware, there is a memory region > > > > starts below LOAD_PHYSICAL_ADDR, and suitable for containing the > > > > kernel. > > > > > > > > EFI stub will perform a kernel relocation when condition 1 is met. But > > > > due to condition 2, EFI stub can't relocate kernel to the preferred > > > > address, so it fallback to ask EFI firmware to alloc lowest usable memory > > > > region, got the low region mentioned in condition 3, and relocated > > > > kernel there. > > > > > > > > It's incorrect to relocate the kernel below LOAD_PHYSICAL_ADDR. This > > > > is the lowest acceptable kernel relocation address. > > > > > > > > The first thing goes wrong is in arch/x86/boot/compressed/head_64.S. > > > > Kernel decompression will force use LOAD_PHYSICAL_ADDR as the output > > > > address if kernel is located below it. Then the relocation before > > > > decompression, which move kernel to the end of the decompression buffer, > > > > will overwrite other memory region, as there is no enough memory there. > > > > > > > > To fix it, just don't let EFI stub relocate the kernel to any address > > > > lower than lowest acceptable address. > > > > > > > > Signed-off-by: Kairui Song > > > > Acked-by: Jarkko Sakkinen > > > > > > > > > > Ingo, Boris, could you please comment on this? > > > > Yah, the commit message makes more sense now. > > > > > Thanks Boris. > > Kairui, I will apply the requested changes myself - no need to spin a v5 Thanks for review and the suggestion, that change is a good idea. -- Best Regards, Kairui Song