Repository navigation
fix(libc): copy mktime's and timelocal's struct tm through checked guest copies - #22929
Conversation
…est copies mktime read the caller's struct tm and wrote the normalized result through the guest pointer, and timelocal stored tm_isdst through it, so a null, unmapped or read-only struct tm crashed the host. The struct is now copied in with one GuestCopyIn_nid_no_patch, and the result, like timelocal's tm_isdst = -1, is written with GuestCopyOut_nid_no_patch. A struct tm that is null or can't be read or written returns -1 with errno set to EFAULT, as time does for an output it can't write. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against c69358e916:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_mktime_testsbuilt cleanly. - CTest (
guest_mktime):1/1 Test #1088: guest_mktime ..................... Passed 0.09 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libc/src/Time.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #1088: guest_mktime .....................***Exception: SegFault 0.77 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Verified core/libs/prx/libc/src/Time.cpp libc_mktime_nid_postfix correctly guards against nullptr and unmapped guest memory using GuestCopyIn_nid_no_patch and sets errno to EFAULT on failure
- Verified both the #if defined(_WIN32) || defined(APPLE) and Linux fallback return paths write back normalized GuestTm using GuestCopyOut_nid_no_patch with EFAULT on failure
- Verified timelocal_nid_postfix writes tm_isdst = -1 via GuestCopyOut_nid_no_patch before forwarding to libc_mktime_nid_postfix, properly returning -1 and setting errno to EFAULT if the write fails
- Verified docs/dev/debt/changes/fix-libc-mktime-guest-copies.md follows TechnicalDebt fragment conventions and AGENTS.md rules
- Verified test coverage in core/libs/tests/GuestMktime.cpp exercises nullptr, unmapped address 0x10, and subsequent valid normalization for libc_mktime, mktime, and timelocal
Looks Good To Me
|
Tested head Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release,
Whole batch: the full This is one combined tree, not a run of this PR alone. AI-assisted: yes (Claude Code) |
|
Thanks @kiwe147 for including this one in the batch. The |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
The checked guest copies protect mktime and timelocal from inaccessible struct tm pointers, and the reviewed changes show no verified blocking defect.
What I ran
Reviewed head c69358e9163b6aff40cb653ed65b8d793a7a6400. I read the prepared description, commit summary, manifest, diff, and all three changed files, then inspected the changed implementation and searched existing guest-copy usage. I did not run commands or tests; reported test results below are author-reported.
Results
| Check | Result | Note |
|---|---|---|
| Changed-file review | passed | All three changed files read |
| Guest-copy call sites | passed | Existing uses found |
| Test execution | not run | Runs described by author only |
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not independently run the Windows or Linux tests, reproduce the negative controls, or validate the combined-tree merge claim. No files were excluded: all files listed in the manifest were included and read.
To get this to a good state
Nothing is required.
What
mktime(libc_mktimeand itsmktimealias) read the caller'sstruct tmthrough the guest pointer and wrote the normalized result back through it, on both the Windows/macOS path and the common one.timelocalstoredtm_isdst = -1through it before callingmktime. A null, unmapped or read-onlystruct tmcrashed the host.Changes:
mktimecopies thestruct tmin with oneGuestCopyIn_nid_no_patchand writes the normalized result with oneGuestCopyOut_nid_no_patchon each of its two paths.timelocalwrites itstm_isdst = -1withGuestCopyOut_nid_no_patch.struct tmthat is null or can't be read or written returns -1 witherrnoset toEFAULT, astimein the same file does for an output it can't write. FreeBSD dereferences the pointer, so this is a host-safety fallback.Results for valid pointers are unchanged.
Tested
Windows 11 VM (GeForce GT 1030, WinLibs GCC 16.2.0 POSIX UCRT, Ninja, Release), which takes the Windows path of
mktime:guest_mktimegainsCheckUnmappedTime. Forlibc_mktime,mktimeandtimelocal, an unmapped (0x10) and a nullstruct tmreturn -1 withEFAULT. A valid conversion afterwards still normalizes.guest_mktimepasses, 3 runs, on9d1aad7bfd.mainwith only the new test (e95c8acc0a) endsguest_mktimein an access violation (0xc0000005).git merge-treeagainstmainis clean. fix(libc): write a 36-byte struct tm as the console does #10409 (Time.cppand this test file) and feat(libc): add the std::__sce_v2 thread start, timed wait, clock and processor count calls #9447 (Time.cpp) also edit these files; both already conflict withmainon their own.tools/check_conventions.pypasses on the branch and this body.tools/debt_fold.py --checkreports nothing for this fragment.Linux (Ubuntu 26.04.1, kernel 7.0), GCC 15.2, Ninja, Release,
-DBUILD_TESTING=ON:guest_mktimepasses, 3 runs, onc69358e916(this PR's head).main's source file endsguest_mktimein SIGSEGV at address0x38.c69358e916, applied with other PRs ontomainfd4aeed483(one combined tree, not this PR alone), Windows 11, WinLibs GCC 15.2.0 r7, Release, no validation layer:guest_mktimepass on an NVIDIA GeForce RTX 3080 (driver 621.24).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)