-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set mmapped files as readonly to prevent other processes from modifying it by accident #137025
base: master
Are you sure you want to change the base?
Conversation
@bors try @rust-timer queue |
r? @fee1-dead rustbot has assigned @fee1-dead. Use |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
Lock mmapped files to at least get some safety out of it Unfortunately this only is a guarantee on windows. Double-unfortunately I don't know what's gonna happen when rustc segfaults on windows and a file is locked. Possibly the file is now deadlocked. Linux just locks file as a hint, so only tools that know about file locking will actually respect it, others will just access it. I guess if we had some sort of story for volatile memory we could use that as we're only reading bytes out of it and not actually mapping data structures to that memory.
This comment has been minimized.
This comment has been minimized.
Though I would also add:
|
💔 Test failed - checks-actions |
This comment has been minimized.
This comment has been minimized.
Some changes occurred in compiler/rustc_codegen_gcc |
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
Lock mmapped files to at least get some safety out of it Unfortunately this only is a guarantee on windows. Double-unfortunately I don't know what's gonna happen when rustc segfaults on windows and a file is locked. Possibly the file is now deadlocked. Linux just locks file as a hint, so only tools that know about file locking will actually respect it, others will just access it. I guess if we had some sort of story for volatile memory we could use that as we're only reading bytes out of it and not actually mapping data structures to that memory.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
The files we mmap are write-once. So couldn't we set them to readonly after creating them? That should be at least as good as locking since making them writable again would require another program going out of its way to bypass this, which isn't the case with advisory locks. |
☔ The latest upstream changes (presumably #137046) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment has been minimized.
This comment has been minimized.
Some changes occurred in compiler/rustc_codegen_ssa |
The job Click to see the possible cause of the failure (guessed by this bot)
|
/// The given file must not be mutated (i.e., not written, not truncated, ...) until the mapping is closed. | ||
/// | ||
/// However in practice most callers do not ensure this, so uses of this function are likely unsound. | ||
/// This process must not modify nor remove the backing file while the memory map lives. |
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.
Why would removing the file be a problem? Mappings should say valid for unlinked files... unless network filesystems are involved I guess...
/// Someone may truncate our file, but then we'll SIGBUS, which is not great, but at least | ||
/// we won't succeed with corrupted data. | ||
/// | ||
/// To get a bit more hardening out of this we will set the file as readonly before opening it. |
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.
can't we immediately set it to readonly after initial creation? The writing process can have an FD with write permission and then make the file readonly that other processes can't open it for writing.
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.
Hmm. That disconnects the read only setting from the mmap. I guess I could check I'd it's already read only
Btw, |
I think the linux CI containers run as root, so we probably should drop |
Unfortunately this only is a guarantee on windows.
Double-unfortunately I don't know what's gonna happen when rustc segfaults on windows and a file is locked. Possibly the file is now deadlocked.
Linux just locks file as a hint, so only tools that know about file locking will actually respect it, others will just access it.
I guess if we had some sort of story for volatile memory we could use that as we're only reading bytes out of it and not actually mapping data structures to that memory.