Repository navigation
Zero the OVERLAPPED passed to LockFileEx in windows_named_sync - #286
Open
juanlofer-eprosima wants to merge 1 commit into
Open
juanlofer-eprosima wants to merge 1 commit into
juanlofer-eprosima wants to merge 1 commit into
Conversation
Signed-off-by: Juan Lopez Fernandez <juanlopez@eprosima.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
windows_named_sync::open_or_create()andwindows_named_sync::close()pass an uninitializedwinapi::interprocess_overlappedtoLockFileEx(andopen_or_create()also toUnlockFileEx).LockFileExtakes the start of the range to lock fromOffset/OffsetHigh, and its documentation requireshEventto be zero or a valid handle. So the byte that gets locked is whatever was left on the stack. This has been the case sincewindows_named_syncwas added (Boost 1.50), and it still is in the latest releases anddevelopbranch.Effect
The lock is meant to make processes take turns while they set up or read the file behind a named object. That file holds the id that names the native object, and the counts that
named_semaphoreandnamed_condition_anywrite inclose()and read back inopen_or_create(). With an arbitrary start, two processes can lock different bytes, and then they don't wait for each other. From reading the code (not reproduced): two processes creating the same object at the same time could both find the file empty, write different ids, and end up using different native objects for the same name.How we found it
We hit this bug in one of our products testing suite, which still uses Boost 1.67 (the lock covered
sizeof_file_infobytes instead of 1);Offset/OffsetHighheld0xFFFFFFFFFFFFFFFF, so the range ran past 2^64,LockFileExfailed withERROR_INVALID_LOCK_RANGE, and thenamed_mutexconstructor threw. Zeroing the structure fixed it. Since 1.77 the range is 1 byte long and can't overflow (we measured thatLockFileExaccepts a range ending exactly at 2^64), so that error no longer shows, but the locked byte is still arbitrary.🤖 Generated with Claude Code