From: "Huang, Kai" <kai.huang@intel.com>
To: "linux-sgx@vger.kernel.org" <linux-sgx@vger.kernel.org>,
"jarkko@kernel.org" <jarkko@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Van Bulck, Jo" <jo.vanbulck@cs.kuleuven.be>
Cc: "dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>
Subject: Re: [PATCH 4/5] selftests/sgx: Ensure expected enclave data buffer size and placement.
Date: Thu, 3 Aug 2023 04:22:55 +0000 [thread overview]
Message-ID: <ea91bcfdf3ae32fb0f7ac4f866c63dbf5bbaa0ab.camel@intel.com> (raw)
In-Reply-To: <20230724165832.15797-5-jo.vanbulck@cs.kuleuven.be>
On Mon, 2023-07-24 at 18:58 +0200, Jo Van Bulck wrote:
> 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.
The "encl_buffer" array is initialized to 1 explicitly, which means it should be
in .data section. As Jarkko commented, can you add more information about in
what cases it can be optimized away?
> Use -fPIE to make the compiler access the non-static buffer with
> RIP-relative addressing.
>
I am not quite following how does "RIP-relative addressing" fix any problem? Is
there any hard relationship between "RIP-relative addressing" and the problem
that you are having?
> 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.
So this change is not to fix the problem that "the compiler may optimize away
the encl_buffer array", correct?
>
> Signed-off-by: Jo Van Bulck <jo.vanbulck@cs.kuleuven.be>
> ---
> 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
>
> INCLUDES := -I$(top_srcdir)/tools/include
> HOST_CFLAGS := -Wall -Werror -g $(INCLUDES) -fPIC -z noexecstack
> -ENCL_CFLAGS := -Wall -Werror -static -nostdlib -nostartfiles -fPIC \
> +ENCL_CFLAGS := -Wall -Werror -static -nostdlib -nostartfiles -fPIE \
> -fno-stack-protector -mrdrnd $(INCLUDES)
>
> TEST_CUSTOM_PROGS := $(OUTPUT)/test_sgx
> diff --git a/tools/testing/selftests/sgx/test_encl.c b/tools/testing/selftests/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] = { 1 };
> +uint8_t __attribute__((section(".data.encl_buffer"))) encl_buffer[8192];
>
> enum sgx_enclu_function {
> EACCEPT = 0x5,
> diff --git a/tools/testing/selftests/sgx/test_encl.lds b/tools/testing/selftests/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
>
> .data : {
> + *(.data.encl_buffer)
> *(.data*)
> } : data
>
next prev parent reply other threads:[~2023-08-03 4:23 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-24 16:58 [PATCH 0/5] selftests/sgx: Fix compilation errors Jo Van Bulck
2023-07-24 16:58 ` [PATCH 1/5] selftests/sgx: Fix uninitialized pointer dereference in error path Jo Van Bulck
2023-07-28 19:03 ` Jarkko Sakkinen
2023-08-07 6:06 ` Jo Van Bulck
2023-07-28 19:04 ` Jarkko Sakkinen
2023-08-03 3:51 ` Huang, Kai
2023-08-07 6:15 ` Jo Van Bulck
2023-07-24 16:58 ` [PATCH 2/5] selftests/sgx: Fix function pointer relocation in test enclave Jo Van Bulck
2023-07-28 19:05 ` Jarkko Sakkinen
2023-08-03 3:58 ` Huang, Kai
2023-08-07 7:13 ` Jo Van Bulck
2023-08-18 12:54 ` Huang, Kai
2023-08-19 2:30 ` Jo Van Bulck
2023-08-21 11:04 ` Huang, Kai
2023-08-21 13:24 ` Jo Van Bulck
2023-07-24 16:58 ` [PATCH 3/5] selftests/sgx: Ensure correct secinfo struct alignment " Jo Van Bulck
2023-07-28 19:05 ` Jarkko Sakkinen
2023-08-03 4:00 ` Huang, Kai
2023-08-07 9:21 ` Jo Van Bulck
2023-07-24 16:58 ` [PATCH 4/5] selftests/sgx: Ensure expected enclave data buffer size and placement Jo Van Bulck
2023-07-28 19:19 ` Jarkko Sakkinen
2023-08-07 9:41 ` Jo Van Bulck
2023-08-18 13:07 ` Huang, Kai
2023-08-19 1:11 ` Jo Van Bulck
2023-08-03 4:22 ` Huang, Kai [this message]
2023-08-07 9:50 ` Jo Van Bulck
2023-07-24 16:58 ` [PATCH 5/5] selftests/sgx: Enclave freestanding compilation + separate linker options Jo Van Bulck
2023-07-28 19:22 ` Jarkko Sakkinen
2023-08-07 10:03 ` Jo Van Bulck
2023-07-28 19:01 ` [PATCH 0/5] selftests/sgx: Fix compilation errors Jarkko Sakkinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ea91bcfdf3ae32fb0f7ac4f866c63dbf5bbaa0ab.camel@intel.com \
--to=kai.huang@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=jarkko@kernel.org \
--cc=jo.vanbulck@cs.kuleuven.be \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sgx@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox