Community
cancel
Showing results for 
Search instead for 
Did you mean: 
jun_z_
Beginner
58 Views

How to debug the sgement fault of SGX?

Hi all,

I am a freshman in SGX. I am trying to rewrite an encryption program based on SGX. The rewritten program is compiled and linked successfully. However, a segment fault is reported when I am running the rewritten program.

1. The following is the trusted part:

sgx_status_t gen_iv_key_p(unsigned char *iv_key_p){
    sgx_status_t sgx_ret;

    sgx_ret = sgx_read_rand(iv_key_p, 48);
    return sgx_ret;
}

sgx_status_t gen_iv_key_u(unsigned char *key_u, unsigned char *IV_u, unsigned char *passwd, int passlen)
{
    sgx_status_t sgx_ret = SGX_SUCCESS;
    sgx_sha_state_handle_t sha_context;

    sgx_ret = sgx_sha256_init(&sha_context);
    if (sgx_ret != SGX_SUCCESS)
    {
        return sgx_ret;
    }

    sgx_ret = sgx_sha256_update((uint8_t*)IV_u, 16, sha_context);
    if (sgx_ret != SGX_SUCCESS)
    {
        sgx_sha256_close(sha_context);
        return sgx_ret;
    }

    sgx_ret = sgx_sha256_update((uint8_t*)passwd, passlen, sha_context);
    if (sgx_ret != SGX_SUCCESS)
    {
        sgx_sha256_close(sha_context);
        return sgx_ret;
    }

    sgx_ret = sgx_sha256_get_hash(sha_context, (uint8_t (*)[32])key_u);
    if (sgx_ret != SGX_SUCCESS)
    {
        sgx_sha256_close(sha_context);
        return sgx_ret;
    }

    sgx_ret = sgx_sha256_close(sha_context);

    return sgx_ret;
}

2. And the EDL file is as following:

enclave {

    include "sgx_trts.h"
    include "sgx_tcrypto.h"

    trusted {
        /* define ECALLs here. */
        public sgx_status_t gen_iv_key_p([out, size=48] unsigned char *iv_key_p);
        public sgx_status_t gen_iv_key_u([out, size=32] unsigned char *key_u,[in, size=16] unsigned char *IV_u, [in, size=passlen] unsigned char *passwd, int passlen);
    };

};

3. Then, I call the trusted part like this:
/*******************************/
/* create the enclave          */
/*******************************/
*ret = sgx_create_enclave(ENCLAVE_FILE, SGX_DEBUG_FLAG, &token, &updated, &eid, NULL);
    if(*ret != SGX_SUCCESS){
        printf("App: error %#x, faild to create enclave.\n", *ret);
        return -1;
}

gen_iv_key_p(eid, ret, buffer);

gen_iv_key_u(eid, ret, key_u, IV, passwd, passlen);

4. The log is as following:

[CEnclavePool /home/zhangjun/project/linux-sgx/psw/urts/enclave.cpp:301] enter CEnclavePool constructor
[parse_dyn /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:153] dynamic tag = 10, ptr = 0
[parse_dyn /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:153] dynamic tag = 1a, ptr = 216e88
[parse_dyn /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:153] dynamic tag = 1c, ptr = 18
[parse_dyn /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:153] dynamic tag = 6ffffef5, ptr = 278
[parse_dyn /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:153] dynamic tag = 5, ptr = 460
[parse_dyn /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:153] dynamic tag = 6, ptr = 2e0
[parse_dyn /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:153] dynamic tag = a, ptr = cf
[parse_dyn /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:153] dynamic tag = b, ptr = 18
[parse_dyn /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:153] dynamic tag = 15, ptr = 0
[parse_dyn /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:153] dynamic tag = 7, ptr = 530
[parse_dyn /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:153] dynamic tag = 8, ptr = 348
[parse_dyn /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:153] dynamic tag = 9, ptr = 18
[parse_dyn /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:153] dynamic tag = 6ffffff9, ptr = 23
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [0] : sh_addr = 0, sh_size = 0, sh_offset = 0, sh_name = 0
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [1] .interp: sh_addr = 238, sh_size = 1c, sh_offset = 238, sh_name = 1b
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [2] .note.gnu.build-id: sh_addr = 254, sh_size = 24, sh_offset = 254, sh_name = 23
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [3] .gnu.hash: sh_addr = 278, sh_size = 64, sh_offset = 278, sh_name = 36
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [4] .dynsym: sh_addr = 2e0, sh_size = 180, sh_offset = 2e0, sh_name = 40
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [0] : sh_addr = 0, sh_size = 0, sh_offset = 0, sh_name = 0
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [1] .interp: sh_addr = 238, sh_size = 1c, sh_offset = 238, sh_name = 1b
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [2] .note.gnu.build-id: sh_addr = 254, sh_size = 24, sh_offset = 254, sh_name = 23
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [3] .gnu.hash: sh_addr = 278, sh_size = 64, sh_offset = 278, sh_name = 36
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [4] .dynsym: sh_addr = 2e0, sh_size = 180, sh_offset = 2e0, sh_name = 40
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [5] .dynstr: sh_addr = 460, sh_size = cf, sh_offset = 460, sh_name = 48
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [0] : sh_addr = 0, sh_size = 0, sh_offset = 0, sh_name = 0
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [1] .interp: sh_addr = 238, sh_size = 1c, sh_offset = 238, sh_name = 1b
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [2] .note.gnu.build-id: sh_addr = 254, sh_size = 24, sh_offset = 254, sh_name = 23
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [3] .gnu.hash: sh_addr = 278, sh_size = 64, sh_offset = 278, sh_name = 36
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [4] .dynsym: sh_addr = 2e0, sh_size = 180, sh_offset = 2e0, sh_name = 40
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [5] .dynstr: sh_addr = 460, sh_size = cf, sh_offset = 460, sh_name = 48
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [6] .rela.dyn: sh_addr = 530, sh_size = 348, sh_offset = 530, sh_name = 50
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [0] : sh_addr = 0, sh_size = 0, sh_offset = 0, sh_name = 0
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [0] : sh_addr = 0, sh_size = 0, sh_offset = 0, sh_name = 0
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [1] .interp: sh_addr = 238, sh_size = 1c, sh_offset = 238, sh_name = 1b
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [2] .note.gnu.build-id: sh_addr = 254, sh_size = 24, sh_offset = 254, sh_name = 23
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [3] .gnu.hash: sh_addr = 278, sh_size = 64, sh_offset = 278, sh_name = 36
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [4] .dynsym: sh_addr = 2e0, sh_size = 180, sh_offset = 2e0, sh_name = 40
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [5] .dynstr: sh_addr = 460, sh_size = cf, sh_offset = 460, sh_name = 48
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [6] .rela.dyn: sh_addr = 530, sh_size = 348, sh_offset = 530, sh_name = 50
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [7] .text: sh_addr = 880, sh_size = 120e7, sh_offset = 880, sh_name = 5a
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [8] .rodata: sh_addr = 13000, sh_size = 1c00, sh_offset = 13000, sh_name = 60
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [9] .eh_frame_hdr: sh_addr = 14c00, sh_size = 45c, sh_offset = 14c00, sh_name = 68
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [10] .eh_frame: sh_addr = 15060, sh_size = 11d0, sh_offset = 15060, sh_name = 76
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [11] .fini_array: sh_addr = 216e88, sh_size = 18, sh_offset = 16e88, sh_name = 80
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [12] .data.rel.ro: sh_addr = 216ea0, sh_size = 28, sh_offset = 16ea0, sh_name = 8c
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [13] .dynamic: sh_addr = 216ec8, sh_size = 120, sh_offset = 16ec8, sh_name = 99
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [14] .got.plt: sh_addr = 217000, sh_size = 18, sh_offset = 17000, sh_name = a2
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [15] .data: sh_addr = 217020, sh_size = 208, sh_offset = 17020, sh_name = ab
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [16] .bss: sh_addr = 217240, sh_size = 458, sh_offset = 17228, sh_name = b1
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [17] .comment: sh_addr = 0, sh_size = 2b, sh_offset = 17228, sh_name = b6
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [18] .note.sgxmeta: sh_addr = 0, sh_size = 1019, sh_offset = 17253, sh_name = bf
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [19] .debug_aranges: sh_addr = 0, sh_size = 620, sh_offset = 18270, sh_name = cd
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [20] .debug_info: sh_addr = 0, sh_size = bab1, sh_offset = 18890, sh_name = dc
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [21] .debug_abbrev: sh_addr = 0, sh_size = 1ef0, sh_offset = 24341, sh_name = e8
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [22] .debug_line: sh_addr = 0, sh_size = 4494, sh_offset = 26231, sh_name = f6
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [23] .debug_str: sh_addr = 0, sh_size = 4c99, sh_offset = 2a6c5, sh_name = 102
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [24] .debug_ranges: sh_addr = 0, sh_size = 2a0, sh_offset = 2f35e, sh_name = 10d
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [25] .shstrtab: sh_addr = 0, sh_size = 11b, sh_offset = 2f5fe, sh_name = 11
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [26] .symtab: sh_addr = 0, sh_size = 1878, sh_offset = 2fe20, sh_name = 1
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [27] .strtab: sh_addr = 0, sh_size = dc0, sh_offset = 31698, sh_name = 9
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [0] : sh_addr = 0, sh_size = 0, sh_offset = 0, sh_name = 0
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [1] .interp: sh_addr = 238, sh_size = 1c, sh_offset = 238, sh_name = 1b
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [2] .note.gnu.build-id: sh_addr = 254, sh_size = 24, sh_offset = 254, sh_name = 23
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [3] .gnu.hash: sh_addr = 278, sh_size = 64, sh_offset = 278, sh_name = 36
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [4] .dynsym: sh_addr = 2e0, sh_size = 180, sh_offset = 2e0, sh_name = 40
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [5] .dynstr: sh_addr = 460, sh_size = cf, sh_offset = 460, sh_name = 48
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [6] .rela.dyn: sh_addr = 530, sh_size = 348, sh_offset = 530, sh_name = 50
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [7] .text: sh_addr = 880, sh_size = 120e7, sh_offset = 880, sh_name = 5a
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [8] .rodata: sh_addr = 13000, sh_size = 1c00, sh_offset = 13000, sh_name = 60
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [9] .eh_frame_hdr: sh_addr = 14c00, sh_size = 45c, sh_offset = 14c00, sh_name = 68
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [10] .eh_frame: sh_addr = 15060, sh_size = 11d0, sh_offset = 15060, sh_name = 76
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [11] .fini_array: sh_addr = 216e88, sh_size = 18, sh_offset = 16e88, sh_name = 80
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [12] .data.rel.ro: sh_addr = 216ea0, sh_size = 28, sh_offset = 16ea0, sh_name = 8c
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [13] .dynamic: sh_addr = 216ec8, sh_size = 120, sh_offset = 16ec8, sh_name = 99
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [14] .got.plt: sh_addr = 217000, sh_size = 18, sh_offset = 17000, sh_name = a2
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [15] .data: sh_addr = 217020, sh_size = 208, sh_offset = 17020, sh_name = ab
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [16] .bss: sh_addr = 217240, sh_size = 458, sh_offset = 17228, sh_name = b1
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [17] .comment: sh_addr = 0, sh_size = 2b, sh_offset = 17228, sh_name = b6
[get_section /home/zhangjun/project/linux-sgx/psw/urts/parser/elfparser.cpp:81] section [18] .note.sgxmeta: sh_addr = 0, sh_size = 1019, sh_offset = 17253, sh_name = bf
[create_enclave enclave_creator_hw.cpp:124]
 secs.attibutes.flags = 6, secs.attributes.xfrm = 7
[build_secs /home/zhangjun/project/linux-sgx/psw/urts/loader.cpp:346] enclave start address = 0x7f1ea2800000, size = 800000
[reg_sig_handler sig_handler.cpp:190] signal handler is registered
[__create_enclave /home/zhangjun/project/linux-sgx/psw/urts/urts_com.h:167] add tcs 0x7f1ea2b5a000
[__create_enclave /home/zhangjun/project/linux-sgx/psw/urts/urts_com.h:167] add tcs 0x7f1ea2ba1000
[__create_enclave /home/zhangjun/project/linux-sgx/psw/urts/urts_com.h:167] add tcs 0x7f1ea2be8000
[__create_enclave /home/zhangjun/project/linux-sgx/psw/urts/urts_com.h:167] add tcs 0x7f1ea2c2f000
[__create_enclave /home/zhangjun/project/linux-sgx/psw/urts/urts_com.h:167] add tcs 0x7f1ea2c76000
[__create_enclave /home/zhangjun/project/linux-sgx/psw/urts/urts_com.h:167] add tcs 0x7f1ea2cbd000
[__create_enclave /home/zhangjun/project/linux-sgx/psw/urts/urts_com.h:167] add tcs 0x7f1ea2d04000
[__create_enclave /home/zhangjun/project/linux-sgx/psw/urts/urts_com.h:167] add tcs 0x7f1ea2d4b000
[__create_enclave /home/zhangjun/project/linux-sgx/psw/urts/urts_com.h:167] add tcs 0x7f1ea2d92000
[__create_enclave /home/zhangjun/project/linux-sgx/psw/urts/urts_com.h:167] add tcs 0x7f1ea2dd9000
[__create_enclave /home/zhangjun/project/linux-sgx/psw/urts/urts_com.h:194] Debug enclave. Checking if VTune is profiling
[__create_enclave /home/zhangjun/project/linux-sgx/psw/urts/urts_com.h:235] VTune is not profiling. Debug OPTIN bit not set and API to do module mapping not invoked
[sig_handler sig_handler.cpp:94] signal handler is triggered
[sig_handler sig_handler.cpp:150] NOT enclave signal
Segmentation fault (core dumped)

How to fix this fault?

0 Kudos
0 Replies