Skip to content

Conversation

@roypat
Copy link
Member

@roypat roypat commented Mar 21, 2025

When mmap-ing a file-like object, vm-memory was trying to validate the
the range [offset, offset+len) was valid in the file. However, our
homegrown check had lots of edge cases where it gave false-positives
(e.g. it rejected things that should really be working, such as vfio
devices, or fds that cannot be seeked like guest_memfd), and trying to
implement a check that works for all of these is in the end wasted
effort anyway, because the kernel validates all this as part of the mmap
syscall anyway. So just drop these checks in favor of failing at
mmap-time.

See also #195 (comment)

Summary of the PR

Please summarize here why the changes in this PR are needed.

Requirements

Before submitting your PR, please make sure you addressed the following
requirements:

  • All commits in this PR have Signed-Off-By trailers (with
    git commit -s), and the commit message has max 60 characters for the
    summary and max 75 characters for each description line.
  • All added/changed functionality has a corresponding unit/integration
    test.
  • All added/changed public-facing functionality has entries in the "Upcoming
    Release" section of CHANGELOG.md (if no such section exists, please create one).
  • Any newly added unsafe code is properly documented.

@roypat roypat force-pushed the stat-instead-of-seek branch 3 times, most recently from db86b91 to cbced4a Compare March 21, 2025 10:40
ShadowCurse
ShadowCurse previously approved these changes Mar 24, 2025
@roypat roypat force-pushed the stat-instead-of-seek branch 2 times, most recently from 1ba4642 to d97d9cd Compare March 26, 2025 15:23
@roypat roypat changed the title Allow constructing MmapRegions for non-seekable fds mmap: drop file-offset checking, defer to mmap(2) instead Mar 26, 2025
@roypat roypat force-pushed the stat-instead-of-seek branch 2 times, most recently from 006c987 to 55dafa9 Compare March 26, 2025 15:51
roypat added a commit to roypat/firecracker that referenced this pull request Apr 2, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Apr 2, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Apr 3, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Apr 3, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Apr 7, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Apr 7, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Apr 7, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Apr 7, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Apr 8, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Apr 8, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Apr 8, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Apr 8, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Apr 8, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Apr 9, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Apr 9, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Apr 9, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to firecracker-microvm/firecracker that referenced this pull request Apr 9, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Apr 25, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Apr 25, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Apr 25, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request May 7, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to firecracker-microvm/firecracker that referenced this pull request May 21, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
@roypat roypat requested a review from rbradford May 22, 2025 12:19
@roypat roypat merged commit b2eaf98 into rust-vmm:main May 22, 2025
2 checks passed
roypat added a commit to roypat/firecracker that referenced this pull request Jun 26, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Jun 26, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Jul 16, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Aug 1, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
@uran0sH uran0sH mentioned this pull request Aug 7, 2025
roypat added a commit to roypat/firecracker that referenced this pull request Aug 13, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Aug 13, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Aug 14, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Aug 14, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Aug 14, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Aug 14, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Aug 14, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Sep 3, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
roypat added a commit to roypat/firecracker that referenced this pull request Sep 8, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
@bonzini bonzini added this to the vm-memory 0.17.0 milestone Sep 8, 2025
roypat added a commit to roypat/firecracker that referenced this pull request Sep 9, 2025
vm-memory has faulty validation logic that prevents us from mmap-ing
guest_memfds, so just bypass that by calling mmap ourselves for the time
being.

See also rust-vmm/vm-memory#320

Signed-off-by: Patrick Roy <[email protected]>
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.

4 participants