Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3853362imm; Tue, 29 May 2018 15:18:07 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIDTyag9pWkkaIDKK+e1HvtKfxjKVtCHYM4Y91yOJmrzhgrP4nF5h1QSKLKsJl+M3RmOW2+ X-Received: by 2002:a17:902:6ac3:: with SMTP id i3-v6mr224191plt.378.1527632286885; Tue, 29 May 2018 15:18:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527632286; cv=none; d=google.com; s=arc-20160816; b=t/CHSjjeAih8I1TGtcVmCHKfi5AJMCgytniE1Vk9PTwO+5BF81BT609uCSvhxVAf8X em6mXkICaFIKpLmEwOc/U3SAcMOREm7+bFL9zorI6HIrkhnpbmk4/YnOJxK3r2SCd1zM P0qpwkC2c0FmswD0IWAKd4IEclyIRmL9JwdKd3dgfQFTUWVSVxe8SQJ8L9hSodXgdrus +gO8EPeAF9mRA8gd9Dd77D7PYd4TmDfYir3vaFNUfCRyaXls1qOoRZL0mdogvShGal1w j6A9N6jWSZgrMP4TSNO0I3+oLCEA4cdHzILNzq3oSETsmj24v8N7aKuTyAczeJgcPFuQ /TmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=YDtWImwpMLwiWcow09kfiVgGJI/8lP8E5mcdAOjfZno=; b=C+LiWJ2/lbXr3KXVUQo5Fw3jfUHDyQrgKjbNyPWcwFj/yQFfPZR4N7gzA0yDKfclfn aBTSJzJV7GJDtRm1ob7j8w6KoZm+oo1CoEGrWlInez3rr0urSo02aMzqV+SdEpnKAbaA 5Zx6pH0gRp4zFW1hMuKug1HvxrqFWFCbASjHAvZ96R9SWd9FjKHQDPC5XVpv+Jcfanzf 7P90Z2hbwTUdTK7luurd23ocpf/pmX3L1LwnnLTVT4lq8E7q+bEkOiNt4tlIwHlEUAOu 5L7yferGvNzeksUBpmpBFsckaV+eGfMCRzq0sTm6bmxinnzecnEJgwxnW4Uk8CsUtaCn cf5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=WhreX7WF; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v66-v6si26530603pgv.344.2018.05.29.15.17.52; Tue, 29 May 2018 15:18:06 -0700 (PDT) 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=@google.com header.s=20161025 header.b=WhreX7WF; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967897AbeE2WQ7 (ORCPT + 99 others); Tue, 29 May 2018 18:16:59 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33898 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967860AbeE2WQz (ORCPT ); Tue, 29 May 2018 18:16:55 -0400 Received: by mail-pf0-f195.google.com with SMTP id a14-v6so7953062pfi.1 for ; Tue, 29 May 2018 15:16:54 -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=YDtWImwpMLwiWcow09kfiVgGJI/8lP8E5mcdAOjfZno=; b=WhreX7WFUwPV8zt8xd8t/49JQVRgxrnl/oqGeAFsWH4VpacEoFQBslxFcFtUHWdsb/ fOZU9GaBkY6ngjJA9044Sp91M6RxNm4Qr2V9VFk+yV+RMP1EiMPHYGEKeW6H/SWJo7u5 Rgg9ElJxV2Hulf7PGHA8buPXv94AdKA4reUiVtwOLk9VT56uzVmUnGpbwGFmf3XgzvuZ zpUaDq/r5EBg0SKtf8mepHw4GawFTKeQ4iVoK+O7uUatABtH5PcXYh7UmvxXcWjX6Wlq llBnTDtvZTHvQk1b58fwA6/pLccfU3UBl2BYRnNvjDXvil2KOEzjEbOCc+sbv54zDKjt /oNw== 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=YDtWImwpMLwiWcow09kfiVgGJI/8lP8E5mcdAOjfZno=; b=HlAM0E7ruRaulNjLEVpxfLlunlCDVOB01dnwwQSAUkbVw4rZeBFzKRbBNgicQscu48 cMzOYxJgfMHlRPjHMOaY82yu84dUFqKKdJkdTTgcIR5uDe3epLwtvFLM+3HfDU6aA+A3 tzKxXwyk0PA2HBsvgM0ILPrvf8LIBjCJQ6zj/r5RAT4I+eulT/8uxPlEtqJzc6ewvLe5 OPSfENFBaXMQgV4RbJgidGMpWVUSGgio/qQ5RlzVm1sC/ZT/13y8UWOSC5NsTQK2TLD2 NcdAMTbZLOc6thKn167iJ9e58x0iOLPeYE/+K3zDYusJi1Hm7HSFDvWeik71KvBr7vTa kggQ== X-Gm-Message-State: ALKqPweWeFk7GpgfUxOkPGZfptFsKpXv1zBs81x+eFeIszGmDkaR8YB6 1Iu0OCNMTjyB4LN/IrB+yjCyvg== X-Received: by 2002:a63:5fcb:: with SMTP id t194-v6mr175358pgb.176.1527632214156; Tue, 29 May 2018 15:16:54 -0700 (PDT) Received: from skynet.sea.corp.google.com ([2620:15c:17:4:29de:3bb1:1270:e679]) by smtp.gmail.com with ESMTPSA id o84-v6sm78767935pfi.27.2018.05.29.15.16.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 May 2018 15:16:52 -0700 (PDT) From: Thomas Garnier To: kernel-hardening@lists.openwall.com Cc: Thomas Garnier , Skip Josh Poimboeuf , Skip Dave Hansen , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Andy Lutomirski , Dominik Brodowski , Borislav Petkov , "Kirill A. Shutemov" , Tom Lendacky , linux-kernel@vger.kernel.org Subject: [PATCH v4 06/27] x86/entry/64: Adapt assembly for PIE support Date: Tue, 29 May 2018 15:15:07 -0700 Message-Id: <20180529221625.33541-7-thgarnie@google.com> X-Mailer: git-send-email 2.17.0.921.gf22659ad46-goog In-Reply-To: <20180529221625.33541-1-thgarnie@google.com> References: <20180529221625.33541-1-thgarnie@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Change the assembly code to use only relative references of symbols for the kernel to be PIE compatible. Position Independent Executable (PIE) support will allow to extend the KASLR randomization range 0xffffffff80000000. Signed-off-by: Thomas Garnier --- arch/x86/entry/entry_64.S | 18 ++++++++++++------ arch/x86/kernel/relocate_kernel_64.S | 8 +++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 3166b9674429..1cbf4c3616a8 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -191,7 +191,7 @@ ENTRY(entry_SYSCALL_64_trampoline) * spill RDI and restore it in a second-stage trampoline. */ pushq %rdi - movq $entry_SYSCALL_64_stage2, %rdi + movabsq $entry_SYSCALL_64_stage2, %rdi JMP_NOSPEC %rdi END(entry_SYSCALL_64_trampoline) @@ -1276,7 +1276,8 @@ ENTRY(error_entry) movl %ecx, %eax /* zero extend */ cmpq %rax, RIP+8(%rsp) je .Lbstep_iret - cmpq $.Lgs_change, RIP+8(%rsp) + leaq .Lgs_change(%rip), %rcx + cmpq %rcx, RIP+8(%rsp) jne .Lerror_entry_done /* @@ -1481,10 +1482,10 @@ ENTRY(nmi) * resume the outer NMI. */ - movq $repeat_nmi, %rdx + leaq repeat_nmi(%rip), %rdx cmpq 8(%rsp), %rdx ja 1f - movq $end_repeat_nmi, %rdx + leaq end_repeat_nmi(%rip), %rdx cmpq 8(%rsp), %rdx ja nested_nmi_out 1: @@ -1538,7 +1539,8 @@ nested_nmi: pushq %rdx pushfq pushq $__KERNEL_CS - pushq $repeat_nmi + leaq repeat_nmi(%rip), %rdx + pushq %rdx /* Put stack back */ addq $(6*8), %rsp @@ -1577,7 +1579,11 @@ first_nmi: addq $8, (%rsp) /* Fix up RSP */ pushfq /* RFLAGS */ pushq $__KERNEL_CS /* CS */ - pushq $1f /* RIP */ + pushq $0 /* Futur return address */ + pushq %rax /* Save RAX */ + leaq 1f(%rip), %rax /* RIP */ + movq %rax, 8(%rsp) /* Put 1f on return address */ + popq %rax /* Restore RAX */ iretq /* continues at repeat_nmi below */ UNWIND_HINT_IRET_REGS 1: diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S index a7227dfe1a2b..0c0fc259a4e2 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -208,11 +208,9 @@ identity_mapped: movq %rax, %cr3 lea PAGE_SIZE(%r8), %rsp call swap_pages - jmp *virtual_mapped_addr(%rip) - - /* Absolute value for PIE support */ -virtual_mapped_addr: - .quad virtual_mapped + movabsq $virtual_mapped, %rax + pushq %rax + ret virtual_mapped: movq RSP(%r8), %rsp -- 2.17.0.921.gf22659ad46-goog