Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5101230imu; Tue, 8 Jan 2019 11:31:06 -0800 (PST) X-Google-Smtp-Source: ALg8bN6TKCG+cfRHH/YPmCtIdGsvHwiY5f2vuxYgu9lou9S7tznbfHdT3bWSDBYbXF+TxEbe5yfA X-Received: by 2002:a63:6f0d:: with SMTP id k13mr2640328pgc.42.1546975866127; Tue, 08 Jan 2019 11:31:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546975866; cv=none; d=google.com; s=arc-20160816; b=ZkAe9z2FGZvLbbaOiaNCigTVDHxW1k3hGkOHaHouH/WoNhVvS6vezXS9hp4K83ms/8 V3iCK6xC0EF4xJDFDPOnrXsVaQQk8nELbB/t5Nr8xu5I8H/S0CyBeyL2trt8rWEBpJHb aX/flXYjye4Najj2mpHyKIrgWa+pP9AZsvPGv11mq8HgNNo1FHDMZi3MO0+QUuV5/Br9 8Tn3qpZdx6TaYiVNN9gJ8xgSyvEDs6ut+kh3DRf6JgDtEohgKnEJyi1zY4xOVivD61u+ mBdIbWTH69ALJq3Q2J1RYSPXdpDgYJoQFxaNivg7BivCWcbh0TMQqJbBI2eC2o67M+mi oSkg== 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 :dkim-signature; bh=pnya8K+GinDYTyldfYxMj9VPrTgQg9rmZsz0+vCnSNM=; b=wQGEL9RipWqhGaV4kDP/ORsak8vGSW8da5rBGMJ8Rddd3kfKB3kruZhBuZQL3oVVEr 4pQBVElukeT+/rRMg9dUqBqq9cl4uPXn7AiGm1ywc+7iNdKVfYzPBTv7m1Bzdjcd1nQ7 O1+DDSF87mTSJeU/6pb5Sk7fOsdgnao63e1vsgPqIM2Jkkdry/qRRUN5YunO6xmCclEo hrYB+ENYbdfIiHldi48jPxa18uuEOcsay6TZBTR7jVT9gozcqMoxg7tTMOQSxpCXAymV hVa5em4borLz2a6IwDuGCsWI9oKaOquLcEG6+bRR/BB4tH9n2uDcTSrw6dSno+xSi4lq eR+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jHCG8F8p; 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 21si42825pge.374.2019.01.08.11.30.50; Tue, 08 Jan 2019 11:31:06 -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=jHCG8F8p; 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 S1729874AbfAHT2D (ORCPT + 99 others); Tue, 8 Jan 2019 14:28:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:34608 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729858AbfAHT2B (ORCPT ); Tue, 8 Jan 2019 14:28:01 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (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 7B8BA20645; Tue, 8 Jan 2019 19:27:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546975680; bh=ommgPjTwp6yBaFXM5KrZY5NkRGZVA/h1whw3hiPBCOw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jHCG8F8ponqUyyGvcBhi/y/ERCDB8vdBDMO+OstfglcQ5TfDzGBhvWgR2UW5EnNAj ihEj+W7GKVEMriu5jhlIIcNQGY1W8flLeP/Nwetg+ZoekD2mxHFMumIxnXZ2dIPYzb qdYjLOq6TFIWrcEizqg22s3eQ7rUEE+h3sPxjGQY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ard Biesheuvel , Nick Desaulniers , Peter Smith , Will Deacon , Sasha Levin Subject: [PATCH AUTOSEL 4.20 049/117] arm64: relocatable: fix inconsistencies in linker script and options Date: Tue, 8 Jan 2019 14:25:17 -0500 Message-Id: <20190108192628.121270-49-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190108192628.121270-1-sashal@kernel.org> References: <20190108192628.121270-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel [ Upstream commit 3bbd3db86470c701091fb1d67f1fab6621debf50 ] readelf complains about the section layout of vmlinux when building with CONFIG_RELOCATABLE=y (for KASLR): readelf: Warning: [21]: Link field (0) should index a symtab section. readelf: Warning: [21]: Info field (0) should index a relocatable section. Also, it seems that our use of '-pie -shared' is contradictory, and thus ambiguous. In general, the way KASLR is wired up at the moment is highly tailored to how ld.bfd happens to implement (and conflate) PIE executables and shared libraries, so given the current effort to support other toolchains, let's fix some of these issues as well. - Drop the -pie linker argument and just leave -shared. In ld.bfd, the differences between them are unclear (except for the ELF type of the produced image [0]) but lld chokes on seeing both at the same time. - Rename the .rela output section to .rela.dyn, as is customary for shared libraries and PIE executables, so that it is not misidentified by readelf as a static relocation section (producing the warnings above). - Pass the -z notext and -z norelro options to explicitly instruct the linker to permit text relocations, and to omit the RELRO program header (which requires a certain section layout that we don't adhere to in the kernel). These are the defaults for current versions of ld.bfd. - Discard .eh_frame and .gnu.hash sections to avoid them from being emitted between .head.text and .text, screwing up the section layout. These changes only affect the ELF image, and produce the same binary image. [0] b9dce7f1ba01 ("arm64: kernel: force ET_DYN ELF type for ...") Cc: Nick Desaulniers Cc: Peter Smith Tested-by: Nick Desaulniers Signed-off-by: Ard Biesheuvel Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- arch/arm64/Makefile | 2 +- arch/arm64/kernel/vmlinux.lds.S | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 6cb9fc7e9382..8978f60779c4 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -18,7 +18,7 @@ ifeq ($(CONFIG_RELOCATABLE), y) # Pass --no-apply-dynamic-relocs to restore pre-binutils-2.27 behaviour # for relative relocs, since this leads to better Image compression # with the relocation offsets always being zero. -LDFLAGS_vmlinux += -pie -shared -Bsymbolic \ +LDFLAGS_vmlinux += -shared -Bsymbolic -z notext -z norelro \ $(call ld-option, --no-apply-dynamic-relocs) endif diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 03b00007553d..7fa008374907 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -99,7 +99,8 @@ SECTIONS *(.discard) *(.discard.*) *(.interp .dynamic) - *(.dynsym .dynstr .hash) + *(.dynsym .dynstr .hash .gnu.hash) + *(.eh_frame) } . = KIMAGE_VADDR + TEXT_OFFSET; @@ -192,12 +193,12 @@ SECTIONS PERCPU_SECTION(L1_CACHE_BYTES) - .rela : ALIGN(8) { + .rela.dyn : ALIGN(8) { *(.rela .rela*) } - __rela_offset = ABSOLUTE(ADDR(.rela) - KIMAGE_VADDR); - __rela_size = SIZEOF(.rela); + __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR); + __rela_size = SIZEOF(.rela.dyn); . = ALIGN(SEGMENT_ALIGN); __initdata_end = .; -- 2.19.1