Repository navigation
vdso: shift time() under time_start on x86_64 - #363
Merged
Merged
Conversation
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.
On x86_64 the vDSO exports time() next to clock_gettime and gettimeofday, and glibc's time() goes through it. patch() replaced it with a plain syscall stub even when a time offset was set, and the time syscall itself isn't intercepted, so time(NULL) kept returning the host clock while date and clock_gettime reported the shifted one. Python's time.gmtime() with no argument reads the clock that way, as does any C code that calls time().
I added an offset stub for time that runs the real syscall, adds the offset to the result and stores it through tloc when tloc is non-NULL. It is 29 bytes, which fits inside __vdso_time on the 7.0 kernel I tested on (41 bytes there). arm64 and riscv64 have no vDSO time and glibc goes through clock_gettime there, so nothing changes for them.
Tested with a unit test that executes the stub (returned and stored values both shifted, NULL tloc handled) and an integration test that checks libc time() and time.gmtime() report 2000 under a 2000 start time. That test fails on main with 2026 and passes with the change. I also ran cargo test -p sandlock-core --lib vdso:: and the test_determinism integration tests.