Skip to content

Invalid mmap(2) call with MAP_ANONYMOUS and fd 0#2

Open
Low-power wants to merge 1 commit intoashfordneil:masterfrom
Low-power:fix-invalid-mmap
Open

Invalid mmap(2) call with MAP_ANONYMOUS and fd 0#2
Low-power wants to merge 1 commit intoashfordneil:masterfrom
Low-power:fix-invalid-mmap

Conversation

@Low-power
Copy link
Copy Markdown

@Low-power Low-power commented Apr 14, 2026

The code contains a non-portable use of mmap(2). It requests MAP_ANONYMOUS, but the file descriptor is not -1. POSIX specified that in case of MAP_ANONYMOUS, the file descriptor should be -1, otherwise the effect is unspecified.1 Apparently Linux simply ignores the file descriptor in this case, but other implementations such as FreeBSD kernel, may reject it with an EINVAL.2

The file descriptor should be set to -1 for anonymous pages.

Footnotes

  1. mmap - The Open Group Base Specifications Issue 8

  2. mmap(2) - FreeBSD Manual Pages

@Low-power Low-power changed the title Calls mmap(2) with MAP_ANONYMOUS and fd 0 Invalid mmap(2) call with MAP_ANONYMOUS and fd 0 Apr 14, 2026
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