Fix integer overflow on guest-derived usize arithmetic#6
Merged
Conversation
… on guest-derived usize values Co-authored-by: CvvT <11675863+CvvT@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix integer overflow vulnerabilities in usize arithmetic
Fix integer overflow on guest-derived usize arithmetic
Feb 23, 2026
CvvT
reviewed
Feb 23, 2026
CvvT
reviewed
Feb 23, 2026
CvvT
reviewed
Feb 23, 2026
CvvT
requested changes
Feb 23, 2026
…ation time Co-authored-by: CvvT <11675863+CvvT@users.noreply.github.com>
CvvT
approved these changes
Feb 23, 2026
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.
Plain
+arithmetic on untrusted guest-providedusizevalues causes debug-mode panics on overflow and silent wrapping in release builds, both of which are exploitable.Changes
msg_handler.rs—get_shm_info_from_optee_msg_param_tmem: replace uncheckedpage_offset + sizewithchecked_add, returningEBadAddron overflow — consistent with the function's existing error-return contract for invalid normal-world input.tmem.sizearrives directly from the untrusted normal world with no prior validation, making this check necessary:process.rs(robust list wake path) was already usingwrapping_addand required no changes.signal/mod.rs(is_on_stackanddeliver_signal) was left unchanged —set_sigaltstackalready validates thatsp + sizecannot overflow viachecked_addbefore storing, so the usage sites are safe.Original prompt
This section details on the original issue you should resolve
<issue_title>Integer overflow vulnerabilities: usize arithmetic on untrusted guest-derived values</issue_title>
<issue_description>## Summary
A scan of the codebase identified several locations where plain
+or-arithmetic is performed onusizevalues derived from untrusted guest input. In debug builds, integer overflows cause panics; in release builds, they silently wrap, potentially producing incorrect pointer values that could be exploited.The safe pattern is to use
.wrapping_add()/.wrapping_sub()instead of+/-on guest-derivedusizevalues.Findings
🔴 HIGH —
litebox_shim_linux/src/syscalls/process.rs(lines 478, 494)Unsafe code:
futex_offsetishead.futex_offset, read directly from the guest-providedRobustListHeadstructure.entryandpendingare guest-controlled pointers from the same structure. A guest can provideentry = usize::MAXandfutex_offset = 1, causing a debug-mode panic on overflow.head_ptr + offset_of!(...)(line 471):head_ptris a guest-provided address passed throughsys_set_robust_list. Althoughoffset_of!(RobustListHead, list) == 0, the addition is still technically unchecked.Suggested fix:
🔴 HIGH —
litebox_shim_optee/src/msg_handler.rs(line 706)Unsafe code:
tmem.sizecomes from the untrusted normal world (viaOpteeMsgParamTmem). Ifsizeis close tousize::MAX, addingpage_offsetoverflows. There is no bounds check onsizebefore this arithmetic.Suggested fix:
Or, better: validate
sizebefore use:🟡 MEDIUM —
litebox_shim_linux/src/syscalls/signal/mod.rs(lines 266, 353)Unsafe code:
SigAltStack::spandSigAltStack::sizeultimately come from the guest viasys_sigaltstack. Theset_sigaltstackfunction validates the sum withchecked_addbefore storing, so the stored values should not overflow in practice. However, these call sites re-perform the addition without wrapping arithmetic. Any future code path that stores aSigAltStackwithout going through the validator would silently introduce a panic.Suggested fix:
Affected Files
litebox_shim_linux/src/syscalls/process.rshead_ptr(fromsys_set_robust_list),entry,pending,futex_offset(fromRobustListHead)litebox_shim_optee/src/msg_handler.rstmem.size(from normal worldOpteeMsgParamTmem)litebox_shim_linux/src/syscalls/signal/mod.rsSigAltStack::sp,SigAltStack::size(fromsys_sigaltstack, validated before storage)References
litebox_shim_linux/src/syscalls/signal/x86.rsandx86_64.rsusewrapping_sub/wrapping_addconsistently for allframe_addrarithmetic.set_sigaltstackalready useschecked_addfor validation — a good pattern to apply at the arithmetic sites too.Comments on the Issue (you are @copilot in this section)
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.