From patchwork Fri Apr 28 09:50:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Wenlong X-Patchwork-Id: 88562 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp818482vqo; Fri, 28 Apr 2023 03:06:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6rbhraRDzBRITk7XRjF+ba0hU937mCHF034Xvg5YBZx2IilZIj5nwIb5x0xg7tAy7ypzy0 X-Received: by 2002:a05:6a20:a10c:b0:f2:f747:2140 with SMTP id q12-20020a056a20a10c00b000f2f7472140mr5342277pzk.2.1682676369752; Fri, 28 Apr 2023 03:06:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682676369; cv=none; d=google.com; s=arc-20160816; b=s5i272R7pEU2Ni42iTchRZIVPck3/wVvyLs1jjHTo9xdm5ZvM4nXSnXvMKqTEcPrhk H9iHWWAyTkYizB8B5XvUpiML2fq90/eTHgW0EvHlu+tyVNdWgM9J2NhHczubPM0msjMb Kn6pPN8m5uVyWz3MU5ovwxUm/11QyC3R3UyeogrbeprBMmwfb1urOICFc1u1Vg5jPf/B EAqa7PZDKNsm9US361EPliBP08eZSywy0p4MNBa85JjkoFGgYoE1YgL5PjRO7qNJCj46 /hqKk0MTPH/hmRWLcnzrAiLbDsFtMq9HqO4JTKYQUjsCaKiDEZOS+RpWQsv35Up4+eK8 JxPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=J571jEdKvPNqfirNKuGvEZmzb9tRdJ6Sr/xTamafYoE=; b=TkWXr7PT4A7QrTj5EANAF25OJxqAhwvAiz0WyF1x4G1ER+HFfreuB45X+SG6vBTOaP jFA2AYLsvbcGRkadFiOJo698uOJzElrIih6JkJYoXDOxcCWGylGtFmVxWuu6LDYdA8ue eUULchZK+fR1cf5zu+zQi8vmXuidKcfpBqpgQarPYK02Wur88rD6gsKIgfR7r4rRNN6/ gsXARLsvquaf8Zg98AcsQwtON8SqsB5iBcQt+b2MzweYB0DRbk+wb8EbzaMNFmWtp5ko r8ELYKwjZGHiy4rxHrBVR7uqUfJhz5Qwjc+LA+5jIgd1uvCqFPMyXg+GThkAdRwcGj7/ kU9Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=antgroup.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e16-20020aa798d0000000b0063b84b5b53asi20319527pfm.9.2023.04.28.03.05.55; Fri, 28 Apr 2023 03:06:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=antgroup.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229680AbjD1JwU (ORCPT + 99 others); Fri, 28 Apr 2023 05:52:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345711AbjD1JwC (ORCPT ); Fri, 28 Apr 2023 05:52:02 -0400 Received: from out0-214.mail.aliyun.com (out0-214.mail.aliyun.com [140.205.0.214]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB907468C for ; Fri, 28 Apr 2023 02:51:56 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047203;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---.STFoG5h_1682675510; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.STFoG5h_1682675510) by smtp.aliyun-inc.com; Fri, 28 Apr 2023 17:51:51 +0800 From: "Hou Wenlong" To: linux-kernel@vger.kernel.org Cc: "Thomas Garnier" , "Lai Jiangshan" , "Kees Cook" , "Hou Wenlong" , "Andy Lutomirski" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , , "H. Peter Anvin" Subject: [PATCH RFC 04/43] x86/entry/64: Adapt assembly for PIE support Date: Fri, 28 Apr 2023 17:50:44 +0800 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764414056790134833?= X-GMAIL-MSGID: =?utf-8?q?1764414056790134833?= From: Thomas Garnier From: Thomas Garnier Change the assembly code to use only relative references of symbols for the kernel to be PIE compatible. Signed-off-by: Thomas Garnier Signed-off-by: Hou Wenlong Cc: Lai Jiangshan Cc: Kees Cook --- arch/x86/entry/entry_64.S | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 21dca946955e..6f2297ebb15f 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -1089,7 +1089,8 @@ SYM_CODE_START(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_lfence /* @@ -1302,10 +1303,10 @@ SYM_CODE_START(asm_exc_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: @@ -1359,7 +1360,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 @@ -1398,7 +1400,11 @@ first_nmi: addq $8, (%rsp) /* Fix up RSP */ pushfq /* RFLAGS */ pushq $__KERNEL_CS /* CS */ - pushq $1f /* RIP */ + pushq $0 /* Space for RIP */ + pushq %rdx /* Save RDX */ + leaq 1f(%rip), %rdx /* Put the address of 1f label into RDX */ + movq %rdx, 8(%rsp) /* Store it in RIP field */ + popq %rdx /* Restore RDX */ iretq /* continues at repeat_nmi below */ UNWIND_HINT_IRET_REGS 1: