Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
proc/linux: Don't open mmapped files before checking stat results (#2002
) Instead of checking the filesystem containing the mapped file against specific magic device numbers, we use stat(2) before actually opening the file. (The open call can block on certain device nodes as reported in #1929.) To overcome the possible TOCTOU issue between stat() and open(), we double-check device, inode after we have opened the file. This also reverts commit 50eeef4. The original problem could also have been fixed by passing O_PATH to open(2). However, there seems to be no way to atomically upgrade those path-only fds to real file descriptors that we can mmap or read from, so this would not helped in overcoming the TOCTOU issue.
- Loading branch information
2967e86
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverity started raising two new warnings, one about the TOCTOU issue, and the other about
fstat
receiving a potentially negativefd
. I copy the whole report here: