Intel® Software Guard Extensions (Intel® SGX)
Use hardware-based isolation and memory encryption to provide more code protection in your solutions.

Access uRSP and uRBP from enclave code on Windows

EgremyB
Novice
433 Views

Hi!

I need to access the uRSP and uRBP registers of the GPRSG portion of the SSA region from enclave code using the Windows SGX SDK on Visual Studio 2019.

I know it can be done using the Linux SGX SDK with the following code :

 

 

typedef uint64_t sys_word_t;
typedef struct _thread_data_t
{
    sys_word_t  self_addr;
    sys_word_t  last_sp;            /* set by urts, relative to TCS */
    sys_word_t  stack_base_addr;    /* set by urts, relative to TCS */
    sys_word_t  stack_limit_addr;   /* set by urts, relative to TCS */
    sys_word_t  first_ssa_gpr;      /* set by urts, relative to TCS */
    sys_word_t  stack_guard;        /* GCC expects start_guard at 0x14 on x86 and 0x28 on x64 */

    sys_word_t  flags;
    sys_word_t  xsave_size;         /* in bytes (se_ptrace.c needs to know its offset).*/
    sys_word_t  last_error;         /* init to be 0. Used by trts. */

#ifdef TD_SUPPORT_MULTI_PLATFORM
    sys_word_t  m_next;             /* next TD used by trusted thread library (of type "struct _thread_data *") */
#else
    struct _thread_data_t *m_next;
#endif
    sys_word_t  tls_addr;           /* points to TLS pages */
    sys_word_t  tls_array;          /* points to TD.tls_addr relative to TCS */
#ifdef TD_SUPPORT_MULTI_PLATFORM
    sys_word_t  exception_flag;     /* mark how many exceptions are being handled */
#else
    intptr_t    exception_flag;
#endif
    sys_word_t  cxx_thread_info[6];
    sys_word_t  stack_commit_addr;
} thread_data_t;

#ifdef __cplusplus
extern "C" {
#endif

thread_data_t *get_thread_data(void);

#ifdef __cplusplus
}
#endif

/* THEN URSP AND URBP CAN BE RETRIEVED LIKE THIS */
thread_data_t *thread_data = get_thread_data();
size_t* regs = (size_t*)(thread_data->first_ssa_gpr);
printf("uRSP: %zx", regs[18]);
printf("uRBP: %zx", regs[19]);


 

 

It seems like the get_thread_data() function does not exist on my system, so I can't use the code shown above. How can it be achieved using the SDK for Visual C++ on Windows 10?

Labels (3)
0 Kudos
1 Solution
JesusG_Intel
Moderator
387 Views

Hello EgremyB,


The functionality you are referring to is part of the trusted runtime, not part of the SGX SDK, and is internal only. SGX does not expose this functionality to the user as it is meant to be used only by the trusted runtime. Unfortunately, what you are trying to do is unsupported.


Sincerely,

Jesus G.

Intel Customer Support


View solution in original post

3 Replies
JesusG_Intel
Moderator
408 Views

Hello EgremyB,


I am checking this with my resources.


Sincerely,

Jesus G.

Intel Customer Support


JesusG_Intel
Moderator
388 Views

Hello EgremyB,


The functionality you are referring to is part of the trusted runtime, not part of the SGX SDK, and is internal only. SGX does not expose this functionality to the user as it is meant to be used only by the trusted runtime. Unfortunately, what you are trying to do is unsupported.


Sincerely,

Jesus G.

Intel Customer Support


JesusG_Intel
Moderator
380 Views

This thread has been marked as answered and Intel will no longer monitor this thread. If you want a response from Intel in a follow-up question, please open a new thread.


Reply