Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp268526ybf; Wed, 26 Feb 2020 12:46:27 -0800 (PST) X-Google-Smtp-Source: APXvYqxn7knaCg78hrGfmOBS319Bx7YPye2+yO+qYp5mIDE9oabxYyORcUM6HwEHCMRDv5olFPLz X-Received: by 2002:a9d:6d10:: with SMTP id o16mr573904otp.28.1582749986837; Wed, 26 Feb 2020 12:46:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582749986; cv=none; d=google.com; s=arc-20160816; b=UUPsgx+4VbiSqcD4XTS9Ivho2EW6R11cpSncd5a/twSmA0U7PJJft2muTsASsf5shW Y8gW2DZaPR56zxKua8blay+MIWqFuiWMGdMxd3F+IjZJuhnmgYdCbWZhAT2ZoDJwKVAU tSOOJqUmVvb3boXG2NC/SRch1uWewuQCiWijsFkgaeRjpgyYN2uo08lg6x2hSNCGn3KI sTC0zQ9PeWyYQS27tQaMdFZlLOf+zbssx6ct8U3S5CS1R6+bPXi32p2uqMN175qGuORw z3eMki5Ror3jV2iNU9xRKr2S+SxhASwmFUgJjsykmSBS1mAtXwy2qc8lFAgVN/VFbHU1 3Ptg== 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=IzShkJtnyIf+SHrtUdVXXyo8uuVvUhx7/kmHbI9SwSg=; b=QurbwG9y2ZtwDdXypGmcEXrHfdqffMvMalNW2ItsmkUmKNMfYQlcysCrKzMRMp5OMN 8a9JfliyWTLz4+muELkN9zmvORXXTpW5kMYvmF7raUPY9oQd2H9IavJS/fOz7YX9RpV5 acTcHRr18M3KNL/683gIJTm27JgDCr9VmT5QgWNX0Pyoa4F4wjq6k2Ieqh8d0VG1/rUD U4N5zoxRYxqvjPmwTECHGp0bHq0zYndbT8QOp8L5Ixw/lP8iW69TjrBOnFaMgXeAbuzm xJN/5jcLjnpQAzA5I8Uy8Ymg4Dav8rXdXxLlRUQqcA3JNGESkPXhPMNbXgtwouH3Y96T ye2Q== 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 i15si329405otk.120.2020.02.26.12.46.14; Wed, 26 Feb 2020 12:46:26 -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 S1727578AbgBZUpT (ORCPT + 99 others); Wed, 26 Feb 2020 15:45:19 -0500 Received: from mail-qt1-f193.google.com ([209.85.160.193]:41544 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727425AbgBZUpS (ORCPT ); Wed, 26 Feb 2020 15:45:18 -0500 Received: by mail-qt1-f193.google.com with SMTP id l21so574279qtr.8; Wed, 26 Feb 2020 12:45:18 -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=IzShkJtnyIf+SHrtUdVXXyo8uuVvUhx7/kmHbI9SwSg=; b=i+a+d3HCgax6Bu00dAjuaBfr1Ot+zdAKV0hNW3rSUt2SsAXKckS9BEles6wyssgRXD YEOpZxqoFcWZFncUegy6txmhQTUwjL+nsXTmKsEpv8vR8+kQ+ke1/l5/RuBf+m7TUbSe 3ldahMe2Uo8RVZ+QyG1tzRVYxcmd8WV9CWu8viWLgXUv5Dbkm0cgksBA+ogbSupOqsOl /LkM7U2XilWsGEk5ppHfrXnulZSq+9t2O0HR3gObOqTcmV68tyu/CNEJvroBP4heclot TugLYEOX3qDdOwGHfP9mN6l5FAmH7RnD38e30qNrgTPonSf/xXWbzX+1biqWl01rEVdV ZKwQ== X-Gm-Message-State: APjAAAXQgenoyPYdd4GC/2LH4sMig7IKkJpJa3QrRIOzGsuqvtSci02V W12oLCZbQZMubBFQuQ0CATc= X-Received: by 2002:aed:2a05:: with SMTP id c5mr724563qtd.361.1582749917618; Wed, 26 Feb 2020 12:45:17 -0800 (PST) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id f26sm1651452qtv.77.2020.02.26.12.45.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 12:45:17 -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 1/1] x86/boot/compressed/32: Fix reloading of GDTR post-relocation Date: Wed, 26 Feb 2020 15:45:15 -0500 Message-Id: <20200226204515.2752095-2-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200226142713.GB3100@gmail.com> References: <20200226142713.GB3100@gmail.com> 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 startup_32, and reloads the GDTR after relocating the kernel for paranoia's sake. 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") --- arch/x86/boot/compressed/head_32.S | 9 ++++----- 1 file changed, 4 insertions(+), 5 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. -- 2.24.1