Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp5297694ybg; Tue, 22 Oct 2019 00:47:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqxo2T0ZARgnQ/DvnoApscc1/VL9j+n5gBMO9Lm31H1U09sEJk8eg+obalIcqYF79EsMV1su X-Received: by 2002:a05:6402:1507:: with SMTP id f7mr29730414edw.68.1571730472419; Tue, 22 Oct 2019 00:47:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571730472; cv=none; d=google.com; s=arc-20160816; b=NDYtLO7lDEn24d2aplvb29mim9IgydMLItlE7WoUdaHu6QXLBPmmZgZP4bdXcG1Xni fiJLnEq+ZIjM86ww9MWuf88MmtoPRl55JaFaI3+pgcKSL2cF+FRXCofcSa36EP6n1Ku6 jDJ9Emc6BvHxVY2HwJCydy6xBEudpydlyC7m5CnuVDjtAKB6QlFoxX28WGrZ3hmVuoj5 VxqxruWYMveqjGwdPgUg/9WSSVcHsTGImL1joowdIRdLbypQpjxEJIY3onz71DggQgR1 JT97GrKEYnkEgDGKS0ZKAdT9+Xd8vdD9b3qKnMtiTCW5bjRzqiZfuNxaiQccpcOpy/9b meGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=3ZuiOtOrGhN5RdAedvLTRxybDphCcw+39KdvlnjWico=; b=xiOnwAAimMij+TYueNwF8gKCjtTWVCG311GZCVcOj7i7G+a4Jrdya49z4EP0Khk8mK gmjXUyBf3ouUg+VuiE70ZlD4gdnBTV3gcOT0SHqrRVtIIkexdDP98uV97fBRc2Y9m9HQ IJST7dRTxERCsQyLf0X6iDrit1UwqSa2uA9zjVBcnpEFqffCpG/0AGQGt8Dif2FS7lxU KY0KB4aQRhKEZ3c9TulrJeC9+CQiihuBpC1bTC2m6Td3jHD1yyPlPRMOYyDCELdCAzL5 aJb8T8JtwCoBM7hkmNDNELZyn432r3zbfdm7ebfZcMlZ7oyOmSeTWH9mac83dz8ji8zg wcQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=oM1KYUcB; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k25si10036096ejs.189.2019.10.22.00.47.28; Tue, 22 Oct 2019 00:47:52 -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; dkim=pass header.i=@alien8.de header.s=dkim header.b=oM1KYUcB; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387977AbfJVHpC (ORCPT + 99 others); Tue, 22 Oct 2019 03:45:02 -0400 Received: from mail.skyhub.de ([5.9.137.197]:42478 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387692AbfJVHpC (ORCPT ); Tue, 22 Oct 2019 03:45:02 -0400 Received: from zn.tnic (p4FED31B8.dip0.t-ipconnect.de [79.237.49.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 220471EC0C5C; Tue, 22 Oct 2019 09:45:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1571730301; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=3ZuiOtOrGhN5RdAedvLTRxybDphCcw+39KdvlnjWico=; b=oM1KYUcBqoXeHpCxTGr4T2mCPDOpn/QS1Fu1A7mp42nW8ZFYkoqyrdjc25nKgwQaJRO16b Da4jkZsNtNck9RHYVDnUG+f71dJ7X3cYlH6cylJLIg90r1l7pATfn1KqM+kBeSYD/032KA AQfYXnUsP/k/wuNcy4CA97yV0Qbgq5s= Date: Tue, 22 Oct 2019 09:44:22 +0200 From: Borislav Petkov To: Ard Biesheuvel Cc: Kairui Song , Linux Kernel Mailing List , Thomas Gleixner , Ingo Molnar , Matthew Garrett , Jarkko Sakkinen , Baoquan He , Dave Young , the arch/x86 maintainers , linux-efi Subject: Re: [PATCH v4] x86, efi: never relocate kernel below lowest acceptable address Message-ID: <20191022074422.GA31700@zn.tnic> References: <20191017093020.28658-1-kasong@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) 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 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. Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette