Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1377557ybf; Thu, 27 Feb 2020 09:48:24 -0800 (PST) X-Google-Smtp-Source: APXvYqyrUkmidO5RnGv+uLQ8A0/YifdFgqJunQcnEVoQkDZxw6nUc9KReoin4LzpKzvqSTu2s8Pp X-Received: by 2002:a05:6808:358:: with SMTP id j24mr134262oie.89.1582825703971; Thu, 27 Feb 2020 09:48:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582825703; cv=none; d=google.com; s=arc-20160816; b=d3cEvGHec/XdGsOq7sFegMdCIjK7xP1OEvZ/wq8iTckskRrN+aNJTZKK3SjI3bnqSN sbcX16370z7rkzqcquDzbqmVBTAOBH3khw/nMNXJpjKJwoaITRtBmQso/i6tXAtuDWB7 OkIeLjFE7Qbcwd+SGSAQCABcDTFTq0lWLzD7UYxwk0FQ85rYAcZY+lemOukfOzvVVuQ0 NvKZSwsM9NuOlby7LBmo6d1uqpYe2H/Rin75EsJKoItFXsSp7ojE3XBy6XsndZ6FBh7c TMNi5/UKBViX+uIHeWxniHXXdOaGNkkS0zrnHRDpWFT8w8HC1vaidPWHfxz1EI3kXD+h ARdw== 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=4O66Es+LnFjr98geYjAvhlVFKs+EAAKmo8Tn0X5SnQs=; b=Hb5xhfRtVOs5CUwUVpxSsMYUttXWT6nKOmE0X15yptmqVc0wWe9MngNbuO7mfU5ZkO VBx9fDsRf9HravpjqRuB0FH/MqksnjCzyf0qESnujal+/6XHv1WnxZAfgkWxR41BHYKe /dDJY4A6hFnAs2Plw2ITTst9rFbQiAKvw7BR65bPozyB84d90KwXsrHNtqic0TwjB1LP 8UW7/31TBfzyh0jbmKaZk8npo1OG0EHEveDjBaKv69MCgY8TBMh4bDIKUZlEh61K1mgD DTfcEyvrrWZ31k916mX9IlG8d8//ZN2V7nXpIF2ybFxMosaqMv/c7xr+Ao0P04bqnvjK WwCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=orZ1B2H1; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b1si291305oib.79.2020.02.27.09.48.12; Thu, 27 Feb 2020 09:48:23 -0800 (PST) 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=@kernel.org header.s=default header.b=orZ1B2H1; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729603AbgB0RsJ (ORCPT + 99 others); Thu, 27 Feb 2020 12:48:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:54534 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729283AbgB0RsJ (ORCPT ); Thu, 27 Feb 2020 12:48:09 -0500 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0CDD924692 for ; Thu, 27 Feb 2020 17:48:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582825688; bh=r57/uzxhx6F527Q1jCnLyD6LKdGxZuBOjgYgGuaL6es=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=orZ1B2H12EHESRAmQjCp9yQ7M32J865Sij+iYYMpaLnLj1DunIAiEtq2qQ5dGcmDC qSkVQUyH1XsWFMyMK80IDIwEr9Qf3DEhqPBMXuKKUOIaom72jbLIHbUPxrsya5uLwV VuAY6juO68gmeNQ9g+n8CzMqhS6hklsz/cpHMxkw= Received: by mail-wr1-f52.google.com with SMTP id m16so4476523wrx.11 for ; Thu, 27 Feb 2020 09:48:07 -0800 (PST) X-Gm-Message-State: APjAAAUKDYVSJUSo9y5Hg1TMlPDuKaSramzruK814L9+KQzoWwcH9qzY L8Xo8H++RuFBULrhXiWEeFSedrWTfPTAi0VN+KTDWQ== X-Received: by 2002:adf:f84a:: with SMTP id d10mr42297wrq.208.1582825686508; Thu, 27 Feb 2020 09:48:06 -0800 (PST) MIME-Version: 1.0 References: <20200226204515.2752095-1-nivedita@alum.mit.edu> <20200226230031.3011645-2-nivedita@alum.mit.edu> <20200227081229.GA29411@gmail.com> <20200227151643.GA3498170@rani.riverdale.lan> <20200227155421.GA3507597@rani.riverdale.lan> In-Reply-To: <20200227155421.GA3507597@rani.riverdale.lan> From: Ard Biesheuvel Date: Thu, 27 Feb 2020 18:47:55 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/1] x86/boot/compressed: Fix reloading of GDTR post-relocation To: Arvind Sankar Cc: Ingo Molnar , linux-efi , Thomas Gleixner , "the arch/x86 maintainers" , Linux Kernel Mailing List , Borislav Petkov 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 Thu, 27 Feb 2020 at 16:54, Arvind Sankar wrote: > > On Thu, Feb 27, 2020 at 04:21:32PM +0100, Ard Biesheuvel wrote: > > On Thu, 27 Feb 2020 at 16:16, Arvind Sankar wrote: > > > > > > On Thu, Feb 27, 2020 at 09:12:29AM +0100, Ingo Molnar wrote: > > > > > > > > * Arvind Sankar wrote: > > > > > > > > > Commit ef5a7b5eb13e ("efi/x86: Remove GDT setup from efi_main") > > > > > introduced GDT setup into the 32-bit kernel's startup_32, and reloads > > > > > the GDTR after relocating the kernel for paranoia's sake. > > > > > > > > > > Commit 32d009137a56 ("x86/boot: Reload GDTR after copying to the end of > > > > > the buffer") introduced a similar GDTR reload in the 64-bit kernel. > > > > > > > > > > The GDTR is adjusted by init_size - _end, however this may not be the > > > > > correct offset to apply if the kernel was loaded at a misaligned address > > > > > or below LOAD_PHYSICAL_ADDR, as in that case the decompression buffer > > > > > has an additional offset from the original load address. > > > > > > > > > > This should never happen for a conformant bootloader, but we're being > > > > > paranoid anyway, so just store the new GDT address in there instead of > > > > > adding any offsets, which is simpler as well. > > > > > > > > > > Signed-off-by: Arvind Sankar > > > > > Fixes: ef5a7b5eb13e ("efi/x86: Remove GDT setup from efi_main") > > > > > Fixes: 32d009137a56 ("x86/boot: Reload GDTR after copying to the end of the buffer") > > > > > > > > Have you or anyone else observed this condition practice, or have a > > > > suspicion that this could happen - or is this a mostly theoretical > > > > concern? > > > > > > > > Thanks, > > > > > > > > Ingo > > > > > > Right now it's a theoretical concern. > > > > > > I'm working on another patch, to tell the EFI firmware PE loader what > > > the kernel's preferred address is, so that we can avoid having to > > > relocate the kernel in the EFI stub in most cases (ie if the PE loader > > > manages to load us at that address). With those changes, the required > > > adjustment won't be init_size - _end any more, and while fixing it up > > > there, I noticed that it could already be the case that the required > > > adjustment is different. > > > > > > > Do you mean setting the image address in the PE/COFF header to the > > preferred address? > > Yep. I'm doing that and then making a few adjustments to the PE entry > code and head_* so that it can decompress starting at image_base instead > of startup_32. Interesting. I am going to rip most of the EFI handover protocol stuff out of OVMF, since it is mostly unnecessary, and having the PE/COFF loader put the image in the correct place right away is a nice complimentary improvement to that. (Note that the OVMF implementation of the EFI handover protocol does not currently honor the preferred address from the setup header anyway)