From patchwork Fri Apr 28 09:50:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Wenlong X-Patchwork-Id: 88574 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp823094vqo; Fri, 28 Apr 2023 03:15:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7tgwbkaiTM/wke44oOxephMVs3YpkyH9eqz/X5IpdPekWU/jRtRxPkL/CukpaLX0zeUuwX X-Received: by 2002:a17:903:41c4:b0:1a6:e58f:8aee with SMTP id u4-20020a17090341c400b001a6e58f8aeemr5243028ple.65.1682676901989; Fri, 28 Apr 2023 03:15:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682676901; cv=none; d=google.com; s=arc-20160816; b=H+i+UcPjkBrIYw+tCFDFvau4975AZL6N2n0/fGYo9lWoA+RnIp/VAk8mMT5X2gOAv9 nJq6JZIPg0qLaW30QtTJJPbPXB1QrHaR1x67AKeyPYE34mJ8k5z/O+EHJRBCt10M9LV+ 8z89QX/Idn50Ro1Frpp6SR7ex1IJm2rN7q4Hh8mpkERLpLj5+oykJZJIk3FQH++YV2vX hrnwrXW2Itz15ujUVgQR67M0yfTwBa6CWLN0YZuxdP7q4eyO3xo/2myA6B1LTs6lWJV4 2N5+yrZhBzLknkNsoeiUkNDi2QS//n9ujxJwhkRLTfq7EpkYv61cv4ttsy0a9H+6FiUR OByw== 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=cmEZVhiF8fX9F4xTfFN7JAl1iwVobQtKpB4OGg7OWrQ=; b=I/1XVBuEqVG7jxfbUnJHhZV/FASvHjrzYOn+3MexYSxWsCCEhIybc8RquQUu9qNT2t fwS4E0XEVJk+3tE1rXXWB43flboK/WWlQzzs7laHCTmMsAJIwpauy7Qqs0tiMbwLIVa4 ZeaSacl2ny0LYzIePz6pHz/vAcSL3LihohXSkgX+QNCYe8Ge6CeUz6UBp4/x62ws1Gm+ lVlRrdZDWIjV9sVQkMKcHWmyNh9kk55MTI5MIGQpcmM+6fw4PFAy6usFsxoLvOOXKjpw YeNop3sYcf5TRY8+T+oTxhvyI/vNFNovc6lmEBS9Nm0JTrutK5W8U02tpAknynzccqJJ e9JQ== 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 t4-20020a170902e84400b001a80ddd372csi22224368plg.43.2023.04.28.03.14.43; Fri, 28 Apr 2023 03:15:01 -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 S1345870AbjD1JxN (ORCPT + 99 others); Fri, 28 Apr 2023 05:53:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345741AbjD1Jwq (ORCPT ); Fri, 28 Apr 2023 05:52:46 -0400 Received: from out0-222.mail.aliyun.com (out0-222.mail.aliyun.com [140.205.0.222]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 255EB5FCD for ; Fri, 28 Apr 2023 02:52:22 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047193;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---.STCEPQo_1682675534; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.STCEPQo_1682675534) by smtp.aliyun-inc.com; Fri, 28 Apr 2023 17:52:15 +0800 From: "Hou Wenlong" To: linux-kernel@vger.kernel.org Cc: "Thomas Garnier" , "Lai Jiangshan" , "Kees Cook" , "Hou Wenlong" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , , "H. Peter Anvin" Subject: [PATCH RFC 12/43] x86,rethook: Adapt assembly for PIE support Date: Fri, 28 Apr 2023 17:50:52 +0800 Message-Id: <8a0c7ca2d70bbc6162c97a87a73dafb24a6659a2.1682673543.git.houwenlong.hwl@antgroup.com> 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?1764414615092114732?= X-GMAIL-MSGID: =?utf-8?q?1764414615092114732?= Change the assembly code to use only relative references of symbols for the kernel to be PIE compatible. Signed-off-by: Hou Wenlong Cc: Thomas Garnier Cc: Lai Jiangshan Cc: Kees Cook --- arch/x86/kernel/rethook.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86/kernel/rethook.c b/arch/x86/kernel/rethook.c index 8a1c0111ae79..ff3733b765e0 100644 --- a/arch/x86/kernel/rethook.c +++ b/arch/x86/kernel/rethook.c @@ -27,7 +27,15 @@ asm( #ifdef CONFIG_X86_64 ANNOTATE_NOENDBR /* This is only jumped from ret instruction */ /* Push a fake return address to tell the unwinder it's a rethook. */ +#ifdef CONFIG_X86_PIE + " pushq $0\n" + " pushq %rdi\n" + " leaq arch_rethook_trampoline(%rip), %rdi\n" + " movq %rdi, 8(%rsp)\n" + " popq %rdi\n" +#else " pushq $arch_rethook_trampoline\n" +#endif UNWIND_HINT_FUNC " pushq $" __stringify(__KERNEL_DS) "\n" /* Save the 'sp - 16', this will be fixed later. */