Is self-modifying code allowed in SGX enclaves? I created a simple example that just calls a function stored in a data buffer. I changed the properties for the enclave DLL so that data is also executable. It worked when I compiled the project in simulation mode, but it crashes in hardware mode.
I cast the data buffer as a function pointer and then call the function pointer. I don't use any inline assembly. To get the bytes for the data buffer, I compiled a project with a simple function (in this case just returning the sum of two parameters), and extracted the bytes of the function from the exe.
I don't see any issues with that, off the top of my head but I'll confer with some experts and report back. Meanwhile, can you post the disassembly for your function? From your description it sounds like it should be small.
Yes, the disassembly is not too long. Here it is:
55 push rbp 8b ec mov ebp,esp 81 ec c0 00 00 00 sub esp,0xc0 53 push rbx 56 push rsi 57 push rdi 8d bd 40 ff ff ff lea edi,[rbp-0xc0] b9 30 00 00 00 mov ecx,0x30 b8 cc cc cc cc mov eax,0xcccccccc f3 ab rep stos DWORD PTR es:[rdi],eax 8b 45 08 mov eax,DWORD PTR [rbp+0x8] 03 45 0c add eax,DWORD PTR [rbp+0xc] 5f pop rdi 5e pop rsi 5b pop rbx 8b e5 mov esp,ebp 5d pop rbp c3 ret