O_CLOEXEC not handled in dup3 system call in user mode
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
QEMU |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
In qemu user mode, for hppa and sparc64 targets, the parameter of the dup3 is not passed correctly when it contains the O_CLOEXEC flag.
When the attached program runs, the expected output is:
errno=9=EBADF
How to reproduce on hppa:
- Compile the program: hppa-linux-
- Set environment variables for running qemu-hppa.
- ~/inst-
errno=22=EINVAL
testdup3.c:54: assertion 'errno == EBADF' failed
How to reproduce on sparc64:
- Compile the program: sparc64-
- Set environment variables for running qemu-sparc64.
- ~/inst-
errno=22=EINVAL
testdup3.c:54: assertion 'errno == EBADF' failed
I see this bug for hppa, sparc64.
I don't see it for m68k, mips, mips64, powerpc, powerpc64.
Most likely because the binary values of O_CLOEXEC on hppa and sparc64 are different than on other platforms. Looking in the glibc source code:
$ grep -r 'define.*O_CLOEXEC' glibc fcntl.h: # define O_CLOEXEC 0x00400000 /* Set close_on_exec. */ mach/hurd/ bits/fcntl. h:# define O_CLOEXEC 0x00400000 /* Set FD_CLOEXEC. */ unix/sysv/ linux/sparc/ bits/fcntl. h:#define __O_CLOEXEC 0x400000 /* Set close_on_exit. */ unix/sysv/ linux/bits/ fcntl-linux. h:# define __O_CLOEXEC 02000000 unix/sysv/ linux/bits/ fcntl-linux. h:# define O_CLOEXEC __O_CLOEXEC /* Set close_on_exec. */ unix/sysv/ linux/hppa/ bits/fcntl. h:#define __O_CLOEXEC 010000000 /* Set close_on_exec. */ unix/sysv/ linux/microblaz e/bits/ fcntl.h: #define __O_CLOEXEC 02000000 /* Set close_on_exec. */ unix/sysv/ linux/alpha/ bits/fcntl. h:#define __O_CLOEXEC 010000000 /* Set close_on_exec. */ nacl/bits/ fcntl.h: # define O_CLOEXEC 02000000 /* Set close_on_exec. */
glibc/bits/
glibc/sysdeps/
glibc/sysdeps/
glibc/sysdeps/
glibc/sysdeps/
glibc/sysdeps/
glibc/sysdeps/
glibc/sysdeps/
glibc/sysdeps/
So, what's missing is probably that the O_CLOEXEC of the target platform gets mapped to O_CLOEXEC of the host platform, during the dup3 system call emulation.