https://bugzilla.redhat.com/show_bug.cgi?id=1254033
Bug ID: 1254033
Summary: Chapter 9.2 advice on using /proc/self/fd to close
file descriptors before execve is dangerously wrong
Product: Fedora Documentation
Version: devel
Component: defensive-coding-guide
Assignee: fweimer(a)redhat.com
Reporter: sstewartgallus00(a)mylangara.bc.ca
QA Contact: docs-qa(a)lists.fedoraproject.org
CC: fweimer(a)redhat.com
Description of problem:
The documentation advises to open /proc/self/fd after forking and close the
file descriptor entries found in there before calling execve. However, in a
multi-threaded environment many memory allocators may deadlock after fork
(opendir, and readdir may allocate memory.) As well, most commonly programmers
implement this by looping over /proc/self/fd while closing file descriptors
which is unsafe because it is like looping over a list while removing entries
from it at the same time. Instead, one should set the close on execute bit on
these file descriptors when looping over the directory entries (probably using
the FIONCLEX ioctl for speed.)
--
You are receiving this mail because:
You are the QA Contact for the bug.