Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signal handler #85

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,17 @@
*.mk
*.mod
*.swn

# Ignore cache directories
*.cache/
**/.cache/

# Ignore compile command files
compile_commands.json

# Ignore backup files
*.bak

# Ignore tags file (for ctags or similar)
tags

10 changes: 5 additions & 5 deletions app/aep-redirect/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <sys/mman.h>

#include "Enclave/encl_u.h"
#include "libsgxstep/counter.h"
#include "libsgxstep/debug.h"
#include "libsgxstep/elf_parser.h"
#include "libsgxstep/enclave.h"
Expand All @@ -31,7 +32,6 @@
#define DBG_ENCL 1

void *data_pt = NULL, *data_page = NULL, *code_pt = NULL;
int fault_fired = 0, aep_fired = 0;
sgx_enclave_id_t eid = 0;

void aep_cb_func(void) {
Expand All @@ -43,11 +43,11 @@ void aep_cb_func(void) {
edbgrd(get_enclave_ssa_gprsgx_adrs(), &gprsgx, sizeof(gprsgx_region_t));
dump_gprsgx_region(&gprsgx);

aep_fired++;
counter.aep_cnt++;
}

void fault_handler(int signo, siginfo_t *si, void *ctx) {
ASSERT(fault_fired < 5);
ASSERT(counter.fault_cnt < 5);

switch (signo) {
case SIGSEGV:
Expand All @@ -71,7 +71,7 @@ void fault_handler(int signo, siginfo_t *si, void *ctx) {
info("Unknown #PF address!");
}

fault_fired++;
counter.fault_cnt++;
}

void attacker_config_page_table(void) {
Expand Down Expand Up @@ -142,7 +142,7 @@ int main(int argc, char **argv) {
SGX_ASSERT(page_aligned_func(eid));

info("all is well; exiting..");
ASSERT(fault_fired && aep_fired);
ASSERT(counter.fault_cnt && counter.aep_cnt);
SGX_ASSERT(sgx_destroy_enclave(eid));
return 0;
}
16 changes: 9 additions & 7 deletions app/bench/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "Enclave/encl_u.h"
#include "libsgxstep/apic.h"
#include "libsgxstep/config.h"
#include "libsgxstep/counter.h"
#include "libsgxstep/debug.h"
#include "libsgxstep/elf_parser.h"
#include "libsgxstep/enclave.h"
Expand All @@ -45,7 +46,6 @@

sgx_enclave_id_t eid = 0;
int strlen_nb_access = 0;
int irq_cnt = 0, do_irq = 1, fault_cnt = 0;
uint64_t *pte_encl = NULL;
uint64_t *pte_str_encl = NULL;
uint64_t *pmd_encl = NULL;
Expand All @@ -56,7 +56,7 @@ uint64_t *pmd_encl = NULL;
void aep_cb_func(void) {
uint64_t erip = edbgrd_erip() - (uint64_t)get_enclave_base();
info("^^ enclave RIP=%#llx; ACCESSED=%d", erip, ACCESSED(*pte_encl));
irq_cnt++;
counter.irq_cnt++;

/* XXX insert custom attack-specific side-channel observation code here */
#if (ATTACK_SCENARIO == STRLEN)
Expand All @@ -68,11 +68,11 @@ void aep_cb_func(void) {
*pte_str_encl = MARK_NOT_ACCESSED(*pte_str_encl);
#endif

if (do_irq && (irq_cnt > NUM_RUNS * 500)) {
if (counter.do_irq && (counter.irq_cnt > NUM_RUNS * 500)) {
info(
"excessive interrupt rate detected (try adjusting timer interval "
"to avoid getting stuck in zero-stepping); aborting...");
do_irq = 0;
counter.do_irq = 0;
}

/*
Expand All @@ -91,7 +91,7 @@ void aep_cb_func(void) {
* enclave instruction.
*
*/
if (do_irq) {
if (counter.do_irq) {
*pmd_encl = MARK_NOT_ACCESSED(*pmd_encl);
apic_timer_irq(SGX_STEP_TIMER_INTERVAL);
}
Expand All @@ -101,7 +101,7 @@ void aep_cb_func(void) {
void fault_handler(int signal) {
info("Caught fault %d! Restoring enclave page permissions..", signal);
*pte_encl = MARK_NOT_EXECUTE_DISABLE(*pte_encl);
ASSERT(fault_cnt++ < 10);
ASSERT(counter.fault_cnt++ < 10);

// NOTE: return eventually continues at aep_cb_func and initiates
// single-stepping mode.
Expand Down Expand Up @@ -167,6 +167,8 @@ int main(int argc, char **argv) {
sgx_launch_token_t token = {0};
int apic_fd, encl_strlen = 0, updated = 0, vec = 0;
idt_t idt = {0};
counter.do_irq = 1;


info_event("Creating enclave...");
SGX_ASSERT(sgx_create_enclave("./Enclave/encl.so", /*debug=*/1, &token,
Expand Down Expand Up @@ -206,7 +208,7 @@ int main(int argc, char **argv) {
/* 3. Restore normal execution environment. */
SGX_ASSERT(sgx_destroy_enclave(eid));

info_event("all done; counted %d/%d IRQs (AEP/IDT)", irq_cnt,
info_event("all done; counted %d/%d IRQs (AEP/IDT)", counter.irq_cnt,
__ss_irq_count);
return 0;
}
8 changes: 4 additions & 4 deletions app/foreshadow/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ uint64_t pte_alias_unmapped = 0x0;

gprsgx_region_t shadow_gprsgx = {0x00};

int fault_fired = 0, cur_byte = 0;
int cur_byte = 0;
sgx_enclave_id_t eid = 0;

/* ================== ATTACKER IRQ/FAULT HANDLERS ================= */

/* Called upon SIGSEGV caused by untrusted page tables. */
void fault_handler(int signal)
{
fault_fired++;
counter.fault_cnt++;

/* remap enclave page, so abort page semantics apply and execution can continue. */
*pte_alias = MARK_PRESENT(pte_alias_unmapped);
Expand All @@ -78,7 +78,7 @@ void fault_handler(int signal)
}
else
{
if (fault_fired == 1)
if (counter.fault_cnt == 1)
printf("[#PF handler] ERESUME prefetch to refresh GPRSGX region; byte: ");
printf("%d ", cur_byte);
}
Expand Down Expand Up @@ -210,7 +210,7 @@ int main( int argc, char **argv )
sgx_step_eresume_cnt = 0;
SGX_ASSERT( enclave_run( eid ) );

ASSERT(fault_fired);
ASSERT(counter.fault_cnt);
dump_gprsgx_region(&shadow_gprsgx);
foreshadow_dump_perf();
info("total of %d faulting ERESUME calls needed", sgx_step_eresume_cnt);
Expand Down
Loading