-
Notifications
You must be signed in to change notification settings - Fork 130
Description
Tested on 2.6.39 UEK kernel on Oracle Linux 6 x86_64
Process::uid() generates Bad file descriptor. This is due to OFlags::PATH beeing used to open the /proc/<id> directory:
procfs/procfs/src/process/mod.rs
Lines 149 to 152 in 86e5ba0
| rustix::fs::openat( | |
| dirfd, | |
| p, | |
| OFlags::NOFOLLOW | OFlags::PATH | OFlags::CLOEXEC, |
procfs/procfs/src/process/mod.rs
Lines 221 to 224 in 86e5ba0
| rustix::fs::openat( | |
| rustix::fs::cwd(), | |
| &root, | |
| OFlags::PATH | OFlags::DIRECTORY | OFlags::CLOEXEC, |
This flag does not give access to some syscall (fstat in this case).
From the manpage (https://man7.org/linux/man-pages/man2/open.2.html):
O_PATH (since Linux 2.6.39)
[...]
other file operations read, write, fchmod, fchown, fgetxattr, ioctl, mmap fail with the
error EBADF.
The following operations can be performed on the resulting
file descriptor:
* [fstat(2)](https://man7.org/linux/man-pages/man2/fstat.2.html) (since Linux 3.6).
* [fstatfs(2)](https://man7.org/linux/man-pages/man2/fstatfs.2.html) (since Linux 3.12).
So for kernels >= 2.6.39 but < 3.6, we should not set the OFlags::PATH flag.
For kernels < 2.6.39, the flag seems to be ignored, so we can keep it.
For kernels >= 3.6, the flag gives better performance, so we should keep it
Can we add a simple if kernel >= 3.6 { flags |= OFlags::PATH }? Or is there a better way to do it?
I don't know if this should be a compile-time check, or runtime. I would personally prefer a runtime check because I reuse a single binary over multiple server, but that's just my personal use-case.