-
Notifications
You must be signed in to change notification settings - Fork 860
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
AUXV parameter AT_EXECFN returns argv[0] instead of filename passed to execve #2133
Comments
As it is weekend, I have some time to do more tests. I modified my "launcher.c" a little bit to pass an empty argv array (argv[0] == NULL)
I also simplified multi_command.c to focus on the essentials
WSL:
;-) Real Ubuntu 16.04:
Seems that WSL's AT_EXECFN points to the process enviroment if argv[0] is NULL as printenv returns this
Interesting strategy to use envp[0] if argv[0] is NULL. |
@christoh - I don't understand this iusse and background, but... saw what might be interesting. This is same what you show;
But... this is... more strange;
|
@sunjoong Before running ./launcher ./multi_command run printenv If my findings are correct, AT_EXECFN always gives you the first line of what printenv says. If you run source /etc/profile, your order of enviroment variables may change and thus AT_EXECFN returns something different. The same applies if you precede a command with LD_SHOW_AUXV=1. This will then be the topmost entry in your environment and thus is returned by getauxval(AT_EXECFN) While your output differs from mine, it strongly supports my theory that envp[0] is used if argv[0] is NULL |
The next question that comes up is: What happens if envp[0] is also NULL. launcher.c
multi_command.c
Output:
If both argv[0] and envp[0] are NULL, AT_EXECFN actually becomes an alias to AT_PLATFORM. At least it doesn't destroy AT_PLATFORM. Same applies if envp itself is NULL. It seems that in the Elf64_auxv_t struct WSL updates a_type but leaves a_un.a_val unchanged from the previous value if a NULL pointer is encountered while filling the AUXV. This might be another bug unrelated to the original one. |
@christoh - Some differences between your previous code and present..... In present;
In previous;
There were two AT_EXECFN, ./launcher and LD_SHOW_AUXV=1, in previous, but only one in present. |
@sunjoong |
@christoh - Thanks :) |
I'll take a look at this while I'm looking at #2031 since it's the same code that sets all this up. |
I've identified the causes of all of the issues above and will be fixing this soon. To summarize:
|
Fixed in 16257. |
Tested with 16257. Everything is as expected and the same as under native Linux |
Your Windows build number: 16199
What you're doing and what's happening:
I have the following multi-command (multi-call) binary "multi_command.c" (one binary that features many commands like e.g. busybox does):
I use AT_EXECFN in the aux vector because argv[0] is unreliable (argv[0] is just another argument like argv[1] to argv[argc-1]) . You cannot expect that every launcher sets it like a standard shell.
Now I launch this program with this "launcher.c" that sets some custom argv[0] like many programs do ( e.g. /etc/inetd.conf requires argv[0] specified explicitly)
The result on real Ubuntu 16.04 is:
AT_EXECFN always contains the filename exactly as passed to the first argument of the execve syscall. The "p variants" (user mode stuff in glibc) of the exec family of functions modify the filename argument before actually syscalling execve.
WSLs implementation incorrectly uses argv[0] instead.
<cmd>
is failing, then runstrace -o strace.txt -ff <cmd>
, and post the strace.txt output here)Won't help very much because getauxval is a glibc user mode function that searches the AUXV in the current process memory without involving a kernel call. But just for completeness.
Real Ubuntu 16.04:
WSL:
The text was updated successfully, but these errors were encountered: