If renderer dies while this function is being executed, the socket will be invalidated and at the attempt of closing it when going out of the scope (note the |fds| vector of scoped FDs), close() will fail with EBADF errno and the described check will hit and crash browser process. However, according to my understanding, this does not have a security implication in this case.
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
Absolutely not. If close() can fail with EBADF, it means the file descriptor was available for reuse. If it was reused, ScopedFD would close an unrelated object upon going out of scope. This sort of bug is especially difficult to track down. Failing on EBADF provides an opportunity to catch the problem when the stars align such that the file descriptor isn't reused.
Receiving EBADF at close() means that you thought you owned a file descriptor but actually didn't. This indicates a serious problem. We do want this to be fatal.
If some other operation closes a file descriptor, we need to be aware of it. We have to avoid the double-close().
--
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
Have you observed the problem you describe? I'm not very familiar with recvmsg's fd-passing API, but that seems fishy. fd tables are local to a process, so if the kernel gives you fd numbers, they should presumably be in your fd table. If the process that sent them to you then crashes, your fd table entries should still remain.
--
In particular, this means, on Linux "IGNORE_EINTR(close(fd))" is actually a dangerous bug. If it ever loops, it is possible the code ends up closing an unrelated file descriptor that had just been opened in a separate thread!
Furthermore, I vaguely recall that Linux uses close()'s exit code to report on things such as errors resulting from delayed allocation. In other words, write() could return success but not actually flush the data to disk. When close() is called a little while later, data gets flushed and now triggers an error, because the file system filled up in the meantime.
This seem to be related to crbug.com/507529 which is about a crash
when plugging and unplugging a USB device.
You guys said that dangerous to close an invalid fd. I don't have much
expertise here, but IIUC in case of an unplugged USB device, we may
end up on an invalid fd. It would be reasonable that it returns EIO.
In such case should we confirm that the error is actually EBADF? The
Markus's suggestion sounds like a good candidate: PCHECK(0 ==
close(fd) || errno != EBADF);