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

psw/ae: blank out ld-linux.so interpretor path from AEs #1061

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

berrange
Copy link

@berrange berrange commented Oct 8, 2024

The enclaves are getting built as ELF executables, and thus the linker will embed the current ld-linux.so path for the host OS environment in the binary:

$ readelf -a libsgx_pce.signed.so | grep interpreter
[Requesting program interpreter: /nix/store/xmprbk52mlcdsljz66m8yf7cf0xf36n1-glibc-2.38-44/lib/ld-linux-x86-64.so.2]

The SGX enclaves are never loaded using ld-linux.so, as SGX has custom code for loading enclaves in the required manner.

This embedded ld-linux.so path thus serves no functional purpose, while also making it harder to do a reproducible build of the enclaves outside of the NixOS environment.

This patch blanks out the NixOS interpretor path, by setting it to the empty string.

Fixes: #1040

Two alternatives I considered:

  • Extending the strip command to add --remove-section=.interp. This has the undesirable side effect that 'readelf' will complain that the AE ELF file is malformed, because ELF executables are expected to have an .interp section
  • Changing LDTFLAGS to add -Wl,--shared. This tells the linker to create an ELF file that is a shared library rather than an executable, and thus avoids creating a .interp section in the first place. This has a bunch of changes to the overall ELF file, however, and I was not confident that the result would be functionally correct for the SGX enclave loader.

I still believe that using -Wl,--shared is probably the more semantically logical approach, but using -Wl,--dynamic-loader, is the approach that has fewer chances of unexpected behaviour changes, hence I picked the latter here.

The enclaves are getting built as ELF executables, and thus the linker
will embed the current ld-linux.so path for the host OS environment
in the binary:

 $ readelf -a libsgx_pce.signed.so | grep interpreter
      [Requesting program interpreter: /nix/store/xmprbk52mlcdsljz66m8yf7cf0xf36n1-glibc-2.38-44/lib/ld-linux-x86-64.so.2]

The SGX enclaves are never loaded using ld-linux.so, as SGX has custom
code for loading enclaves in the required manner.

This embedded ld-linux.so path thus serves no functional purpose, while
also making it harder to do a reproducible build of the enclaves outside
of the NixOS environment.

This patch blanks out the NixOX interpretor path, by setting it to the
empty string.

Fixes: intel#1040
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
@berrange
Copy link
Author

berrange commented Oct 8, 2024

The DCAP counterpart of this is intel/SGXDataCenterAttestationPrimitives#435

@haitaohuang
Copy link
Contributor

I realize we probably do not want to re-sign AEs for this change only if this affects the sigstruct (likely not but did not check)

@berrange
Copy link
Author

I realize we probably do not want to re-sign AEs for this change only if this affects the sigstruct (likely not but did not check)

In Fedora context, I've got a local workaround to do reproducible builds by matching the current nixos path. So I'm fine if this only applies to future AEs, no need to re-sign anything that already exists IMHO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pre-built architectural enclaves contain redundant NixOS ld-linux path
2 participants