Avoid repeating original argv[0]#7
Conversation
resolves AsahiLinux#6 binfmt-dispatcher gets typically registered to binfmt-misc with flags `POCF`. - `P` will preserve the original argv[0] used - `O` will give the resolved binary (e.g. after symlink derefence) as an open file in fd 3 - but we can't use it as-is as FEX (at least) doesn't support taking "pathname" (execve) as an open file descriptor. - `C` and `F` are irrelevant here. To support properly binary file already open as fd 3, FEX needs to be patched to use `fexecve(3, argv, env)` kind of call when requested, it doesn't appear to support it yet. Signed-off-by: Fabrice A. Marie <fabrice@evren.co>
91ccc2e to
7345eec
Compare
GnomedDev
left a comment
There was a problem hiding this comment.
I have an x64 Rust binary which prints std::env::args().collect::<Vec<String>>() which previously resulted in
gnome@daisy-macbookpro:~/Coding/Personal/temp$ ./target/x86_64-unknown-linux-musl/debug/temp foo bar
[binfmt_dispatcher] Using FEX with muvm
Failed to set the new pressure in the guest: could not connect to muvm server: No such file or directory (os error 2)
No IPv6 nameserver available for NDP/DHCPv6
Using default interface naming scheme 'v257'.
["/home/gnome/Coding/Personal/temp/target/x86_64-unknown-linux-musl/debug/temp", "./target/x86_64-unknown-linux-musl/debug/temp", "./target/x86_64-unknown-linux-musl/debug/temp", "foo", "bar"]
(mangled args, but executes the binary)
I have attempted testing this patch by building this branch and replacing /usr/bin/binfmt-dispatcher (and fixing the SELinux junk), and now I get the following error when executing the same binary.
gnome@daisy-macbookpro:~/Coding/Personal/temp$ ./target/x86_64-unknown-linux-musl/debug/temp foo bar
[binfmt_dispatcher] Using FEX with muvm
Failed to set the new pressure in the guest: could not connect to muvm server: No such file or directory (os error 2)
No IPv6 nameserver available for NDP/DHCPv6
Using default interface naming scheme 'v257'.
./target/x86_64-unknown-linux-musl/debug/temp: command not found
"/usr/bin/FEXInterpreter" process exited with status code: 248
(cannot execute the binary anymore)
muvm does not preserve cwd. AsahiLinux/muvm@1edd91d |
|
Before: After: Thanks for your patch! Leslie Zhai |
| } | ||
|
|
||
| // File descriptor 3 is where binfmt_misc typically passes the executable | ||
| let binary: PathBuf = read_link("/proc/self/fd/3").unwrap_or_else(|e| { |
There was a problem hiding this comment.
warning: unused import: `read_link`
--> src/main.rs:12:29
|
12 | use std::fs::{canonicalize, read_link};
| ^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: unused import: `PathBuf`
--> src/main.rs:15:23
|
15 | use std::path::{Path, PathBuf};
| ^^^^^^^
warning: `binfmt-dispatcher` (bin "binfmt-dispatcher") generated 2 warnings (run `cargo fix --bin "binfmt-dispatcher"` to apply 2 suggestions)
|
Hi! Can somebody summarize the situation here? From what I can see, binfmt-dispatcher in Fedora is completely broken because of the binary being passed as the value of the first argument? |
|
Let's try to summon the maintainer... /cc @davide125 🙇 |
|
I'm aware of this. It's pending finding the time to put together a testing setup, which will hopefully happen sometime later next month. |
|
Hey, any updates @davide125? |
resolves #6
binfmt-dispatcher gets typically registered to binfmt-misc with flags
POCF.Pwill preserve the original argv[0] usedOwill give the resolved binary (e.g. after symlink derefence) as an open file in fd 3CandFare irrelevant here.To support properly binary file already open as fd 3, FEX needs to be patched to use
fexecve(3, argv, env)kind of call when requested, it doesn't appear to support it yet.Signed-off-by: Fabrice A. Marie fabrice@evren.co