open() with O_CLOEXEC returns an error
- Found in: 1.19
Partial fix in 859
CategoryPostponed (awaiting complete fix)
The O_CLOEXEC flag for open() was introduced in glibc 2.7 and in some Linux 2.6.x version. Plash does not support it yet. The flag will be rejected by either FsOp (in the fsop_open method) or FsObjReal (in the file_open method).
glibc has started using this flag internally. The functions for reading /etc/passwd and /etc/group use this flag. glibc has introduced a flag for fdopen() which is translated into O_CLOEXEC.
To reproduce:
$ pola-run -fw / --log -e id ... #1: [r!] open: /etc/passwd, flags=0o2000000, mode=0o0: fail: Invalid argument #1: [r!] open: /etc/group, flags=0o2000000, mode=0o0: fail: Invalid argument ... uid=1000 gid=1000
The expected output would include the user and group names; for example:
uid=1000(mrs) gid=1000(mrs)
Thomas Leonard reported this problem; see mailing list post.
Currently this problem does not appear to be serious, because only glibc has been observed to use this flag, and only for /etc/passwd, which is only used to map UIDs to user names, and it fails gracefully. But in time, we can expect other programs to use this flag.
Questions
Does glibc have test cases covering this flag?
Does glibc make open() test for kernel support for O_CLOEXEC and fall back to fcntl() when the flag is unavailable?
Tasks
Although this flag is rejected by FsObjReal, which rejects any flag it doesn't recognise, the problem can't be fixed there because it is in the wrong process. The FD_CLOEXEC flag applies to the file descriptor table slot, not the FD itself.
- All calls to recvmsg() in the comms layer should use O_CLOEXEC (or its equivalent)
open() in PlashGlibc should unset FD_CLOEXEC if O_CLOEXEC was not used
Partial fix
Linux's open() syscall ignores flags that it does not recognise, so older versions that do not support O_CLOEXEC do not return an error. This means a simple fix is to not return an error when open() is passed the O_CLOEXEC flag. I am reluctant to ignore other unknown flags.
