From: Jarkko Sakkinen <jarkko@kernel.org>
To: shuah@kernel.org
Cc: linux-kselftest@vger.kernel.org, linux-sgx@vger.kernel.org,
Reinette Chatre <reinette.chatre@intel.com>,
Jarkko Sakkinen <jarkko@kernel.org>,
Dave Hansen <dave.hansen@linux.intel.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH v8 5/5] selftests/sgx: Refine the test enclave to have storage
Date: Thu, 10 Jun 2021 11:30:21 +0300 [thread overview]
Message-ID: <20210610083021.392269-5-jarkko@kernel.org> (raw)
In-Reply-To: <20210610083021.392269-1-jarkko@kernel.org>
Extend the enclave to have two operations: ENCL_OP_PUT and ENCL_OP_GET.
ENCL_OP_PUT stores value inside the enclave address space and
ENCL_OP_GET reads it. The internal buffer can be later extended to be
variable size, and allow reclaimer tests.
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
tools/testing/selftests/sgx/defines.h | 10 ++++
tools/testing/selftests/sgx/main.c | 57 ++++++++++++++++++-----
tools/testing/selftests/sgx/test_encl.c | 19 +++++++-
tools/testing/selftests/sgx/test_encl.lds | 3 +-
4 files changed, 74 insertions(+), 15 deletions(-)
diff --git a/tools/testing/selftests/sgx/defines.h b/tools/testing/selftests/sgx/defines.h
index 0bd73428d2f3..f88562afcaa0 100644
--- a/tools/testing/selftests/sgx/defines.h
+++ b/tools/testing/selftests/sgx/defines.h
@@ -18,4 +18,14 @@
#include "../../../../arch/x86/include/asm/enclu.h"
#include "../../../../arch/x86/include/uapi/asm/sgx.h"
+enum encl_op_type {
+ ENCL_OP_PUT,
+ ENCL_OP_GET,
+};
+
+struct encl_op {
+ uint64_t type;
+ uint64_t buffer;
+};
+
#endif /* DEFINES_H */
diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c
index bcd0257f48e0..e252015e0c15 100644
--- a/tools/testing/selftests/sgx/main.c
+++ b/tools/testing/selftests/sgx/main.c
@@ -193,14 +193,14 @@ FIXTURE_TEARDOWN(enclave)
encl_delete(&self->encl);
}
-#define ENCL_CALL(in, out, run, clobbered) \
+#define ENCL_CALL(op, run, clobbered) \
({ \
int ret; \
if ((clobbered)) \
- ret = vdso_sgx_enter_enclave((unsigned long)(in), (unsigned long)(out), 0, \
+ ret = vdso_sgx_enter_enclave((unsigned long)(op), 0, 0, \
EENTER, 0, 0, (run)); \
else \
- ret = sgx_enter_enclave((void *)(in), (void *)(out), 0, EENTER, NULL, NULL, \
+ ret = sgx_enter_enclave((void *)(op), NULL, 0, EENTER, NULL, NULL, \
(run)); \
ret; \
})
@@ -215,22 +215,44 @@ FIXTURE_TEARDOWN(enclave)
TEST_F(enclave, unclobbered_vdso)
{
- uint64_t result = 0;
+ struct encl_op op;
- EXPECT_EQ(ENCL_CALL(&MAGIC, &result, &self->run, false), 0);
+ op.type = ENCL_OP_PUT;
+ op.buffer = MAGIC;
+
+ EXPECT_EQ(ENCL_CALL(&op, &self->run, false), 0);
- EXPECT_EQ(result, MAGIC);
+ EXPECT_EEXIT(&self->run);
+ EXPECT_EQ(self->run.user_data, 0);
+
+ op.type = ENCL_OP_GET;
+ op.buffer = 0;
+
+ EXPECT_EQ(ENCL_CALL(&op, &self->run, false), 0);
+
+ EXPECT_EQ(op.buffer, MAGIC);
EXPECT_EEXIT(&self->run);
EXPECT_EQ(self->run.user_data, 0);
}
TEST_F(enclave, clobbered_vdso)
{
- uint64_t result = 0;
+ struct encl_op op;
+
+ op.type = ENCL_OP_PUT;
+ op.buffer = MAGIC;
+
+ EXPECT_EQ(ENCL_CALL(&op, &self->run, true), 0);
+
+ EXPECT_EEXIT(&self->run);
+ EXPECT_EQ(self->run.user_data, 0);
+
+ op.type = ENCL_OP_GET;
+ op.buffer = 0;
- EXPECT_EQ(ENCL_CALL(&MAGIC, &result, &self->run, true), 0);
+ EXPECT_EQ(ENCL_CALL(&op, &self->run, true), 0);
- EXPECT_EQ(result, MAGIC);
+ EXPECT_EQ(op.buffer, MAGIC);
EXPECT_EEXIT(&self->run);
EXPECT_EQ(self->run.user_data, 0);
}
@@ -245,14 +267,25 @@ static int test_handler(long rdi, long rsi, long rdx, long ursp, long r8, long r
TEST_F(enclave, clobbered_vdso_and_user_function)
{
- uint64_t result = 0;
+ struct encl_op op;
self->run.user_handler = (__u64)test_handler;
self->run.user_data = 0xdeadbeef;
- EXPECT_EQ(ENCL_CALL(&MAGIC, &result, &self->run, true), 0);
+ op.type = ENCL_OP_PUT;
+ op.buffer = MAGIC;
+
+ EXPECT_EQ(ENCL_CALL(&op, &self->run, true), 0);
+
+ EXPECT_EEXIT(&self->run);
+ EXPECT_EQ(self->run.user_data, 0);
+
+ op.type = ENCL_OP_GET;
+ op.buffer = 0;
+
+ EXPECT_EQ(ENCL_CALL(&op, &self->run, true), 0);
- EXPECT_EQ(result, MAGIC);
+ EXPECT_EQ(op.buffer, MAGIC);
EXPECT_EEXIT(&self->run);
EXPECT_EQ(self->run.user_data, 0);
}
diff --git a/tools/testing/selftests/sgx/test_encl.c b/tools/testing/selftests/sgx/test_encl.c
index cf25b5dc1e03..734ea52f9924 100644
--- a/tools/testing/selftests/sgx/test_encl.c
+++ b/tools/testing/selftests/sgx/test_encl.c
@@ -4,6 +4,8 @@
#include <stddef.h>
#include "defines.h"
+static uint8_t encl_buffer[8192] = { 1 };
+
static void *memcpy(void *dest, const void *src, size_t n)
{
size_t i;
@@ -14,7 +16,20 @@ static void *memcpy(void *dest, const void *src, size_t n)
return dest;
}
-void encl_body(void *rdi, void *rsi)
+void encl_body(void *rdi, void *rsi)
{
- memcpy(rsi, rdi, 8);
+ struct encl_op *op = (struct encl_op *)rdi;
+
+ switch (op->type) {
+ case ENCL_OP_PUT:
+ memcpy(&encl_buffer[0], &op->buffer, 8);
+ break;
+
+ case ENCL_OP_GET:
+ memcpy(&op->buffer, &encl_buffer[0], 8);
+ break;
+
+ default:
+ break;
+ }
}
diff --git a/tools/testing/selftests/sgx/test_encl.lds b/tools/testing/selftests/sgx/test_encl.lds
index 0fbbda7e665e..a1ec64f7d91f 100644
--- a/tools/testing/selftests/sgx/test_encl.lds
+++ b/tools/testing/selftests/sgx/test_encl.lds
@@ -18,9 +18,10 @@ SECTIONS
.text : {
*(.text*)
*(.rodata*)
+ FILL(0xDEADBEEF);
+ . = ALIGN(4096);
} : text
- . = ALIGN(4096);
.data : {
*(.data*)
} : data
--
2.31.1
next prev parent reply other threads:[~2021-06-10 8:30 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-10 8:30 [PATCH v8 1/5] selftests/sgx: Rename 'eenter' and 'sgx_call_vdso' Jarkko Sakkinen
2021-06-10 8:30 ` [PATCH v8 2/5] selftests/sgx: Migrate to kselftest harness Jarkko Sakkinen
2021-06-10 8:30 ` [PATCH v8 3/5] selftests/sgx: Dump enclave memory map Jarkko Sakkinen
2021-06-11 22:45 ` Shuah Khan
2021-06-12 0:34 ` Dave Hansen
2021-06-12 4:27 ` Jarkko Sakkinen
2021-06-14 16:45 ` Shuah Khan
2021-06-15 13:07 ` Jarkko Sakkinen
2021-06-10 8:30 ` [PATCH v8 4/5] selftests/sgx: Add EXPECT_EEXIT() macro Jarkko Sakkinen
2021-06-10 8:30 ` Jarkko Sakkinen [this message]
2021-06-14 20:16 ` [PATCH v8 5/5] selftests/sgx: Refine the test enclave to have storage Shuah Khan
2021-06-15 13:13 ` Jarkko Sakkinen
2021-06-15 13:15 ` Jarkko Sakkinen
2021-06-15 21:55 ` Shuah Khan
2021-06-18 9:07 ` Jarkko Sakkinen
2021-06-10 15:45 ` [PATCH v8 1/5] selftests/sgx: Rename 'eenter' and 'sgx_call_vdso' Dave Hansen
2021-06-11 17:35 ` Shuah Khan
2021-06-11 22:47 ` Shuah Khan
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=20210610083021.392269-5-jarkko@kernel.org \
--to=jarkko@kernel.org \
--cc=dave.hansen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-sgx@vger.kernel.org \
--cc=reinette.chatre@intel.com \
--cc=shuah@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 NNTP newsgroup(s).