Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2183194ybl; Sat, 11 Jan 2020 11:02:33 -0800 (PST) X-Google-Smtp-Source: APXvYqwfg5K2Q818HuGnWxvUodDdmcOQFO35FrHcdAsE8XxHizSgFfM16NETDloA4dC9uZi2gXIK X-Received: by 2002:a05:6830:22e2:: with SMTP id t2mr7840713otc.129.1578769352989; Sat, 11 Jan 2020 11:02:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578769352; cv=none; d=google.com; s=arc-20160816; b=dn2afdGAlnVOnJ8xmib/GopOVXfvZgMXkHxHRVZzaYBWHhkGeeyf7FYreq+YBQRx9+ KicZXayaLXLi9mlIrHox7I29nEDKaER4xeeV0Xgbnr0iaAULrud3ePCS/0H/5+GE5OD4 dbACZ0rdiL6LgEaITuSesc7c3U8r74CGyB3Ju3RaLQaR2Heb4qOvlJlvF8m4pRqzCboQ qwfbBcoRQAsJDSqXjkHeBWcsmClViqBSPHpeyiAiTS18Zs+lhBsTgJjHicRh8cOLhQkl zKCAe42+ZC6WNBnLSn11Sf/OHti9qA3B3DWIEdTJaVdbuve0xHgrM8Be64UvekjDia7c lemQ== 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 :message-id:date:subject:cc:to:from; bh=sladguh/MWEPFdXOX2gUvv7NIFdbKZrPNbZv9Rn+p2w=; b=qHcpyVf7QTXcXRRUALm5eBDJQAnfZFu0r50mqBU5fxSdusjoSS4Y7ebRe5ZuUlEuAT n5MLrI1fvT6c2JDHhh+Stjw1frRbAmMKdXf6sI8WszdpTcPz64TlP0NFsoKgpjaLZMi5 7gDxqp5xxnu9+9QSD0RFxox3DOeeWG17EhSoaM9gDfQMN8insZqMT0BHeOoCW4ux2nrf eFWt2S6QYyTjCqRdSar+vQP9GIa7zaNUsT3/hDxqj+5Vbe+Ez1aOLPrURS3p66ktjv1G /3/PCymsJEQjft1QJZIQgRSu3TGGRRYHJPPIzeE+XwBOaxp8FNMnz0/Y5SX4q1mi2yOs S25A== 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 l17si3814339otk.218.2020.01.11.11.02.10; Sat, 11 Jan 2020 11:02:32 -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 S1730871AbgAKTAS (ORCPT + 99 others); Sat, 11 Jan 2020 14:00:18 -0500 Received: from mail-qk1-f196.google.com ([209.85.222.196]:36402 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730851AbgAKTAS (ORCPT ); Sat, 11 Jan 2020 14:00:18 -0500 Received: by mail-qk1-f196.google.com with SMTP id a203so5069531qkc.3 for ; Sat, 11 Jan 2020 11:00:17 -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:mime-version :content-transfer-encoding; bh=sladguh/MWEPFdXOX2gUvv7NIFdbKZrPNbZv9Rn+p2w=; b=RfnYgmX5aXt4nGx5itAt1pMa5NV1nq8+CEKnEk2UgNXJh4W4/rkULl1xG0wa+tjT9/ egIl4yv20wwhGJRqAIkqjuJG4rrsu7K5NCRLgsu1vjMfcMJ30KWRMmJv/NP3O05RjdzI keJjvJOz8jPFijEAu8bWGHuJrvnGP5LiNUsSfITeQY2xHI4cNXZt5pN8TvgVDLqnkbCz cvHeow/yPFGY+OogMsiHsHjeiJy9rRRAOGF1lg+eg9gd9IBBCBr1qLPzCBXtGZl8t8cV thjqcUYeUnPXmGvyQOudQUE0pN0UlydoxvpcZFDXgUyec7ocZr5VDrhSHT26xk5F9gaK IX9g== X-Gm-Message-State: APjAAAXa2ABmHGadEMrk677GrmaEdtVfK9EoadK1MSRLLdQUkEHILzR8 DKJ8/PR7RAA3NzXGGXw568s= X-Received: by 2002:a05:620a:8ca:: with SMTP id z10mr4176340qkz.345.1578769217126; Sat, 11 Jan 2020 11:00:17 -0800 (PST) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id s27sm2588518qkm.97.2020.01.11.11.00.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jan 2020 11:00:16 -0800 (PST) From: Arvind Sankar To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Cc: x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] x86/boot/compressed: Correct relocation destination on old linkers Date: Sat, 11 Jan 2020 14:00:15 -0500 Message-Id: <20200111190015.3257863-1-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.24.1 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 As described in commit 6d92bc9d483a ("x86/build: Build compressed x86 kernels as PIE"), pre-2.26 binutils generates R_386_32 relocations in PIE mode. Since the startup code does not perform relocation, any reloc entry with R_386_32 will remain as 0 in the executing code. Commit 974f221c84b0 ("x86/boot: Move compressed kernel to the end of the decompression buffer") added a new symbol _end but did not mark it hidden, which doesn't give the correct offset on older linkers. This doesn't cause a crash, but means the compressed kernel is actually relocated starting from the end of the decompression buffer, rather than ending there. Mark _end as hidden to fix. Fixes: 974f221c84b0 ("x86/boot: Move compressed kernel to the end of the decompression buffer") Signed-off-by: Arvind Sankar --- arch/x86/boot/compressed/head_32.S | 5 +++-- arch/x86/boot/compressed/head_64.S | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S index f2dfd6d083ef..e4d1142f9f65 100644 --- a/arch/x86/boot/compressed/head_32.S +++ b/arch/x86/boot/compressed/head_32.S @@ -49,16 +49,17 @@ * Position Independent Executable (PIE) so that linker won't optimize * R_386_GOT32X relocation to its fixed symbol address. Older * linkers generate R_386_32 relocations against locally defined symbols, - * _bss, _ebss, _got and _egot, in PIE. It isn't wrong, just less + * _bss, _ebss, _got, _egot and _end, in PIE. It isn't wrong, just less * optimal than R_386_RELATIVE. But the x86 kernel fails to properly handle * R_386_32 relocations when relocating the kernel. To generate - * R_386_RELATIVE relocations, we mark _bss, _ebss, _got and _egot as + * R_386_RELATIVE relocations, we mark _bss, _ebss, _got, _egot and _end as * hidden: */ .hidden _bss .hidden _ebss .hidden _got .hidden _egot + .hidden _end __HEAD SYM_FUNC_START(startup_32) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 6eb30f8a3ce7..206fb95e827c 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -42,6 +42,7 @@ .hidden _ebss .hidden _got .hidden _egot + .hidden _end __HEAD .code32 -- 2.24.1