Skip to content

vdso: shift time() under time_start on x86_64 - #363

Merged
congwang-mk merged 1 commit into
multikernel:mainfrom
saviourmk:vdso-shift-time
Nov 28, 2026
Merged

congwang-mk merged 1 commit into
multikernel:mainfrom
saviourmk:vdso-shift-time

Conversation

@saviourmk

Copy link
Copy Markdown
Contributor

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.

@congwang-mk
congwang-mk merged commit 7da68ae into multikernel:main Nov 28, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants