From nobody Mon Feb 9 05:00:07 2026 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 85367C001B0 for ; Mon, 24 Jul 2023 16:59:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231336AbjGXQ7C (ORCPT ); Mon, 24 Jul 2023 12:59:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229654AbjGXQ6y (ORCPT ); Mon, 24 Jul 2023 12:58:54 -0400 Received: from icts-p-cavuit-1.kulnet.kuleuven.be (icts-p-cavuit-1.kulnet.kuleuven.be [IPv6:2a02:2c40:0:c0::25:132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E4C0E5A; Mon, 24 Jul 2023 09:58:51 -0700 (PDT) X-KULeuven-Envelope-From: jo.vanbulck@cs.kuleuven.be X-KULeuven-Scanned: Found to be clean X-KULeuven-ID: 038372005D.ACF16 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:143:242:ac11:20]) by icts-p-cavuit-1.kulnet.kuleuven.be (Postfix) with ESMTP id 038372005D; Mon, 24 Jul 2023 18:58:49 +0200 (CEST) BCmilterd-Mark-Subject: no BCmilterd-Errors: BCmilterd-Report: SA-HVU#DKIM_VALID_AU#0.00,SA-HVU#DKIM_SIGNED#0.00,SA-HVU#DKIM_VALID#0.00 X-CAV-Cluster: smtps DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cs.kuleuven.be; s=cav; t=1690217928; bh=Dxe4W9x8+HN82nw05K2qrlUg5MVRgfjaV8O1qUj6+p0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hwmbn9rCqHz1P3oByOgsUimcVdmObnyariMY+tPGekHMmJYi2vKrXWBWipplbR2bG xZrREpROqLaG/OU+85t+bcsV9toeIdybkC/Cfp7nMHR3n7qujeOwQ8D8t8Ad9rqVmD f2MtIbHdL4FnuUgIb6mBuOKB/M0MFxqR/zhmHqkk= Received: from librem.epfl.ch (eduroam-269-1-126.epfl.ch [192.33.197.126]) (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 C58F9D4EC8A4D; Mon, 24 Jul 2023 18:58:48 +0200 (CEST) X-Kuleuven: This mail passed the K.U.Leuven mailcluster From: Jo Van Bulck To: jarkko@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org Cc: dave.hansen@linux.intel.com, Jo Van Bulck Subject: [PATCH 1/5] selftests/sgx: Fix uninitialized pointer dereference in error path. Date: Mon, 24 Jul 2023 18:58:28 +0200 Message-Id: <20230724165832.15797-2-jo.vanbulck@cs.kuleuven.be> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230724165832.15797-1-jo.vanbulck@cs.kuleuven.be> References: <20230724165832.15797-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" Ensure ctx is zero-initialized, such that the encl_measure function will not call EVP_MD_CTX_destroy with an uninitialized ctx pointer in case of an early error during key generation. Signed-off-by: Jo Van Bulck --- tools/testing/selftests/sgx/sigstruct.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/sgx/sigstruct.c b/tools/testing/selfte= sts/sgx/sigstruct.c index a07896a46364..dd1fdab90e26 100644 --- a/tools/testing/selftests/sgx/sigstruct.c +++ b/tools/testing/selftests/sgx/sigstruct.c @@ -318,9 +318,9 @@ bool encl_measure(struct encl *encl) struct sgx_sigstruct *sigstruct =3D &encl->sigstruct; struct sgx_sigstruct_payload payload; uint8_t digest[SHA256_DIGEST_LENGTH]; + EVP_MD_CTX *ctx =3D NULL; unsigned int siglen; RSA *key =3D NULL; - EVP_MD_CTX *ctx; int i; =20 memset(sigstruct, 0, sizeof(*sigstruct)); --=20 2.34.1 From nobody Mon Feb 9 05:00:07 2026 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 BA84AC04A6A for ; Mon, 24 Jul 2023 16:58:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230439AbjGXQ65 (ORCPT ); Mon, 24 Jul 2023 12:58:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229576AbjGXQ6y (ORCPT ); Mon, 24 Jul 2023 12:58:54 -0400 Received: from icts-p-cavuit-1.kulnet.kuleuven.be (icts-p-cavuit-1.kulnet.kuleuven.be [134.58.240.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05AA1126; Mon, 24 Jul 2023 09:58:52 -0700 (PDT) X-KULeuven-Envelope-From: jo.vanbulck@cs.kuleuven.be X-KULeuven-Scanned: Found to be clean X-KULeuven-ID: 1232220163.ABA9F 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:143:242:ac11:20]) by icts-p-cavuit-1.kulnet.kuleuven.be (Postfix) with ESMTP id 1232220163; Mon, 24 Jul 2023 18:58:50 +0200 (CEST) BCmilterd-Mark-Subject: no BCmilterd-Errors: BCmilterd-Report: SA-HVU#DKIM_SIGNED#0.00,SA-HVU#DKIM_VALID_AU#0.00,SA-HVU#DKIM_VALID#0.00 X-CAV-Cluster: smtps DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cs.kuleuven.be; s=cav; t=1690217930; bh=lD0kiMZBWsG3Ln0sGsNKeezq03rPSOt4ymfz5+VDe5o=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=X1MseRk3DkU3MNN07Fegf9l2srv+Bl1Gam+0X5B7xHLustc9BncqfUBNhkZB/bSxe 1nGsE+H9tj39rHG2uugIWeFQhyuo7X9C1subFYGTyYPUOkcyApft7ogcfcBvTZ68D3 lWCxeDWeflwNWkBP3FZQv2KULHybxfgkwaOvRrxI= Received: from librem.epfl.ch (eduroam-269-1-126.epfl.ch [192.33.197.126]) (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 D3C9DD4E6AE09; Mon, 24 Jul 2023 18:58:49 +0200 (CEST) X-Kuleuven: This mail passed the K.U.Leuven mailcluster From: Jo Van Bulck To: jarkko@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org Cc: dave.hansen@linux.intel.com, Jo Van Bulck Subject: [PATCH 2/5] selftests/sgx: Fix function pointer relocation in test enclave. Date: Mon, 24 Jul 2023 18:58:29 +0200 Message-Id: <20230724165832.15797-3-jo.vanbulck@cs.kuleuven.be> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230724165832.15797-1-jo.vanbulck@cs.kuleuven.be> References: <20230724165832.15797-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" Relocate encl_op_array entries at runtime relative to the enclave base to ensure correct function pointer when compiling the test enclave with -Os. Signed-off-by: Jo Van Bulck Reviewed-by: Jarkko Sakkinen --- tools/testing/selftests/sgx/test_encl.c | 6 ++++-- tools/testing/selftests/sgx/test_encl.lds | 1 + tools/testing/selftests/sgx/test_encl_bootstrap.S | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/sgx/test_encl.c b/tools/testing/selfte= sts/sgx/test_encl.c index c0d6397295e3..4e31a6c3d673 100644 --- a/tools/testing/selftests/sgx/test_encl.c +++ b/tools/testing/selftests/sgx/test_encl.c @@ -119,9 +119,11 @@ static void do_encl_op_nop(void *_op) =20 } =20 +uint64_t get_enclave_base(void); + void encl_body(void *rdi, void *rsi) { - const void (*encl_op_array[ENCL_OP_MAX])(void *) =3D { + static void (*encl_op_array[ENCL_OP_MAX])(void *) =3D { do_encl_op_put_to_buf, do_encl_op_get_from_buf, do_encl_op_put_to_addr, @@ -135,5 +137,5 @@ void encl_body(void *rdi, void *rsi) struct encl_op_header *op =3D (struct encl_op_header *)rdi; =20 if (op->type < ENCL_OP_MAX) - (*encl_op_array[op->type])(op); + (*(get_enclave_base() + encl_op_array[op->type]))(op); } 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..6126dbd7ad1c 100644 --- a/tools/testing/selftests/sgx/test_encl_bootstrap.S +++ b/tools/testing/selftests/sgx/test_encl_bootstrap.S @@ -86,6 +86,11 @@ encl_entry_core: mov $4, %rax enclu =20 + .global get_enclave_base +get_enclave_base: + lea __enclave_base(%rip), %rax + ret + .section ".data", "aw" =20 encl_ssa_tcs1: --=20 2.34.1 From nobody Mon Feb 9 05:00:07 2026 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 E7594C001DF for ; Mon, 24 Jul 2023 16:59:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231405AbjGXQ7G (ORCPT ); Mon, 24 Jul 2023 12:59:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229828AbjGXQ6z (ORCPT ); Mon, 24 Jul 2023 12:58:55 -0400 Received: from icts-p-cavuit-3.kulnet.kuleuven.be (icts-p-cavuit-3.kulnet.kuleuven.be [IPv6:2a02:2c40:0:c0::25:133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFE2410CE; Mon, 24 Jul 2023 09:58:53 -0700 (PDT) X-KULeuven-Envelope-From: jo.vanbulck@cs.kuleuven.be X-KULeuven-Scanned: Found to be clean X-KULeuven-ID: 34CDE20172.A54AF 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:143:242:ac11:20]) by icts-p-cavuit-3.kulnet.kuleuven.be (Postfix) with ESMTP id 34CDE20172; Mon, 24 Jul 2023 18:58:52 +0200 (CEST) BCmilterd-Mark-Subject: no BCmilterd-Errors: BCmilterd-Report: SA-HVU#DKIM_SIGNED#0.00,SA-HVU#DKIM_VALID_AU#0.00,SA-HVU#DKIM_VALID#0.00 X-CAV-Cluster: smtps DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cs.kuleuven.be; s=cav; t=1690217932; bh=3sTVjBcJqPPjo0OYzuqe+tfGHRmT4ncnbaTXkKSK/8Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Ue2HPViRtDvweYElbzuySHqCl1DMqOYVqkL9UDu4XyGNXo5uBgQSiT1tgHU9+oyLR p8doeRmvjGreVh06CSr+ISFNMd76XT7auLLlmfHexCeUY8iPo9O9RWPrNhBP9rlaBe Xd6aDJHapSjvFzZ2czbENmcXKaky8ZNJUucmlW8c= Received: from librem.epfl.ch (eduroam-269-1-126.epfl.ch [192.33.197.126]) (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 04B32D4EC8A4D; Mon, 24 Jul 2023 18:58:51 +0200 (CEST) X-Kuleuven: This mail passed the K.U.Leuven mailcluster From: Jo Van Bulck To: jarkko@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org Cc: dave.hansen@linux.intel.com, Jo Van Bulck Subject: [PATCH 3/5] selftests/sgx: Ensure correct secinfo struct alignment in test enclave. Date: Mon, 24 Jul 2023 18:58:30 +0200 Message-Id: <20230724165832.15797-4-jo.vanbulck@cs.kuleuven.be> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230724165832.15797-1-jo.vanbulck@cs.kuleuven.be> References: <20230724165832.15797-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" Declare the secinfo struct as volatile to prevent compiler optimizations from passing an unaligned pointer to ENCLU. Signed-off-by: Jo Van Bulck Reviewed-by: Jarkko Sakkinen --- tools/testing/selftests/sgx/test_encl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/sgx/test_encl.c b/tools/testing/selfte= sts/sgx/test_encl.c index 4e31a6c3d673..aba301abefb8 100644 --- a/tools/testing/selftests/sgx/test_encl.c +++ b/tools/testing/selftests/sgx/test_encl.c @@ -18,7 +18,8 @@ enum sgx_enclu_function { =20 static void do_encl_emodpe(void *_op) { - struct sgx_secinfo secinfo __aligned(sizeof(struct sgx_secinfo)) =3D {0}; + /* declare secinfo volatile to preserve alignment */ + volatile struct sgx_secinfo secinfo __aligned(sizeof(struct sgx_secinfo))= =3D {0}; struct encl_op_emodpe *op =3D _op; =20 secinfo.flags =3D op->flags; @@ -32,7 +33,8 @@ static void do_encl_emodpe(void *_op) =20 static void do_encl_eaccept(void *_op) { - struct sgx_secinfo secinfo __aligned(sizeof(struct sgx_secinfo)) =3D {0}; + /* declare secinfo volatile to preserve alignment */ + volatile struct sgx_secinfo secinfo __aligned(sizeof(struct sgx_secinfo))= =3D {0}; struct encl_op_eaccept *op =3D _op; int rax; =20 --=20 2.34.1 From nobody Mon Feb 9 05:00:07 2026 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 83661C001B0 for ; Mon, 24 Jul 2023 16:59:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231395AbjGXQ7J (ORCPT ); Mon, 24 Jul 2023 12:59:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230210AbjGXQ64 (ORCPT ); Mon, 24 Jul 2023 12:58:56 -0400 Received: from icts-p-cavuit-1.kulnet.kuleuven.be (icts-p-cavuit-1.kulnet.kuleuven.be [IPv6:2a02:2c40:0:c0::25:132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19F02126; Mon, 24 Jul 2023 09:58:55 -0700 (PDT) X-KULeuven-Envelope-From: jo.vanbulck@cs.kuleuven.be X-KULeuven-Scanned: Found to be clean X-KULeuven-ID: 1D22F2005D.A8315 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:143:242:ac11:20]) by icts-p-cavuit-1.kulnet.kuleuven.be (Postfix) with ESMTP id 1D22F2005D; Mon, 24 Jul 2023 18:58:53 +0200 (CEST) BCmilterd-Mark-Subject: no BCmilterd-Errors: BCmilterd-Report: SA-HVU#DKIM_VALID_AU#0.00,SA-HVU#DKIM_SIGNED#0.00,SA-HVU#DKIM_VALID#0.00 X-CAV-Cluster: smtps DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cs.kuleuven.be; s=cav; t=1690217933; bh=Gi0IyqkKqOBe/zI/Lx9svnal+udDUH2FRaFTai1kGtA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SHRygbfxOBfDkmBGSA75+2n1rA0RJm3xAeNC/GcGQAorTNuZxhlbyRpk+VPkcPqfw hzPsgw2BS8leWj1Wr2lpAPZOqf6uxC45XS4mrGoSSa9KY4h0H4dw+5vyKvpmD0GILt ce/U316itZYCOUJyyqUKiybF5Og+XYopBbcNxfkQ= Received: from librem.epfl.ch (eduroam-269-1-126.epfl.ch [192.33.197.126]) (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 DE1B3D4ECBC84; Mon, 24 Jul 2023 18:58:52 +0200 (CEST) X-Kuleuven: This mail passed the K.U.Leuven mailcluster From: Jo Van Bulck To: jarkko@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org Cc: dave.hansen@linux.intel.com, Jo Van Bulck Subject: [PATCH 4/5] selftests/sgx: Ensure expected enclave data buffer size and placement. Date: Mon, 24 Jul 2023 18:58:31 +0200 Message-Id: <20230724165832.15797-5-jo.vanbulck@cs.kuleuven.be> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230724165832.15797-1-jo.vanbulck@cs.kuleuven.be> References: <20230724165832.15797-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" Do not declare the enclave data buffer static to ensure it is not optimized away by the compiler, even when not used entirely by the test enclave code. Use -fPIE to make the compiler access the non-static buffer with RIP-relative addressing. Place the enclave data buffer in a separate section that is explicitly placed at the start of the .data segment in the linker script, as expected by the external tests manipulating page permissions. Signed-off-by: Jo Van Bulck --- tools/testing/selftests/sgx/Makefile | 2 +- tools/testing/selftests/sgx/test_encl.c | 5 +++-- tools/testing/selftests/sgx/test_encl.lds | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/sgx/Makefile b/tools/testing/selftests= /sgx/Makefile index 50aab6b57da3..c5483445ba28 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 -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.c b/tools/testing/selfte= sts/sgx/test_encl.c index aba301abefb8..5c274e517d13 100644 --- a/tools/testing/selftests/sgx/test_encl.c +++ b/tools/testing/selftests/sgx/test_encl.c @@ -7,9 +7,10 @@ /* * Data buffer spanning two pages that will be placed first in .data * segment. Even if not used internally the second page is needed by - * external test manipulating page permissions. + * external test manipulating page permissions. Do not declare this + * buffer as static, so the compiler cannot optimize it out. */ -static uint8_t encl_buffer[8192] =3D { 1 }; +uint8_t __attribute__((section(".data.encl_buffer"))) encl_buffer[8192]; =20 enum sgx_enclu_function { EACCEPT =3D 0x5, diff --git a/tools/testing/selftests/sgx/test_encl.lds b/tools/testing/self= tests/sgx/test_encl.lds index ca659db2a534..79b1e41d8d24 100644 --- a/tools/testing/selftests/sgx/test_encl.lds +++ b/tools/testing/selftests/sgx/test_encl.lds @@ -24,6 +24,7 @@ SECTIONS } : text =20 .data : { + *(.data.encl_buffer) *(.data*) } : data =20 --=20 2.34.1 From nobody Mon Feb 9 05:00:07 2026 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 74360C001B0 for ; Mon, 24 Jul 2023 16:59:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231548AbjGXQ7L (ORCPT ); Mon, 24 Jul 2023 12:59:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230391AbjGXQ64 (ORCPT ); Mon, 24 Jul 2023 12:58:56 -0400 Received: from icts-p-cavuit-4.kulnet.kuleuven.be (icts-p-cavuit-4.kulnet.kuleuven.be [IPv6:2a02:2c40:0:c0::25:134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB687E5A; Mon, 24 Jul 2023 09:58:55 -0700 (PDT) X-KULeuven-Envelope-From: jo.vanbulck@cs.kuleuven.be X-KULeuven-Scanned: Found to be clean X-KULeuven-ID: CB535DB.A756E 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:143:242:ac11:20]) by icts-p-cavuit-4.kulnet.kuleuven.be (Postfix) with ESMTP id CB535DB; Mon, 24 Jul 2023 18:58:53 +0200 (CEST) BCmilterd-Mark-Subject: no BCmilterd-Errors: BCmilterd-Report: SA-HVU#DKIM_SIGNED#0.00,SA-HVU#DKIM_VALID_AU#0.00,SA-HVU#DKIM_VALID#0.00 X-CAV-Cluster: smtps DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cs.kuleuven.be; s=cav; t=1690217933; bh=7w33D2QvDz7AkCtWs7b/bIb0ogVy47O5Viakal8e88M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GnxZ+KGTozPERbXejMfgQSdvxq86xtqt8zgHR2rn0ZneMV98sT58DT+KaHVFMZCMy RdbE/+BBoyC6T1xAOPODMK2xEsL6+nG7ga4sMtGi7Lx+wKPbHtRgvoRNkfbR2jLDqE N9Ks2XPGOfLUlbfbIxIAJYlj9wRvVxVuhpTxUu2c= Received: from librem.epfl.ch (eduroam-269-1-126.epfl.ch [192.33.197.126]) (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 98910D4EC8A4D; Mon, 24 Jul 2023 18:58:53 +0200 (CEST) X-Kuleuven: This mail passed the K.U.Leuven mailcluster From: Jo Van Bulck To: jarkko@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org Cc: dave.hansen@linux.intel.com, Jo Van Bulck Subject: [PATCH 5/5] selftests/sgx: Enclave freestanding compilation + separate linker options. Date: Mon, 24 Jul 2023 18:58:32 +0200 Message-Id: <20230724165832.15797-6-jo.vanbulck@cs.kuleuven.be> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230724165832.15797-1-jo.vanbulck@cs.kuleuven.be> References: <20230724165832.15797-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" Fixes "'linker' input unused [-Wunused-command-line-argument]" errors when compiling with clang. Additionally pass -ffreestanding to prohibit memset/memcpy stdlib calls for optimized enclave code. Signed-off-by: Jo Van Bulck --- tools/testing/selftests/sgx/Makefile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/sgx/Makefile b/tools/testing/selftests= /sgx/Makefile index c5483445ba28..aff419615462 100644 --- a/tools/testing/selftests/sgx/Makefile +++ b/tools/testing/selftests/sgx/Makefile @@ -12,9 +12,11 @@ OBJCOPY :=3D $(CROSS_COMPILE)objcopy 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 -fPIE \ - -fno-stack-protector -mrdrnd $(INCLUDES) +HOST_CFLAGS :=3D -Wall -Werror -g $(INCLUDES) -fPIC +HOST_LDFLAGS :=3D -z noexecstack -lcrypto +ENCL_CFLAGS :=3D -Wall -Werror -static -nostdlib -ffreestanding \ + -nostartfiles -fPIE -fno-stack-protector -mrdrnd $(INCLUDES) +ENCL_LDFLAGS :=3D -z noexecstack -Wl,--build-id=3Dnone =20 TEST_CUSTOM_PROGS :=3D $(OUTPUT)/test_sgx TEST_FILES :=3D $(OUTPUT)/test_encl.elf @@ -28,7 +30,7 @@ $(OUTPUT)/test_sgx: $(OUTPUT)/main.o \ $(OUTPUT)/sigstruct.o \ $(OUTPUT)/call.o \ $(OUTPUT)/sign_key.o - $(CC) $(HOST_CFLAGS) -o $@ $^ -lcrypto + $(CC) $(HOST_CFLAGS) -o $@ $^ $(HOST_LDFLAGS) =20 $(OUTPUT)/main.o: main.c $(CC) $(HOST_CFLAGS) -c $< -o $@ @@ -46,7 +48,7 @@ $(OUTPUT)/sign_key.o: sign_key.S $(CC) $(HOST_CFLAGS) -c $< -o $@ =20 $(OUTPUT)/test_encl.elf: test_encl.lds test_encl.c test_encl_bootstrap.S - $(CC) $(ENCL_CFLAGS) -T $^ -o $@ -Wl,--build-id=3Dnone + $(CC) $(ENCL_CFLAGS) -T $^ -o $@ $(ENCL_LDFLAGS) =20 EXTRA_CLEAN :=3D \ $(OUTPUT)/test_encl.elf \ --=20 2.34.1