mprotect changes a whole range instead of stopping at the first failing mapping

Open
#489 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c, linux

Research direction

Start by reading sys_mprotect and the range handling around guest_region_range_has_ro_shared_backing; the issue does not name their source files or tests. Trace how mappings are processed in address order, including holes and RLIMIT_DATA refusals. Done means processing stops at the first failing mapping while earlier changes remain, matching the Linux behavior described in the issue.

Written by the indexing model from the issue text.

Description

bug

sys_mprotect changes a whole range at once, where Linux's mprotect_fixup takes the mappings in address order and stops at the first one that fails, leaving the mappings below it changed.

On 170b5df, mapping three read-only pages, unmapping the middle one, then mprotect(p, 3 pages, PROT_READ | PROT_WRITE) returns 0 and makes the first and third pages writable. Linux 6.12 returns ENOMEM at the hole, with the first page writable and the third unchanged.

The same whole-range step shows up in the RLIMIT_DATA check from #485: the part of a range below the mapping the limit refuses is changed with one sys_mprotect, so guest_region_range_has_ro_shared_backing refuses that whole part with EACCES before any mapping below the shared one changes, and a hole inside it gets page tables and the new permissions.

A fix would walk the range in address order and stop at the first hole, refused mapping or RLIMIT_DATA refusal.

Dominant language
C
Stars
287
Forks
33
Avg merge
2d 17h
Merged PRs (30d)
18

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sysprog21/elfuse

All issues in sysprog21/elfuse

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.