MAP_FIXED shared mapping of a read-only fd fails with EACCES

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

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c, macos

Research direction

Start by reading sys_mmap, mmap_fixed_commit, and hvf_apply_file_overlay to follow how read-only file descriptors are handled in fixed and non-fixed mappings. Reproduce the issue with the supplied mmap sequence and compare it with Linux 6.12. Done when the fixed shared read-only mapping succeeds, including MAP_FIXED_NOREPLACE into a free hole, while existing behavior remains covered.

Written by the indexing model from the issue text.

Description

bug

On 170b5df, mmap(addr, len, PROT_READ, MAP_SHARED | MAP_FIXED, fd, 0) with fd opened O_RDONLY fails with EACCES; MAP_FIXED_NOREPLACE into a free hole fails the same way. Linux 6.12 maps both. Without MAP_FIXED, the same call succeeds under elfuse.

The non-fixed path in sys_mmap checks overlay_fd_writable and falls back to the pread snapshot for a read-only fd. mmap_fixed_commit calls hvf_apply_file_overlay without that check, and hvf_apply_file_overlay returns EACCES for a read-only fd.

Repro: create a 4 MiB file, open it O_RDONLY, reserve 36 MiB with an anonymous PROT_NONE mapping, then mmap(reserve, 4 MiB, PROT_READ, MAP_SHARED | MAP_FIXED, fd, 0).

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.