Skip to content

Fix correctness bugs with overflow guards#48

Merged
jserv merged 1 commit intomainfrom
correctness
Apr 4, 2026
Merged

Fix correctness bugs with overflow guards#48
jserv merged 1 commit intomainfrom
correctness

Conversation

@jserv
Copy link
Copy Markdown
Contributor

@jserv jserv commented Apr 4, 2026

The following correctness bugs fixed with unit test coverage:

  • sendfile: loop writes until all read bytes are drained to destination, guard zero-progress (wr==0) with EIO, track partial writes via goto
  • ELF PT_INTERP: reject (return -1) instead of truncating when segment overflows buf_len, NUL terminator is missing, path exceeds output buffer, or interpreter string is empty
  • I/O pointer arithmetic: add __builtin_add_overflow guards on all 10 sites across read, pread, write, pwrite, sendfile, readv/writev, and shadow-read paths to prevent guest-controlled address wrap
  • procmem: split process_vm_readv n<=0 into n<0 (-errno) and n==0 (-EFAULT) to eliminate stale errno; guard remote_addr+total overflow

Change-Id: Iac51bf55d02e02e6b0eb4b35ecf5c22b989d5234


Summary by cubic

Fixes multiple correctness bugs in I/O and ELF parsing with overflow guards and stricter errors to prevent address wrap, silent truncation, and stale errno. Expands tests for sendfile, PT_INTERP, and procmem to lock in behavior.

  • Bug Fixes
    • Added __builtin_add_overflow guards across read/pread/write/pwrite/readv/writev/sendfile and shadow-read paths; return EFAULT/EOVERFLOW on overflow.
    • sendfile now loops on short writes for both LKL and host FDs; wr<=0 is EIO on zero progress; tracks partial writes; guards read/offset arithmetic; offset writeback is best-effort.
    • Read/write forwarding rejects remote address overflow before guest_mem_read/write; propagate first error if no bytes were transferred.
    • ELF PT_INTERP: reject when segment exceeds buffer, missing NUL, empty string, or path doesn’t fit output; stop truncating and return -1.
    • procmem: split process_vm_readv results into n<0 → -errno and n==0 → -EFAULT; guard remote_addr + total overflow.

Written for commit 0000256. Summary will update on new commits.

cubic-dev-ai[bot]

This comment was marked as resolved.

The following correctness bugs fixed with unit test coverage:
- sendfile: loop writes until all read bytes are drained to destination,
  guard zero-progress (wr==0) with EIO, track partial writes via goto
- ELF PT_INTERP: reject (return -1) instead of truncating when segment
  overflows buf_len, NUL terminator is missing, path exceeds output
  buffer, or interpreter string is empty
- I/O pointer arithmetic: add __builtin_add_overflow guards on all 10
  sites across read, pread, write, pwrite, sendfile, readv/writev, and
  shadow-read paths to prevent guest-controlled address wrap
- procmem: split process_vm_readv n<=0 into n<0 (-errno) and n==0
  (-EFAULT) to eliminate stale errno; guard remote_addr+total overflow

Change-Id: Iac51bf55d02e02e6b0eb4b35ecf5c22b989d5234
@jserv jserv merged commit fa29f7a into main Apr 4, 2026
5 checks passed
@jserv jserv deleted the correctness branch April 4, 2026 04:13
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.

1 participant