From nobody Fri Sep 12 01:33:28 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55C4DC001B0 for ; Tue, 8 Aug 2023 20:23:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233524AbjHHUXk (ORCPT ); Tue, 8 Aug 2023 16:23:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233257AbjHHUXY (ORCPT ); Tue, 8 Aug 2023 16:23:24 -0400 Received: from icts-p-cavuit-3.kulnet.kuleuven.be (icts-p-cavuit-3.kulnet.kuleuven.be [134.58.240.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 485589EDB; Tue, 8 Aug 2023 12:32:27 -0700 (PDT) X-KULeuven-Envelope-From: jo.vanbulck@cs.kuleuven.be X-KULeuven-Scanned: Found to be clean X-KULeuven-ID: 47921201CF.A1124 X-KULeuven-Information: Katholieke Universiteit Leuven Received: from icts-p-ceifnet-smtps-0.kuleuven.be (icts-p-ceifnet-smtps.service.icts.svcd [IPv6:2a02:2c40:0:51:144:242:ac11:2f]) by icts-p-cavuit-3.kulnet.kuleuven.be (Postfix) with ESMTP id 47921201CF; Tue, 8 Aug 2023 21:32:25 +0200 (CEST) BCmilterd-Mark-Subject: no BCmilterd-Errors: BCmilterd-Report: SA-HVU#DKIM_SIGNED#0.00,SA-HVU#DKIM_VALID#0.00,SA-HVU#DKIM_VALID_AU#0.00 X-CAV-Cluster: smtps DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cs.kuleuven.be; s=cav; t=1691523145; bh=LHWOrlXFlSIJK8AJUxpnLildKFYA5GugfWRgE1behfk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FCqX70SLi1DVJeREQ6P/VgJgmaABT76H39dMp1AxXEf3ms7mxzrNrYKprHOATUkA6 UpSSCFKsXgR00G5+sLDRtvOawxbzwEUWkjm/RPmmsPGeh7I31emBwaIVbieCcgKXDR gGXd4++Rhu3RiEETJU3ZSni5anqaA8DDA3EwiFnU= Received: from localhost.localdomain (rrcs-24-123-120-98.central.biz.rr.com [24.123.120.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by icts-p-ceifnet-smtps-0.kuleuven.be (Postfix) with ESMTPSA id B1F10D4F79BEF; Tue, 8 Aug 2023 21:32:23 +0200 (CEST) X-Kuleuven: This mail passed the K.U.Leuven mailcluster From: Jo Van Bulck To: jarkko@kernel.org, kai.huang@intel.com, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org Cc: dave.hansen@linux.intel.com, Jo Van Bulck Subject: [PATCH 2/8] selftests/sgx: Produce static-pie executable for test enclave Date: Tue, 8 Aug 2023 12:31:39 -0700 Message-Id: <20230808193145.8860-3-jo.vanbulck@cs.kuleuven.be> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230808193145.8860-1-jo.vanbulck@cs.kuleuven.be> References: <20230808193145.8860-1-jo.vanbulck@cs.kuleuven.be> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. Link: https://lore.kernel.org/all/f9c24d89-ed72-7d9e-c650-050d722c6b04@cs.k= uleuven.be/ Signed-off-by: Jo Van Bulck Reviewed-by: Jarkko Sakkinen --- tools/testing/selftests/sgx/Makefile | 2 +- tools/testing/selftests/sgx/test_encl.lds | 1 + tools/testing/selftests/sgx/test_encl_bootstrap.S | 12 ++++++------ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/sgx/Makefile b/tools/testing/selftests= /sgx/Makefile index 50aab6b57da3..1d6315a2e5f5 100644 --- a/tools/testing/selftests/sgx/Makefile +++ b/tools/testing/selftests/sgx/Makefile @@ -13,7 +13,7 @@ endif =20 INCLUDES :=3D -I$(top_srcdir)/tools/include HOST_CFLAGS :=3D -Wall -Werror -g $(INCLUDES) -fPIC -z noexecstack -ENCL_CFLAGS :=3D -Wall -Werror -static -nostdlib -nostartfiles -fPIC \ +ENCL_CFLAGS :=3D -Wall -Werror -static-pie -nostdlib -nostartfiles -fPIE \ -fno-stack-protector -mrdrnd $(INCLUDES) =20 TEST_CUSTOM_PROGS :=3D $(OUTPUT)/test_sgx diff --git a/tools/testing/selftests/sgx/test_encl.lds b/tools/testing/self= tests/sgx/test_encl.lds index a1ec64f7d91f..ca659db2a534 100644 --- a/tools/testing/selftests/sgx/test_encl.lds +++ b/tools/testing/selftests/sgx/test_encl.lds @@ -10,6 +10,7 @@ PHDRS SECTIONS { . =3D 0; + __enclave_base =3D .; .tcs : { *(.tcs*) } : tcs diff --git a/tools/testing/selftests/sgx/test_encl_bootstrap.S b/tools/test= ing/selftests/sgx/test_encl_bootstrap.S index 03ae0f57e29d..c91743f14312 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 __enclave_base and + # then add the address of encl_stack to get the address for the stack. + lea __enclave_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 @@ -55,12 +58,9 @@ encl_entry_core: push %rax =20 push %rcx # push the address after EENTER - push %rbx # push the enclave base address =20 call encl_body =20 - pop %rbx # pop the enclave base address - /* Clear volatile GPRs, except RAX (EEXIT function). */ xor %rcx, %rcx xor %rdx, %rdx --=20 2.34.1