Repository navigation
Enforce guest RLIMIT_AS and RLIMIT_DATA #485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -292,6 +292,10 @@ typedef struct { | |
| */ | ||
| uint64_t overlay_end; /* Host-page-aligned overlay end (exclusive). */ | ||
| char name[64]; /* Label: "[heap]", "[stack]", ELF path, etc. */ | ||
| uint64_t shm_attach; /* Nonzero for a SysV shm attach: a serial unique | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 5c25e3c: |
||
| * to that attach, so the region never merges with | ||
| * or lends its vma_id to any other mapping. | ||
| */ | ||
| } guest_region_t; | ||
|
|
||
| /* TLB invalidation request kinds. After every page-table modification, the shim | ||
|
|
@@ -540,8 +544,9 @@ typedef struct { | |
|
|
||
| /* Semantic region tracking for munmap/mprotect/proc-self-maps */ | ||
| guest_region_t regions[GUEST_MAX_REGIONS]; | ||
| int nregions; /* Number of active regions */ | ||
| uint64_t next_vma_id; /* Last logical-VMA lineage ID allocated. */ | ||
| int nregions; /* Number of active regions */ | ||
| uint64_t next_vma_id; /* Last logical-VMA lineage ID allocated. */ | ||
| uint64_t next_shm_attach; /* Last SysV shm attach serial handed out. */ | ||
| /* Set when a full region table stopped a mutation from being recorded: | ||
| * guest_region_set_prot unable to split (leaving a region's old prot, or | ||
| * applying the new one to a tail no PTE work covered), a munmap split | ||
|
|
@@ -844,7 +849,7 @@ static inline bool guest_range_hits_infra(const guest_t *g, | |
|
|
||
| /* Whether a tracked region is address space a Linux process would have. The | ||
| * shim and its data sit in the infra reserve, which Linux has no mapping for, | ||
| * so they do not count toward VmSize. | ||
| * so they count toward neither VmSize nor RLIMIT_AS and RLIMIT_DATA. | ||
| */ | ||
| static inline bool guest_region_in_process_vm(const guest_t *g, | ||
| const guest_region_t *r) | ||
|
|
@@ -1318,10 +1323,24 @@ int guest_region_add_ex_owned_gpa(guest_t *g, | |
| int owned_backing_fd, | ||
| bool inherited_at_fork, | ||
| uint64_t vma_id); | ||
|
|
||
| /* Re-seed the logical-VMA allocator from a restored region snapshot. Fork IPC | ||
| * restores regions by value, so next_vma_id must be advanced past every | ||
| * serialized lineage before child-private mappings are added. | ||
| /* guest_region_add_ex_owned_gpa, for a region that carries @shm_attach. */ | ||
| int guest_region_add_attach_gpa(guest_t *g, | ||
| uint64_t start, | ||
| uint64_t end, | ||
| uint64_t gpa_base, | ||
| int prot, | ||
| int flags, | ||
| uint64_t offset, | ||
| const char *name, | ||
| int owned_backing_fd, | ||
| bool inherited_at_fork, | ||
| uint64_t vma_id, | ||
| uint64_t shm_attach); | ||
|
|
||
| /* Re-seed the logical-VMA allocator and the shm attach serial from a restored | ||
| * region snapshot. Fork IPC restores regions by value, so next_vma_id and | ||
| * next_shm_attach must be advanced past every serialized lineage and attach | ||
| * before child-private mappings are added. | ||
| */ | ||
| void guest_reseed_next_vma_id(guest_t *g); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two pieces of one attach can merge while their segment offsets run backwards. Attach two pages at
A, thenmremap(A, 4096, 4096, MREMAP_MAYMOVE | MREMAP_FIXED, A + 8192). The moved page keeps the sourcevma_idand getsgpa_base == start, so it passesregions_mergeable_layoutagainst the page left atA + 4096, and the merged record keeps that page's offset of 4096.shmdt(A)then takes the merged record as the first part and clamps the writeback at the segment end. It never copies the moved page back to segment offset 0, but still unmaps it, so that page's writes are lost and the segment detaches early. Linux keeps the moved page as its own VMA and leaves it attached. Requiring contiguous offsets for attach records closes it. Atest-rlimit-memstep for this move (write both pages, detach, reattach, check both) would guard it.