From patchwork Wed Oct 11 20:30:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 10000553 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 855716037F for ; Wed, 11 Oct 2017 20:33:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79EAC28B37 for ; Wed, 11 Oct 2017 20:33:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D9FF28B6A; Wed, 11 Oct 2017 20:33:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E5DA728B37 for ; Wed, 11 Oct 2017 20:33:24 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2NfE-0000ic-7F; Wed, 11 Oct 2017 20:31:36 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2NfC-0000fm-NJ for xen-devel@lists.xenproject.org; Wed, 11 Oct 2017 20:31:34 +0000 Received: from [85.158.143.35] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-2.bemta-6.messagelabs.com id 23/9B-02373-6AF7ED95; Wed, 11 Oct 2017 20:31:34 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrFIsWRWlGSWpSXmKPExsVyMfTAFt2l9fc iDZbuYbP4vmUykwOjx+EPV1gCGKNYM/OS8isSWDOudz5jKzggVfGkcQtbA+McsS5GLg4hgRmM EjePfGQEcVgEXrFITHw6kQ3EkRDoZ5XovfKXpYuRE8jJkuibPoMdwk6TuHBvAxuEXSHx9ew1R hBbSEBJYuuGpcwQY/8xSjRtOwtWxCagJbGnYT4TSEJE4ISwxKYPv8H2MQucYZI43neSFaRKWM BW4v6fdiYQm0VAVWLy7nZmEJtXwFKiZ/MEZoh1FhLHjh0GO4kTKP594yFmiNUWEitnnWedwCi 4gJFhFaN6cWpRWWqRrqVeUlFmekZJbmJmjq6hgZlebmpxcWJ6ak5iUrFecn7uJkZg2DEAwQ7G u5sCDjFKcjApifI+jLkXKcSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mCd3odUE6wKDU9tSItMwcYA TBpCQ4eJRHeJpA0b3FBYm5xZjpE6hSjJceFO5f+MHEc2HMLSHbcvPuHSYglLz8vVUqctxSkQQ CkIaM0D24cLEovMcpKCfMyAh0oxFOQWpSbWYIq/4pRnINRSZj3MMgUnsy8Eritr4AOYgI6SDT tDshBJYkIKakGxrJlHrryth3/EvoLH8l9e/L53YlEyxMrY2cERPQtCncTUDzJ9eWkMZuKT/Ox t8oFB2wXfvP92ztN5WP4r4A1liFXZ+pOOMfmcOCVZ4rJ5KSYSs/iSQkbvy7eOeHNorxjfjzvh Pl4Dc6wNOZP5JnCfGrRr47wtyxb53z6mn5zgfEnm7MLS8Sev1diKc5INNRiLipOBABoYhKKzQ IAAA== X-Env-Sender: thgarnie@google.com X-Msg-Ref: server-5.tower-21.messagelabs.com!1507753891!68764314!1 X-Originating-IP: [209.85.192.180] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 23361 invoked from network); 11 Oct 2017 20:31:32 -0000 Received: from mail-pf0-f180.google.com (HELO mail-pf0-f180.google.com) (209.85.192.180) by server-5.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 11 Oct 2017 20:31:32 -0000 Received: by mail-pf0-f180.google.com with SMTP id 17so1932871pfn.12 for ; Wed, 11 Oct 2017 13:31:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rTRF5EsAKsx8IX6+UZpMdLlToReJc/ZfQ0FNzhsNUoI=; b=IZNCbf4+GnXXDByQN9i77V2MEnW+FhUqwFEmRXzvNyAQ81GJat5odmHkQdzam6+uS4 ObNa6KqEKRAXDeCjx9h1wG5uhoCdv0j0O7FsZathvV3ZPrGaCFwm6U122r8jK0YD+Z+R rBasUqYK8koURidKWw6zFhGhk8eZ+8usOz+Dghk2gQOhb21KwN/FHyCWjZp3ueURBe4E rtf0oAt5jSY/DDRqVJ+QPM/y+sI0VS6J95Ppb2J+iv292jHekeVmkcCDoPAhov+w4ufa keWW5OQcD6g49fJPs6NHkOL/Bd2dijqk1kbKscnjmiM2U4FJtV9LewNenM5Z/vNU7QPO /nSg== 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; bh=rTRF5EsAKsx8IX6+UZpMdLlToReJc/ZfQ0FNzhsNUoI=; b=E7+f/4bWFsrFPUxVCQgQy/ScqZ65N62qJQD7fBNTAhjTe4huY6z9/2eQqRaN+7X10d qYy3NXL0NyGWDRPJnqmQNXlNZc6WsxBT/UlYEZ5Iqz7fx9wEiq5DagR/lFDPbTviP6Ep 8tf/JCeF9jAzIxZtUWZCpdI0IBFPd2s66Cvw+Ncea+tq9LSRBrkWC3SjJGURpGuNsRR6 e6sPjqCg1KsyLiVsrQg1BsdhEmNn3rIGOKXggOvsI8E6IH+PDzALYfsZfcDb5ANMcdlH Xa8pmSGjT4R0ES8k2Fgy+2AM3EGyBVkIjtuqP3ezYQ1Xh0Tau7em3H5ecFA8sXHXgF+T 3YoQ== X-Gm-Message-State: AMCzsaUyZ60v3fmPz7aX3q0u0GoGpRxg+NCyTY3w9cNfqsLuSmn3vfhL BsiNT6sKkesRcapy8loIFXp3Lg== X-Google-Smtp-Source: AOwi7QBgEzzCk5IjEBF+qTJfu5tvE9fFxcFdp8AyfbevarLDMso6wnrXYG9i5rcrNJOfPJIesyWucw== X-Received: by 10.98.62.195 with SMTP id y64mr200540pfj.140.1507753890883; Wed, 11 Oct 2017 13:31:30 -0700 (PDT) Received: from skynet.sea.corp.google.com ([172.31.92.33]) by smtp.gmail.com with ESMTPSA id n12sm20691913pfb.149.2017.10.11.13.31.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Oct 2017 13:31:30 -0700 (PDT) From: Thomas Garnier To: Herbert Xu , "David S . Miller" , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Peter Zijlstra , Josh Poimboeuf , Arnd Bergmann , Thomas Garnier , Kees Cook , Andrey Ryabinin , Matthias Kaehlcke , Tom Lendacky , Andy Lutomirski , "Kirill A . Shutemov" , Borislav Petkov , "Rafael J . Wysocki" , Len Brown , Pavel Machek , Juergen Gross , Chris Wright , Alok Kataria , Rusty Russell , Tejun Heo , Christoph Lameter , Boris Ostrovsky , Paul Gortmaker , Andrew Morton , Alexey Dobriyan , "Paul E . McKenney" , Nicolas Pitre , Borislav Petkov , "Luis R . Rodriguez" , Greg Kroah-Hartman , Christopher Li , Steven Rostedt , Jason Baron , Mika Westerberg , Dou Liyang , "Rafael J . Wysocki" , Lukas Wunner , Masahiro Yamada , Alexei Starovoitov , Daniel Borkmann , Markus Trippelsdorf , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Joerg Roedel , Rik van Riel , David Howells , Ard Biesheuvel , Waiman Long , Kyle Huey , Jonathan Corbet , Michal Hocko , Peter Foley , Paul Bolle , Jiri Kosina , "H . J . Lu" , Rob Landley , Baoquan He , =?UTF-8?q?Jan=20H=20=2E=20Sch=C3=B6nherr?= , Daniel Micay Date: Wed, 11 Oct 2017 13:30:17 -0700 Message-Id: <20171011203027.11248-18-thgarnie@google.com> X-Mailer: git-send-email 2.15.0.rc0.271.g36b669edcc-goog In-Reply-To: <20171011203027.11248-1-thgarnie@google.com> References: <20171011203027.11248-1-thgarnie@google.com> Cc: linux-arch@vger.kernel.org, kvm@vger.kernel.org, linux-pm@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-sparse@vger.kernel.org, linux-crypto@vger.kernel.org, kernel-hardening@lists.openwall.com, xen-devel@lists.xenproject.org Subject: [Xen-devel] [PATCH v1 17/27] xen: Adapt assembly for PIE support X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Change the assembly code to use the new _ASM_GET_PTR macro which get a symbol reference while being PIE compatible. Adapt the relocation tool to ignore 32-bit Xen code. Position Independent Executable (PIE) support will allow to extended the KASLR randomization range below the -2G memory limit. Signed-off-by: Thomas Garnier --- arch/x86/tools/relocs.c | 16 +++++++++++++++- arch/x86/xen/xen-head.S | 9 +++++---- arch/x86/xen/xen-pvh.S | 13 +++++++++---- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index 5d3eb2760198..bc032ad88b22 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -831,6 +831,16 @@ static int is_percpu_sym(ElfW(Sym) *sym, const char *symname) strncmp(symname, "init_per_cpu_", 13); } +/* + * Check if the 32-bit relocation is within the xenpvh 32-bit code. + * If so, ignores it. + */ +static int is_in_xenpvh_assembly(ElfW(Addr) offset) +{ + ElfW(Sym) *sym = sym_lookup("pvh_start_xen"); + return sym && (offset >= sym->st_value) && + (offset < (sym->st_value + sym->st_size)); +} static int do_reloc64(struct section *sec, Elf_Rel *rel, ElfW(Sym) *sym, const char *symname) @@ -892,8 +902,12 @@ static int do_reloc64(struct section *sec, Elf_Rel *rel, ElfW(Sym) *sym, * the relocations are processed. * Make sure that the offset will fit. */ - if (r_type != R_X86_64_64 && (int32_t)offset != (int64_t)offset) + if (r_type != R_X86_64_64 && + (int32_t)offset != (int64_t)offset) { + if (is_in_xenpvh_assembly(offset)) + break; die("Relocation offset doesn't fit in 32 bits\n"); + } if (r_type == R_X86_64_64) add_reloc(&relocs64, offset); diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S index 124941d09b2b..e5b7b9566191 100644 --- a/arch/x86/xen/xen-head.S +++ b/arch/x86/xen/xen-head.S @@ -25,14 +25,15 @@ ENTRY(startup_xen) /* Clear .bss */ xor %eax,%eax - mov $__bss_start, %_ASM_DI - mov $__bss_stop, %_ASM_CX + _ASM_GET_PTR(__bss_start, %_ASM_DI) + _ASM_GET_PTR(__bss_stop, %_ASM_CX) sub %_ASM_DI, %_ASM_CX shr $__ASM_SEL(2, 3), %_ASM_CX rep __ASM_SIZE(stos) - mov %_ASM_SI, xen_start_info - mov $init_thread_union+THREAD_SIZE, %_ASM_SP + _ASM_GET_PTR(xen_start_info, %_ASM_AX) + mov %_ASM_SI, (%_ASM_AX) + _ASM_GET_PTR(init_thread_union+THREAD_SIZE, %_ASM_SP) jmp xen_start_kernel END(startup_xen) diff --git a/arch/x86/xen/xen-pvh.S b/arch/x86/xen/xen-pvh.S index e1a5fbeae08d..43e234c7c2de 100644 --- a/arch/x86/xen/xen-pvh.S +++ b/arch/x86/xen/xen-pvh.S @@ -101,8 +101,8 @@ ENTRY(pvh_start_xen) call xen_prepare_pvh /* startup_64 expects boot_params in %rsi. */ - mov $_pa(pvh_bootparams), %rsi - mov $_pa(startup_64), %rax + movabs $_pa(pvh_bootparams), %rsi + movabs $_pa(startup_64), %rax jmp *%rax #else /* CONFIG_X86_64 */ @@ -137,10 +137,15 @@ END(pvh_start_xen) .section ".init.data","aw" .balign 8 + /* + * Use a quad for _pa(gdt_start) because PIE does not understand a + * long is enough. The resulting value will still be in the lower long + * part. + */ gdt: .word gdt_end - gdt_start - .long _pa(gdt_start) - .word 0 + .quad _pa(gdt_start) + .balign 8 gdt_start: .quad 0x0000000000000000 /* NULL descriptor */ .quad 0x0000000000000000 /* reserved */