From patchwork Fri Dec 8 18:12:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 175996 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp5632453vqy; Fri, 8 Dec 2023 10:14:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IE7xafJB17DREFvc1BQKTEgP/ngc6pp7ywM4XS2+thNbLomUOkJmvGQP9V8e6tBTEgNrZC6 X-Received: by 2002:a05:6358:6f07:b0:170:17eb:14b6 with SMTP id r7-20020a0563586f0700b0017017eb14b6mr379240rwn.38.1702059243905; Fri, 08 Dec 2023 10:14:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702059243; cv=none; d=google.com; s=arc-20160816; b=dBEc2/Spbz2Z9+4I+KcyFKyYE+E3yi4NzH374ktabdB2poR2Sufa1/EfvrXqYHn6YS 1LQIKQ4D4GUVOFfRPlegTKfzkmLBIK9yPx22NKAggLmoXCDi1UDSrNBPR83YPeZo2mLt pRvkQxk7UL9MFBCnGYXwH0Tt2GK3soyqLbpx8Bl2sbMabd9yHK94aM9pD3rMLl5HtE3R P07TjRd4/Dh8ZenFuUNN1reG/6Anuallp6x1ghFY4w6O++8lcRdTyw7x2oywqvWbJyhV i/WL+RUV770oJPdFUSEhwMhrX9Udi873bdZds/NkSRJENHst4eeYNPuHVv8BOqmVD3zV 0X4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=iw47ohedCEaZOlCqlGrH7FBw+ilqjehAoGogtWxJjsI=; fh=NdptIAQysOQlidYXeN2I+7Z8M3wdEdDWch6LHJ8uuCQ=; b=Gg12FxrPF1VMqs9TkfrCgGghQ5GEU5wkAJpWQ47UQpipwZNwujO3WQe63RER0x+JVa dkSXdgoTP8jimJGfepOqkEc5WJIWeZmp/6D5MXSX7bL/UMuFS0B8SrEPqfiROkLcBal6 2aXh9zc+w7RSgnr+mh5Q7MM8pfLOz+xEUU4Zajkrq1Dff8Z8NRj/OFRFoMKKksXiWqwB WulS1+AHrQV2n9XvvHTvHVHKLUA8y2072AgAUiSyamSWxZ4vEdU98LyLvjiGUU/6o/21 2MB+fCnlUZP9gpXRRa/2W1Ms7Dn47o4L0fOXUDH6jEWwJZy0QDTupfd2yK9rSG9Nk0v2 ajNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=SCStw0L3; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id p125-20020a634283000000b005c6c950c3bfsi1842974pga.645.2023.12.08.10.14.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 10:14:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=SCStw0L3; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 55A4D81E1B5A; Fri, 8 Dec 2023 10:13:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1574619AbjLHSNK (ORCPT + 99 others); Fri, 8 Dec 2023 13:13:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1574486AbjLHSMz (ORCPT ); Fri, 8 Dec 2023 13:12:55 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB7FB10EB; Fri, 8 Dec 2023 10:13:01 -0800 (PST) Date: Fri, 08 Dec 2023 18:12:59 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1702059180; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iw47ohedCEaZOlCqlGrH7FBw+ilqjehAoGogtWxJjsI=; b=SCStw0L31XDFyxvmjZ0GgHVej5jfvRF5TeuvkZ1alouLm0K6kcsIWA2gIlCCnbOwFvuQCx OI+lUbguFXD9LAVZAOYlbrKhELmpYnp8pRNrXsC0JoUT/veHaVe8LHPimgxYHkPM3rE9qd t9lJiGtTmxzppJ9tJiuc4QDkMU5S/k4PXjAeZpKVRDmrEPcWQ0yP0dhb1DmxF1HBri5N8z KiHmtwDCS0VF/q63URLqY9bywezG4b5gdTqsNUPz2SiOx5/HdWH6Fw/WTxpIgwS29ZIrxS HXct1blaDsjL8Y9jQ5MLG7SGOOR/+X0YBBMIG5Da6EsfaYF/jj/NfovK7AzcOw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702059180; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iw47ohedCEaZOlCqlGrH7FBw+ilqjehAoGogtWxJjsI=; b=j9XEzSi1nzJOkjq6GbT+y+lw8KNIoc9nezn+mn9haGtKa8t41gqQOXcSL7gua+K1nC0SgA JJHLtLF0YcLjMcDg== From: "tip-bot2 for Jo Van Bulck" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/sgx] selftests/sgx: Produce static-pie executable for test enclave Cc: Jo Van Bulck , Dave Hansen , Jarkko Sakkinen , Kai Huang , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <170205917995.398.14866199583250820547.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 08 Dec 2023 10:13:55 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784738473670901695 X-GMAIL-MSGID: 1784738473670901695 The following commit has been merged into the x86/sgx branch of tip: Commit-ID: f7884e732841450de36c2b1ed49b91e8e854a7d1 Gitweb: https://git.kernel.org/tip/f7884e732841450de36c2b1ed49b91e8e854a7d1 Author: Jo Van Bulck AuthorDate: Thu, 05 Oct 2023 17:38:48 +02:00 Committer: Dave Hansen CommitterDate: Fri, 08 Dec 2023 10:05:27 -08:00 selftests/sgx: Produce static-pie executable for test enclave The current combination of -static and -fPIC creates a static executable with position-dependent addresses for global variables. Use -static-pie and -fPIE to create a proper static position independent executable that can be loaded at any address without a dynamic linker. When building the original "lea (encl_stack)(%rbx), %rax" assembly code with -static-pie -fPIE, the linker complains about a relocation it cannot resolve: /usr/local/bin/ld: /tmp/cchIWyfG.o: relocation R_X86_64_32S against `.data' can not be used when making a PIE object; recompile with -fPIE collect2: error: ld returned 1 exit status Thus, since only RIP-relative addressing is legit for local symbols, use "encl_stack(%rip)" and declare an explicit "__encl_base" symbol at the start of the linker script to be able to calculate the stack address relative to the current TCS in the enclave assembly entry code. Signed-off-by: Jo Van Bulck Signed-off-by: Dave Hansen Reviewed-by: Jarkko Sakkinen Acked-by: Kai Huang Link: https://lore.kernel.org/all/f9c24d89-ed72-7d9e-c650-050d722c6b04@cs.kuleuven.be/ Link: https://lore.kernel.org/all/20231005153854.25566-8-jo.vanbulck%40cs.kuleuven.be --- tools/testing/selftests/sgx/Makefile | 2 +- tools/testing/selftests/sgx/test_encl.lds | 1 + tools/testing/selftests/sgx/test_encl_bootstrap.S | 9 ++++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/sgx/Makefile b/tools/testing/selftests/sgx/Makefile index 7eb890b..8d2ba6a 100644 --- a/tools/testing/selftests/sgx/Makefile +++ b/tools/testing/selftests/sgx/Makefile @@ -14,7 +14,7 @@ endif INCLUDES := -I$(top_srcdir)/tools/include HOST_CFLAGS := -Wall -Werror -g $(INCLUDES) -fPIC HOST_LDFLAGS := -z noexecstack -lcrypto -ENCL_CFLAGS += -Wall -Werror -static -nostdlib -ffreestanding -fPIC \ +ENCL_CFLAGS += -Wall -Werror -static-pie -nostdlib -ffreestanding -fPIE \ -fno-stack-protector -mrdrnd $(INCLUDES) ENCL_LDFLAGS := -Wl,-T,test_encl.lds,--build-id=none diff --git a/tools/testing/selftests/sgx/test_encl.lds b/tools/testing/selftests/sgx/test_encl.lds index a1ec64f..62d3716 100644 --- a/tools/testing/selftests/sgx/test_encl.lds +++ b/tools/testing/selftests/sgx/test_encl.lds @@ -10,6 +10,7 @@ PHDRS SECTIONS { . = 0; + __encl_base = .; .tcs : { *(.tcs*) } : tcs diff --git a/tools/testing/selftests/sgx/test_encl_bootstrap.S b/tools/testing/selftests/sgx/test_encl_bootstrap.S index e0ce993..28fe5d2 100644 --- a/tools/testing/selftests/sgx/test_encl_bootstrap.S +++ b/tools/testing/selftests/sgx/test_encl_bootstrap.S @@ -42,9 +42,12 @@ encl_entry: # RBX contains the base address for TCS, which is the first address # inside the enclave for TCS #1 and one page into the enclave for - # TCS #2. By adding the value of encl_stack to it, we get - # the absolute address for the stack. - lea (encl_stack)(%rbx), %rax + # TCS #2. First make it relative by substracting __encl_base and + # then add the address of encl_stack to get the address for the stack. + lea __encl_base(%rip), %rax + sub %rax, %rbx + lea encl_stack(%rip), %rax + add %rbx, %rax jmp encl_entry_core encl_dyn_entry: # Entry point for dynamically created TCS page expected to follow