Re: [PATCH v3 2/9] selftests/sgx: Produce static-pie executable for test enclave

From: Jo Van Bulck
Date: Wed Aug 23 2023 - 09:21:45 EST


On 22.08.23 02:26, Huang, Kai wrote:

... I think only this build flag change should be done in this patch, as
described in the changelog.

Because ...

... if I am not missing anything, this chunk isn't needed for _this_ patch.  The
old code can still produce the correct stack address. __encl_base is only needed
for the next patch, thus the relevant change should be moved to the next patch.

I understand the confusion, but the reason I included this small change already in this commit is to make sure the commit compiles standalone. That is, when building the original assembly statement "lea (encl_stack)(%rbx), %rax" with -static-pie -fPIE, the linker complains about a relocation it cannot resolve:

/usr/local/bin/ld: /tmp/cchIWyfG.o: relocation R_X86_64_32S against `.data' can not be used when making a PIE object; recompile with -fPIE
collect2: error: ld returned 1 exit status

The problem is that only RIP-relative addressing is legit for local symbols, ie "encl_stack(%rip)". Hence, __encl_base is already needed here to calculate the stack address in the updated asm sequence in this patch.

Hope this helps clarifying!

I honestly don't understand what's the purpose of this code change. I believe
this change can be done (because it looks there's no need push/pop %rbx in the
first place), but again it should be in the next patch I suppose.

Thanks, the purpose indeed was merely to remove redundant code that is not needed. I see that it would be better to include this in a separate patch, so I'll update this in the next patch revision.

FWIW: if this is okay, while I'm on it, I'll also take a shot at removing remaining (unnecessary) assembly register cleansing code to make it more obvious that the test enclave is *not* exemplary secure, as per our earlier discussions. Ie in response to Dave's earlier comments that "The only patches I want for the kernel are to make the test enclave more *obviously* insecure." [1].

Best,
Jo

[1] https://lore.kernel.org/all/da0cfb1e-e347-f7f2-ac72-aec0ee0d867d@xxxxxxxxx/