Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp378746ybf; Wed, 26 Feb 2020 15:01:01 -0800 (PST) X-Google-Smtp-Source: APXvYqy7V2ByavHxFZ6Fx0JsPVHEijr4KDoCQRgN9vsgr/QSaU9urMYCHEmqAsCSsnwMIxSemRd9 X-Received: by 2002:aca:b588:: with SMTP id e130mr1127597oif.176.1582758061140; Wed, 26 Feb 2020 15:01:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582758061; cv=none; d=google.com; s=arc-20160816; b=VysUKxxJwvLJm3X0OeLlKUkIWpFgQu0B4kDvUtgGk1c4axfeDZqCa+L35MZTjny64/ dzxgH88OCXoD8VS3OsybXRHkb1au31KswfnLBBBHB76eGX4pUuX+jkyN5APoCvYIvKl8 0kTAnxB9CbbIAlvJjLe8ujJxrVAUuirp1bLHxpCsKSk8nTfXv1p2ryFyDc8MJmHrXaJk 7vvs3opgU3lCkUJPO6C4rla7QV0hkf6QQCqSj5MdZO094e4iIygXvr1yL3rFgKlB1ml1 gaiv7jBYFGyM7Xw5Ht7P/ZIWC6Wr6dIJBjiS62RK3AeJKwGw3GRHq7nvVM7XsE7AWLsi DuXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=O2Z5RXhPBPSH5s6BhEsyCrcYpDZ4Af1ge3xB8VWs430=; b=jW7rt7T0rvyYQdbtxf/hbsxWArNiOW1l2NxVl9e/e+RL+lTrbh8skZZrVdks5EnGOw TlXZaPZPoid9evwNRmt4HK3ObJfDZ2DPLA2fWuAAUeI7BCcfFD1O5wGNG5CHv45q5cGH KB13ko/gZPkbKLiSyVkFEbKhKRTCxGD4uDWWy8xEiQS9tNqlO15PhL/8dVGZ0dDsI+EP 6yclNMiBF2Tk9EDLndptMY3bcw2/XtjdTjcXGXMYODknqXLVm+HITCiVfKfqdnSywOAq gq4o2p5eWMy7CpAoso4b3O1Y2md9hYFd6xp14MMbFRNX4iKMZZgGyM6XCXEr7xqjnV0b B0fQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z14si469408oth.15.2020.02.26.15.00.47; Wed, 26 Feb 2020 15:01:01 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727930AbgBZXAf (ORCPT + 99 others); Wed, 26 Feb 2020 18:00:35 -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-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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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) /* -- 2.24.1