mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
util: Make files opened with fdbridge::fopen noninheritable #36677
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36677
Loading…
Reference in a new issue
No description provided.
Delete branch "u/sirecmg/36668-fopen-inheritable-fix"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #36668
Use the 'e' mode on POSIX to set close-on-exec and the 'N' mode on windows to prevent file handle inheritance by child processes.
This PR is still in WIP... until I add some test cases and verify that it works on Windows and Mac. I've only tested it on Linux (OpenSUSE Tumbleweed)
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.
Conflicts
No conflicts as of last run.
Review failed because required verification did not complete.
Earlier concerns remain unresolved; see the full report for their current assessments.
Review coverage was incomplete.
Reviewed:
17ea8dd8185c· Full review report · Previous reportsIs "e" available on all non-Windows systems?
🚧 At least one of the CI tasks failed.
Task
macOS native: https://github.com/bitcoin/bitcoin/actions/runs/40583887664/job/122476509348LLM reason (✨ experimental): CI failed because
fs_tests/fsbridge_fopen_noninheritablefailed its check that the file descriptor has the close-on-exec flag set.Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
Unfortunately, the consecutive
fopenandfcntl(..., FD_CLOEXEC)calls are not atomic, which is a race in a multithreaded process.Could we keep the original
eapproach on Linux and handle macOS separately withopenusingO_CLOEXEC, followed byfdopen?I tested
fsbridge::fopenatca864d2fc1with a standalone MSVC test usingfs.cpp. The file was opened in append mode ("a"), and handle inheritance was enabled inCreateProcessW. After the parent closed the file,DeleteFileWfailed withERROR_SHARING_VIOLATIONon the pre-PR code. With this change, deletion succeeded while the child was still alive.The compilation errors in
fs_tests.cpppreventtest_bitcoinfrom building on Windows.Yes, you are right, I will try to find a solution on how I can make it safe under multi threaded processes.
I changed implementation into three cases
references/docs
linux
windows
UNIX
typos
Thanks @ValeraFinebits. I fixed the typos. Let me know what you think.
Could we also add
<cstring>forstd::strchr?Added the missing include!
could you please squash your commits into two: one for the unit test and one for the fix ?
see: https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits
Tested on Windows at
0c9ab56: the new test passes with the fix and fails on theHANDLE_FLAG_INHERITcheck when I revert the Windows change infs.cpp. Restoring the fix makes it pass again.I performed a squash to clean up the git history, as asked.
seems like this fixes #36668. you can add
Fixes #36668to the PR description to have it auto-close on merge