Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp5615363ybg; Tue, 22 Oct 2019 06:03:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqzKj/17AQBoX1QadmDqZ9gNJQJbrqLNV4J+na9HIZu6JGZDE2huqFThz1z9PwsM3m/z4oS4 X-Received: by 2002:a17:906:6a4a:: with SMTP id n10mr26964340ejs.23.1571749415542; Tue, 22 Oct 2019 06:03:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571749415; cv=none; d=google.com; s=arc-20160816; b=u0DF6VStS/znFyafTL8VtJ6zwwHX67HTykz/S1XYC+1fXjxX/3fCUJnYvPlyaF4XDS IZDstF71AYG+qPnkJBKxXSEt1VE7D0oISkXTypf7XRW7SRX6rRhXFvdwe6eHY9Hj6Twy zCGqs9Rix4WLVgOyc5FrAwjHCUJzBqVgaNolnt09md5k3GZmvijK1TUK3FzLWKgqd0X4 /ym2BRjbKLSTelALODi8EI5Eol+IxPUIH/BtI0BliW04LsTNsmntpndwLDh42RFzsMpa xkmKrjICpIq/PLeKLCoKCjgA5+QYvC/KgwnmCTrLHDkX5j768fZvbkBts7K1WpMnBV9b o/ig== 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:dkim-signature; bh=bs4FuisA7tS9+U8xJf8/W529cyeyrvU2aBJyOthDVWw=; b=jQlU67DOS1S78TTL554m8qCB8yOistQlpq9S8Fw0vXcJY2We0yU1bMuMlqo7DZOT9Z PZehaI3SFfX1XGq5t+njGsJkEzCwS2iuy2ogE52a3fGDwYL7BCmu1XUFIj0/Vp/RnUCF Sidl226nbBaYnZIv5fYiGOvrFyqBw4LjMdXUEBACj+12aB5VAFry44neCWMyjtd2S/Ax UXD8U6d78OBy5iA3q7nfOV0RquJCrh5+GykH6+OiV7+Wkg1oAwTO44UxtIuUm+/NlzdK VVkMp3lqfzmNwaRYj3/E54OgWXjredNhx2MyY5v4xQnKsqY14ClJTXExI2x82kVYyyDp ithQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PN5rfyxj; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z16si1601935edi.241.2019.10.22.06.02.54; Tue, 22 Oct 2019 06:03:35 -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=@linaro.org header.s=google header.b=PN5rfyxj; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731784AbfJVKPV (ORCPT + 99 others); Tue, 22 Oct 2019 06:15:21 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:50636 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731778AbfJVKPU (ORCPT ); Tue, 22 Oct 2019 06:15:20 -0400 Received: by mail-wm1-f68.google.com with SMTP id q13so6496394wmj.0 for ; Tue, 22 Oct 2019 03:15:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bs4FuisA7tS9+U8xJf8/W529cyeyrvU2aBJyOthDVWw=; b=PN5rfyxjT7AapqUMB+Y7mgH5VSyCVdj5Jn9Slj8OyW8taLbYV2jYyrTmViNLP9cC03 tVgLKPkNPWkehyPE26++c9DZRVajd6Us3QrOAH2+GJqXd5vVSL7TTct/qBS13QHEw0LS Pkp6lpvnqugLw3cBBics6hufuqH/xur5gqhK3ijhqwGTp0pGjDbbzDI4R9mdKyINFLOA 2DDa0c0U3RGF2UhrLeUICJa9i5o0BEvM+AnH2fCHQw6B7beSrg+peyiwvtLZDirbwZlK EPN/oSUG2rTIYSyOpo8xuv8x8DGvmP7bcBK7m8OJXtM40TDw6JckyeJWCMfmhDY1DwIq eKbg== 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=bs4FuisA7tS9+U8xJf8/W529cyeyrvU2aBJyOthDVWw=; b=mwjKSaO/0xWn+3HKmuaCH8NMu8Bz30Lspwi4hvd5X0UUUHZqLz3pewz9cbBtuj2SQQ CZ22mDHLxAoQc7RIzXHZSB4gLGWv92JM2kbmE/Um9hQjQgU5tl0rAYshC+pi8ylIreXl h3MsB02VzUojVuHmrAmjb5pjT78plrgoy5BJSGeW09/G6OkSPF/Opeusi9D3titZ88GQ UIxor15vaAQ5f1zBGABfsAmRaezJznTdPQPLqHCk5YZYQmcER/Yhalmfh+puXg2rgNKE h8nmMOLkTq054alOSFKbr7s3zceTunBgVzv5FHxRWIB7iDr/oNBljTLOorTNwv1hw8y/ +mnA== X-Gm-Message-State: APjAAAVLVY9OS4SpUniHIiXZahXFAeqdny/d+Kj7jWGEeLtXjkGDNzlS iAJaoMZ03a3Zh25YBeolUj7tHSPU4KNVOAozOrgMrA== X-Received: by 2002:a7b:c925:: with SMTP id h5mr2062160wml.61.1571739318364; Tue, 22 Oct 2019 03:15:18 -0700 (PDT) MIME-Version: 1.0 References: <20191017093020.28658-1-kasong@redhat.com> <20191022074422.GA31700@zn.tnic> In-Reply-To: <20191022074422.GA31700@zn.tnic> From: Ard Biesheuvel Date: Tue, 22 Oct 2019 12:15:12 +0200 Message-ID: Subject: Re: [PATCH v4] x86, efi: never relocate kernel below lowest acceptable address To: Borislav Petkov 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 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, 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