Linux-Sgx Archive on lore.kernel.org
 help / color / Atom feed
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc: linux-sgx@vger.kernel.org
Subject: [PATCH for_v23 2/5] selftests/x86/sgx: Add check to verify exit handler stack alignment
Date: Thu, 10 Oct 2019 17:40:56 -0700
Message-ID: <20191011004059.28581-3-sean.j.christopherson@intel.com> (raw)
In-Reply-To: <20191011004059.28581-1-sean.j.christopherson@intel.com>

Add an assembly trampoline to the basic exit handler to snapshot the
pre-CALL %rsp in order to verify that the stack is 16-byte aligned as
required by the x86_64 ABI.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 tools/testing/selftests/x86/sgx/defines.h |  1 +
 tools/testing/selftests/x86/sgx/main.c    | 20 +++++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/x86/sgx/defines.h b/tools/testing/selftests/x86/sgx/defines.h
index 199a830e198a..8ddd3cfd1070 100644
--- a/tools/testing/selftests/x86/sgx/defines.h
+++ b/tools/testing/selftests/x86/sgx/defines.h
@@ -15,6 +15,7 @@ typedef uint64_t u64;
 
 #define __aligned(x) __attribute__((__aligned__(x)))
 #define __packed __attribute__((packed))
+#define __used __attribute__((__used__))
 
 /* Derived from asm-generic/bitsperlong.h. */
 #if __x86_64__
diff --git a/tools/testing/selftests/x86/sgx/main.c b/tools/testing/selftests/x86/sgx/main.c
index 029502d81ac9..f46e5c8fdac4 100644
--- a/tools/testing/selftests/x86/sgx/main.c
+++ b/tools/testing/selftests/x86/sgx/main.c
@@ -331,14 +331,28 @@ static void test_vdso_no_exit_handler(struct sgx_secs *secs)
 	ASSERT_EQ(exception.leaf, ENCLU_EENTER);
 }
 
-static int basic_exit_handler(long rdi, long rsi, long rdx, int ret,
-			      long r8, long r9, void *tcs, long ursp,
-			      struct sgx_enclave_exception *e)
+static int __used __basic_exit_handler(long rdi, long rsi, long rdx, int ret,
+				       long r8, long r9, void *tcs, long ursp,
+				       struct sgx_enclave_exception *e)
 {
+	TEST_ASSERT(!(r9 & 0xf), "Pre-CALL RSP not 16-byte aligned: %lx\n", r9);
 	ASSERT_EQ(ret, 0);
 	return 0;
 }
 
+extern void *basic_exit_handler;
+
+static void __used basic_exit_handler_trampoline(void)
+{
+	/* Load the pre-CALL %rsp into %r9 to verify correct alignment. */
+	asm volatile("1:\n\t"
+		     "lea 0x8(%%rsp), %%r9\n\t"
+		     "jmp __basic_exit_handler\n\t"
+		     "basic_exit_handler: .quad 1b\n\t"
+		     ".global basic_exit_handler"
+		     ::: "memory");
+}
+
 static int nr_page_faults;
 
 static int mprotect_exit_handler(long rdi, long rsi, long rdx, int ret,
-- 
2.22.0


  parent reply index

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-11  0:40 [PATCH for_v23 0/5] x86/vdso: sgx: Bug fixes Sean Christopherson
2019-10-11  0:40 ` [PATCH for_v23 1/5] x86/vdso: sgx: Fix misaligned stack bug when invoking exit handler Sean Christopherson
2019-10-11  0:40 ` Sean Christopherson [this message]
2019-10-14 21:09   ` [PATCH for_v23 2/5] selftests/x86/sgx: Add check to verify exit handler stack alignment Jarkko Sakkinen
2019-10-14 21:14     ` Jarkko Sakkinen
2019-10-11  0:40 ` [PATCH for_v23 3/5] x86/vdso: sgx: Fix unwinder support Sean Christopherson
2019-10-16 22:25   ` Xing, Cedric
2019-10-11  0:40 ` [PATCH for_v23 4/5] x86/vdso: sgx: Reorder params to callback to improve readability Sean Christopherson
2019-10-16 22:24   ` Xing, Cedric
2019-10-16 23:06     ` Sean Christopherson
2019-10-11  0:40 ` [PATCH for_v23 5/5] selftests/x86/sgx: Update the callbacks function parameters Sean Christopherson
2019-10-14 21:27 ` [PATCH for_v23 0/5] x86/vdso: sgx: Bug fixes Jarkko Sakkinen

Reply instructions:

You may reply publically 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=20191011004059.28581-3-sean.j.christopherson@intel.com \
    --to=sean.j.christopherson@intel.com \
    --cc=jarkko.sakkinen@linux.intel.com \
    --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

Linux-Sgx Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-sgx/0 linux-sgx/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-sgx linux-sgx/ https://lore.kernel.org/linux-sgx \
		linux-sgx@vger.kernel.org
	public-inbox-index linux-sgx

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-sgx


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git