From patchwork Tue May 29 22:15:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 10437279 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 92614601C7 for ; Tue, 29 May 2018 22:19:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79CA828911 for ; Tue, 29 May 2018 22:19:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E0E82891F; Tue, 29 May 2018 22:19:06 +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=-12.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 8DE1028911 for ; Tue, 29 May 2018 22:19:05 +0000 (UTC) Received: (qmail 17417 invoked by uid 550); 29 May 2018 22:17:05 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 16315 invoked from network); 29 May 2018 22:17:01 -0000 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=EUbcIbBlCnFrb94VeZXyQPEY+hZ2UwiREpZfB+qlc9A=; b=o/VsbizGQGOXUvm5IqM970Y7CxdO3h9t1hHlGbhj7Pq6DwJhZW1cCpD4jTGBBJHf6u nekYmpwp5ybFkK1doXm6Lywhi5oMthrXtrOQlGLt8d68KI0y9N6r0akx9diKOe8Iwmdn fs3AvqMNZERCGPEbXPnQ74Fz00IggtQ/YyPJiyysAssZw8sbmUlW8GPPwJ7na8UcoZTu +HI9h40CiKrxE2u5eMevhYbVoSldDN5eYP0hidcJpJc67mgbO2TbjfYUsyZ1a4SG9YYs qNJGIydmSydM0MwAxeRnqSjmLr5vdojeWVQEphFu9+eQUKjXyJW2P134tcYoGWekOKQ8 KVSg== 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=EUbcIbBlCnFrb94VeZXyQPEY+hZ2UwiREpZfB+qlc9A=; b=WluUhad+21FOfh3UHTpG1FHZ5Kom7A7+cgrKN79M7bcLqxehxLEm5P09OX4Hxf1Eqe shtejodBArsVmCNAwribQiJ1UGG8dpEzeQqB16Y6QcUceYbi7IGAJA3syzWQ6LMfYBd7 /PlIiwyBr/kV7Wkq0mU/fh3h9iDxzkBeAHh7v2enw994BPo1NYgxNCu4Ebd/dnz+NAmH IuOC2FPmIFm8feedolIJ0YKjnXGhOqwiH7PfPQCsszW1USoIQjgiMkQtf1s12U6NrCxG z6q9mzLJfEEiXr6swfwgGpLo4q88IyuUWGdYmrpilmbnzXs2IRe9ybe5jCU0V3ORACUG rZ+A== X-Gm-Message-State: ALKqPwf5M+PHQyUdI2L5ltZAForJbzeNkhuQUlQaScqG0sjaBoGWhkKn 1E2lrBMgbA87HmOnIkoFxY1pLm87VFM= X-Google-Smtp-Source: ADUXVKJS5CvysDkEy0QkV6q0USyKrsWPTa2MmBmwxP8GEol5s464WGLzsWW/Tp/SsHzwzNZMvwWMkg== X-Received: by 2002:a62:4141:: with SMTP id o62-v6mr196999pfa.111.1527632209682; Tue, 29 May 2018 15:16:49 -0700 (PDT) From: Thomas Garnier To: kernel-hardening@lists.openwall.com Cc: Thomas Garnier , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Tom Lendacky , "Kirill A. Shutemov" , linux-kernel@vger.kernel.org Subject: [PATCH v4 05/27] x86: relocate_kernel - Adapt assembly for PIE support Date: Tue, 29 May 2018 15:15:06 -0700 Message-Id: <20180529221625.33541-6-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> X-Virus-Scanned: ClamAV using ClamSMTP 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/kernel/relocate_kernel_64.S | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S index 11eda21eb697..a7227dfe1a2b 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -208,9 +208,11 @@ identity_mapped: movq %rax, %cr3 lea PAGE_SIZE(%r8), %rsp call swap_pages - movq $virtual_mapped, %rax - pushq %rax - ret + jmp *virtual_mapped_addr(%rip) + + /* Absolute value for PIE support */ +virtual_mapped_addr: + .quad virtual_mapped virtual_mapped: movq RSP(%r8), %rsp