From patchwork Wed Feb 26 23:00:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arvind Sankar X-Patchwork-Id: 206515 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1696DC4BA2D for ; Wed, 26 Feb 2020 23:00:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E97EA20838 for ; Wed, 26 Feb 2020 23:00:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726413AbgBZXAe (ORCPT ); Wed, 26 Feb 2020 18:00:34 -0500 Received: from mail-qv1-f65.google.com ([209.85.219.65]:34395 "EHLO mail-qv1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727329AbgBZXAe (ORCPT ); Wed, 26 Feb 2020 18:00:34 -0500 Received: by mail-qv1-f65.google.com with SMTP id o18so661983qvf.1; Wed, 26 Feb 2020 15:00:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O2Z5RXhPBPSH5s6BhEsyCrcYpDZ4Af1ge3xB8VWs430=; b=A+fe8+cvLa4z3bup8ukiPGOS8V4ORL8iXCHgLxi2lBr5MtX+NpLBgxen7N6dk9XE41 QjCvEIECn6AJd1DioBdE3ZNZhP6BT3g3T+lpUWJEUEhUX3LzqmbhT0YxbQV1oKrvKTpq Su48q9bFyvVWni6XIsQ9JqVePu/UbwTHe8WL6ytUCrXV+mMXpGOFvIJHElpWSUrF2Xcb Zg+/znfs6WAqt7nhEz86WHSjjGQ2f/nQjMOcIw2d2t6TLf2joyE60mERg9YMdE2JfL2N CiFf2+AExBZ/Wq3rd34RDctM7NE2LAinP7oRQuNxGQuC78hygOr8sjyp8gnbdMWdB/8h I1Hg== X-Gm-Message-State: APjAAAXLJCK64of3eo3AiG/p4xz5BQZB1acGuTBwYgoCW9W/xnQV1kWY bmcSH6BvAmZmSPGKVlCeV2j8MTseoiA= X-Google-Smtp-Source: APXvYqwQDvebgWRZcR5rgX9WQUAm6ZWjwlM4Ts/rzEDjCkMXq76uPkMByJWCZLIUBeBGn8eMUl4O/w== X-Received: by 2002:a0c:c24f:: with SMTP id w15mr1650989qvh.66.1582758032999; Wed, 26 Feb 2020 15:00:32 -0800 (PST) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id t2sm1965323qkc.31.2020.02.26.15.00.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 15:00:32 -0800 (PST) From: Arvind Sankar To: Ingo Molnar Cc: Ard Biesheuvel , linux-efi@vger.kernel.org, Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/1] x86/boot/compressed: Fix reloading of GDTR post-relocation Date: Wed, 26 Feb 2020 18:00:31 -0500 Message-Id: <20200226230031.3011645-2-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200226204515.2752095-1-nivedita@alum.mit.edu> References: <20200226204515.2752095-1-nivedita@alum.mit.edu> MIME-Version: 1.0 Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org 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") --- arch/x86/boot/compressed/head_32.S | 9 ++++----- arch/x86/boot/compressed/head_64.S | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S index 356060c5332c..2f8138b71ea9 100644 --- a/arch/x86/boot/compressed/head_32.S +++ b/arch/x86/boot/compressed/head_32.S @@ -139,12 +139,11 @@ SYM_FUNC_START(startup_32) /* * The GDT may get overwritten either during the copy we just did or * during extract_kernel below. To avoid any issues, repoint the GDTR - * to the new copy of the GDT. EAX still contains the previously - * calculated relocation offset of init_size - _end. + * to the new copy of the GDT. */ - leal gdt(%ebx), %edx - addl %eax, 2(%edx) - lgdt (%edx) + leal gdt(%ebx), %eax + movl %eax, 2(%eax) + lgdt (%eax) /* * Jump to the relocated address. diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index f7bacc4c1494..fcf8feaa57ea 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -456,8 +456,8 @@ trampoline_return: * to the new copy of the GDT. */ leaq gdt64(%rbx), %rax - subq %rbp, 2(%rax) - addq %rbx, 2(%rax) + leaq gdt(%rbx), %rdx + movq %rdx, 2(%rax) lgdt (%rax) /*