From: Jo Van Bulck <jo.vanbulck@cs.kuleuven.be>
To: jarkko@kernel.org, linux-sgx@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: dave.hansen@linux.intel.com, Jo Van Bulck <jo.vanbulck@cs.kuleuven.be>
Subject: [PATCH 4/4] selftests/sgx: Fix compiler optimizations in test enclave
Date: Wed, 19 Jul 2023 16:25:00 +0200 [thread overview]
Message-ID: <20230719142500.13623-5-jo.vanbulck@cs.kuleuven.be> (raw)
In-Reply-To: <20230719142500.13623-1-jo.vanbulck@cs.kuleuven.be>
Relocate encl_op_array entries at runtime relative to the enclave base to
ensure correct function pointer when compiling the test enclave with -Os.
Declare the secinfo struct as volatile to prevent compiler optimizations
from passing an unaligned pointer to ENCLU.
Signed-off-by: Jo Van Bulck <jo.vanbulck@cs.kuleuven.be>
---
tools/testing/selftests/sgx/test_encl.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/sgx/test_encl.c b/tools/testing/selftests/sgx/test_encl.c
index 5531f5d48..d78596ccf 100644
--- a/tools/testing/selftests/sgx/test_encl.c
+++ b/tools/testing/selftests/sgx/test_encl.c
@@ -88,7 +88,8 @@ static void *memset(void *dest, int c, size_t n)
static void do_encl_emodpe(void *_op)
{
struct encl_op_emodpe op;
- struct sgx_secinfo secinfo __aligned(sizeof(struct sgx_secinfo)) = {0};
+ /* declare secinfo volatile to preserve alignment */
+ volatile struct __aligned(sizeof(struct sgx_secinfo)) sgx_secinfo secinfo = {0};
SAFE_COPY_STRUCT(_op, &op);
ASSERT_INSIDE_ENCLAVE(op.epc_addr, PAGE_SIZE);
@@ -105,8 +106,9 @@ static void do_encl_emodpe(void *_op)
static void do_encl_eaccept(void *_op)
{
struct encl_op_eaccept op;
- struct sgx_secinfo secinfo __aligned(sizeof(struct sgx_secinfo)) = {0};
int rax;
+ /* declare secinfo volatile to preserve alignment */
+ volatile struct __aligned(sizeof(struct sgx_secinfo)) sgx_secinfo secinfo = {0};
SAFE_COPY_STRUCT(_op, &op);
ASSERT_INSIDE_ENCLAVE(op.epc_addr, PAGE_SIZE);
@@ -205,7 +207,7 @@ static void do_encl_op_nop(void *_op)
void encl_body(void *rdi, void *rsi)
{
- const void (*encl_op_array[ENCL_OP_MAX])(void *) = {
+ static const void (*encl_op_array[ENCL_OP_MAX])(void *) = {
do_encl_op_put_to_buf,
do_encl_op_get_from_buf,
do_encl_op_put_to_addr,
@@ -220,5 +222,5 @@ void encl_body(void *rdi, void *rsi)
SAFE_COPY_STRUCT(rdi, &op);
if (op.type < ENCL_OP_MAX)
- (*encl_op_array[op.type])(rdi);
+ (*(get_enclave_base() + encl_op_array[op.type]))(rdi);
}
--
2.34.1
next prev parent reply other threads:[~2023-07-19 14:49 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-19 14:24 [PATCH 0/4] selftests/sgx: Harden test enclave Jo Van Bulck
2023-07-19 14:24 ` [PATCH 1/4] selftests/sgx: Harden test enclave ABI Jo Van Bulck
2023-07-20 17:27 ` Jarkko Sakkinen
2023-07-20 19:14 ` Jo Van Bulck
2023-07-19 14:24 ` [PATCH 2/4] selftests/sgx: Store base address and size in test enclave Jo Van Bulck
2023-07-20 17:29 ` Jarkko Sakkinen
2023-07-20 19:18 ` Jo Van Bulck
2023-07-19 14:24 ` [PATCH 3/4] selftests/sgx: Harden test enclave API Jo Van Bulck
2023-07-20 17:32 ` Jarkko Sakkinen
2023-07-20 19:34 ` Jo Van Bulck
2023-07-19 14:25 ` Jo Van Bulck [this message]
2023-07-20 17:25 ` [PATCH 0/4] selftests/sgx: Harden test enclave Jarkko Sakkinen
2023-07-20 19:12 ` Jo Van Bulck
2023-07-20 19:56 ` Dave Hansen
2023-07-20 20:57 ` Jo Van Bulck
2023-07-22 18:10 ` Jarkko Sakkinen
2023-07-24 10:46 ` Jo Van Bulck
2023-07-28 18:54 ` Jarkko Sakkinen
2023-08-07 6:06 ` Jo Van Bulck
2023-08-07 11:58 ` Jarkko Sakkinen
-- strict thread matches above, loose matches on Subject: below --
2023-07-20 22:16 [PATCH v2 " Jo Van Bulck
2023-07-20 22:16 ` [PATCH 4/4] selftests/sgx: Fix compiler optimizations in " Jo Van Bulck
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=20230719142500.13623-5-jo.vanbulck@cs.kuleuven.be \
--to=jo.vanbulck@cs.kuleuven.be \
--cc=dave.hansen@linux.intel.com \
--cc=jarkko@kernel.org \
--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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).