Skip to content

Fix use after free in ExecutableAllocator::AllocateThunksFromTemplate() - #134131

Merged
jkotas merged 1 commit into
dotnet:mainfrom
PavlNekrasov:fix/allocatethunksfromtemplate-use-after-free
Sep 21, 2026
Merged

jkotas merged 1 commit into
dotnet:mainfrom
PavlNekrasov:fix/allocatethunksfromtemplate-use-after-free

Conversation

@PavlNekrasov

Copy link
Copy Markdown
Contributor

fix #134128

Return NULL right after BackoutBlock(), as the three other callers of BackoutBlock() in this file do.

Signed-off-by: [email protected]
Signed-off-by: [email protected]

Problem:
When ReserveDoubleMappedMemory() fails in
ExecutableAllocator::AllocateThunksFromTemplate(),
BackoutBlock(block, isFreeBlock) deletes the block if it was not taken
from the free list. Execution then continues and dereferences
block->baseRX, which is freed memory in that case and a stale value
otherwise.

Solution:
Return NULL right after BackoutBlock(), as the three other callers of
BackoutBlock() in this file do.

Signed-off-by: [email protected]
Signed-off-by: [email protected]
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Sep 17, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

@PavlNekrasov PavlNekrasov changed the title Fix: DEREF_AFTER_FREE Fix use after free in ExecutableAllocator::AllocateThunksFromTemplate() Sep 17, 2026
@agocke
agocke requested a balanced review from Copilot September 18, 2026 23:11

@agocke agocke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused control-flow fix correctly prevents dereferencing the backed-out block.

Review effort: Balanced
Findings: None

What changed in this PR

Prevents a use-after-free when executable thunk memory reservation fails.

Changes:

  • Returns immediately after BackoutBlock, avoiding access to the released block.
File Description
src/​coreclr/​utilcode/​executableallocator.cpp Stops thunk allocation after reservation failure.

@jkotas
jkotas merged commit 8123b7a into dotnet:main Sep 21, 2026
121 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 22, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-VM-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use after free in ExecutableAllocator::AllocateThunksFromTemplate()

4 participants