linux-user/main: Check errno when getting AT_EXECFD

It's possible for AT_EXECFD to end up with a valid value of 0. Check
errno when using qemu_getauxval instead of return value to handle this
case.

Not handling this case leads to a confusing condition where the
executable ends up as fd 0, i.e. stdin.

Signed-off-by: Vivian Wang <uwu@dram.page>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Fixes: 0b959cf5e4 ("linux-user: Use qemu_getauxval for AT_EXECFD")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2448
Message-ID: <20240723100545.405476-3-uwu@dram.page>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Vivian Wang 2024-07-23 18:05:45 +08:00 committed by Richard Henderson
parent 22531d8cc5
commit 25268a1855

View File

@ -755,8 +755,9 @@ int main(int argc, char **argv, char **envp)
/* /*
* Manage binfmt-misc open-binary flag * Manage binfmt-misc open-binary flag
*/ */
errno = 0;
execfd = qemu_getauxval(AT_EXECFD); execfd = qemu_getauxval(AT_EXECFD);
if (execfd == 0) { if (errno != 0) {
execfd = open(exec_path, O_RDONLY); execfd = open(exec_path, O_RDONLY);
if (execfd < 0) { if (execfd < 0) {
printf("Error while loading %s: %s\n", exec_path, strerror(errno)); printf("Error while loading %s: %s\n", exec_path, strerror(errno));