Skip to content

Bound shared mmap writeback to its valid range - #1695

Open
carlosqwqqwq wants to merge 1 commit into
qilingframework:devfrom
carlosqwqqwq:codex/qiling-d102-munmap-eof
Open

carlosqwqqwq wants to merge 1 commit into
qilingframework:devfrom
carlosqwqqwq:codex/qiling-d102-munmap-eof

Conversation

@carlosqwqqwq

Copy link
Copy Markdown

Checklist

Which kind of PR do you create?

  • This PR only contains minor fixes.
  • This PR contains major feature update.
  • This PR introduces a new function/api for Qiling Framework.

Coding convention?

  • The new code conforms to Qiling Framework naming convention.
  • The imports are arranged properly; no import changes are required.
  • The writeback bounds and zero-length behavior are covered by focused tests.
  • The Linux mmap(2) behavior is referenced below.

Extra tests?

  • No extra tests are needed for this PR.
  • I have added enough tests for this PR.
  • Tests will be added after some discussion and review.

Changelog?

  • This PR doesn't need to update Changelog.
  • Changelog will be updated after some proper review.
  • Changelog has been updated in my PR.

Target branch?

  • The target branch is dev branch.

One last thing

Summary

For file-backed writable MAP_SHARED mappings, munmap() previously read and wrote the full requested length. This could extend a short backing file to the mapping size, including when the guest never touched the mapping, and could read past the mapped range for an overlong unmap request.

The change limits writeback to the requested length, the bytes remaining in the current mapping, and the bytes remaining in the backing file. It skips memory and file I/O when that extent is zero, preserving the partial-page EOF behavior documented by Linux.

Fixes #1694.

Validation

  • cd tests && PYTHONPATH=.. python3 -m unittest test_syscall_munmap_shared_eof — passed.
  • cd tests && PYTHONPATH=.. python3 test_posix.py MunmapSharedEofTests — passed.
  • The regression coverage includes an untouched short file, writes within and beyond EOF, a private-mapping control, and an overlong unmap request.

Reference

@carlosqwqqwq
carlosqwqqwq force-pushed the codex/qiling-d102-munmap-eof branch from f854d5f to 5411bb8 Compare November 23, 2026 19:23
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