mirror of
https://github.com/FEX-Emu/FEX.git
synced 2025-02-10 00:55:55 +00:00
![Ryan Houdek](/assets/img/avatar_default.png)
This lets us support the final two flags in binfmt_misc that we needed. 1) Support open_binary 2) Support preserve 1) We already supported the credentials flag, which implied open_binary, but we weren't handling half of it. With the open_binary flag, the Linux kernel passes us the executable in an FD instead of as a pathname. This can be found inside of auxv on startup, inside of AT_EXECFD. If AT_EXECFD is available then we prioritize using that instead of the pathname passed in. This fixes a potential permissions issue where an executable is executed without read permissions. 2) The preserve flag has the Linux kernel preserve the original argv[0] that was passed to the application. Prior to supporting this flag, the kernel would provide us with a resolved program path. This can happen in the instance where something like `blah` resolves to `/usr/loca/bin/blah` which isn't what the user originally typed. This works around this problem by handing the interpreter both the resolved path and the original typed path. Alongside open_binary, we can just use the FD passed in instead of the resolved path, this means we can just drop the argv[0] for the guest (which is the kernel resolved path) and pass through arguments unmangled. We do have to make a minor assumption here that if we are using EXECFD that we assume preserve. It isn't until kernel v5.12 that we can actually check AT_FLAGS to see if that was true.