Skip to content

doublemapping.cpp causes crash with SIGXFSZ if file size limits <2TB are in effect #117819

Description

@djast

Description

src/coreclr/minipal/Unix/doublemapping.cpp does:

if (ftruncate(fd, MaxDoubleMappedSize) == -1)

where

#ifdef TARGET_64BIT
static const off_t MaxDoubleMappedSize = 2048ULL10241024*1024;
#else
static const off_t MaxDoubleMappedSize = UINT_MAX;
#endif

This causes the process to fail with SIGXFSZ if a file size limit has been imposed via setrlimit()/prlimit().

Reproduction Steps

Set a file size limit (e.g., "ulimit -S -f 25165824" from bash).
Run any program which invokes VMToOSInterface::CreateDoubleMemoryMapper().

Expected behavior

Process continues normally.

Actual behavior

Process dies with SIGXFSZ.

Regression?

Issue was observed in the Visual Studio Code C/C++ extension; problem occurs in ms-vscode.cpptools-1.23.5-linux-x64 but was not present in ms-vscode.cpptools-1.22.11-linux-x64 (cf. microsoft/vscode-cpptools#13768).
See also microsoft/vscode#251037 , in VS Code's vsce-sign program.
I presume these projects are embedding their libmscordaccore.so libraries from dotnet/runtime.

Known Workarounds

No response

Configuration

AlmaLinux 8.10 x86_64.

Other information

Issue could be addressed by calling getrlimit(RLIMIT_FSIZE) and capping the parameter to ftruncate() at the soft limit.

Activity

  1. added
    untriaged
    on Jul 18, 2025
  2. added
    needs-area-label
    on Jul 18, 2025
  3. added
    area-PAL-coreclr
    on Jul 20, 2025
  4. removed
    untriaged
    on Jul 21, 2025
  5. added this to the 10.0.0 milestone on Jul 21, 2025
  6. janvorli commented on Jul 21, 2025

    @janvorli
    Member

    @djast what is the limit that your device has set? I'd like to understand how low it actually is. If it is smaller than the size of all the executable code loaded from crossgened assemblies, generated by JIT and some runtime helpers, then it would prevent your app execution even if we dynamically set the double mapping max size based on the limit.
    Having said that, I believe we should honor that limit.

  7. djast commented on Jul 21, 2025

    @djast
    Author

    At our site, we currently set RLIMIT_FSIZE to 24GB to prevent users from inadvertently filling up disk partitions with runaway processes (or creating huge sparse files that may interfere with backup/restore processes).

    If the size of all the executable code exceeds that limit, the program isn't running anyway, because the VM subsystem will be paging itself into oblivion.

    I don't know whether the 2TB anonymous memory allocation may have other adverse performance effects on some systems (e.g., systems which disable or limit memory overcommitment), but it may be prudent to consider reducing the allocation to something more reasonable (e.g., the amount of virtual memory in the system) even if RLIMIT_FSIZE does not prevent creating memfd's of unlimited size.

  8. janvorli commented on Jul 21, 2025

    @janvorli
    Member

    but it may be prudent to consider reducing the allocation to something more reasonable (e.g., the amount of virtual memory in the system)

    The information I have found about what influences the max memfd size seems to indicate that while the total mapped size is limited, I have found no information on limits of the total memfd size besides the RLIMIT_FILESIZE. I think we might set the limit to say twice the amount of the physical memory to accommodate for the theoretical extreme case when all the physical memory would be double mapped as RW and RX at the same time. And of course cap that by the RLIMIT_FILESIZE.

  9. removed
    needs-area-label
    on Jul 23, 2025
  10. added 2 commits that reference this issue on Sep 3, 2025
    a8e7741
    f4a4d5c
  11. added a commit that references this issue on Sep 5, 2025
    1e6e939
  12. added a commit that references this issue on Sep 8, 2025
    a10c6d1
  13. locked and limited conversation to collaborators on Oct 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-PAL-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions