Skip to content

mmap.resize() crashes on NetBSD when growing a shared anonymous mapping #154258

Description

@serhiy-storchaka

Crash report

On NetBSD, mmap.resize() crashes (SIGSEGV) when growing a shared anonymous mapping:

import mmap
m = mmap.mmap(-1, 4096)      # shared anonymous mapping
m[:] = b'A' * 4096
m.resize(8192)               # "succeeds"
m[4096]                      # SIGSEGV

resize() returns without error and the original page is still readable, but the grown region is not backed, so accessing it crashes.

The cause is NetBSD's mremap(): growing a MAP_SHARED | MAP_ANON mapping returns a mapping whose new region is unmapped (verified with a standalone C program — a MAP_PRIVATE anonymous mapping grows correctly, a MAP_SHARED one does not). This is the same behaviour as the Linux kernel bug that Modules/mmapmodule.c already guards against for __linux__ (https://bugzilla.kernel.org/show_bug.cgi?id=8691); Linux later made mremap() reject the grow, but NetBSD still returns the broken mapping. Because NetBSD's mremap() does not return MAP_FAILED, the failure can't be detected from its return value.

The NetBSD behaviour is undocumented (not in the mremap(2) BUGS section) and appears unreported upstream.

Fix: reject growing a shared anonymous mapping on NetBSD with ValueError, as is already done on Linux.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15pre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesOS-netbsdextension-modulesC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dump

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions