Skip to content

[release/7.0-preview5] Fix VTableCallHolder writeable mapping size with W^X#70103

Merged
carlossanlop merged 1 commit into
release/7.0-preview5from
backport/pr-70093-to-release/7.0-preview5
Jun 2, 2022
Merged

[release/7.0-preview5] Fix VTableCallHolder writeable mapping size with W^X#70103
carlossanlop merged 1 commit into
release/7.0-preview5from
backport/pr-70093-to-release/7.0-preview5

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented Jun 1, 2022

Backport of #70093 to release/7.0-preview5

The size of this holder is dynamic, but when we are creating the writeable
mapping of this holder to initialize its code, we don't take that into account.
So in case the holder is located at the end of a memory page and crosses its
boundary, the writeable mapping covers only the beginning of the holder and
so we either crash during the initialization if the following memory page is
not mapped or read only, or we corrupt a completely unrelated memory page
in case it is mapped and writeable.

The fix is to use the real size of the holder instead of sizeof(...).

/cc @janvorli

Customer Impact

Runtime with W^X enabled (the default in preview 5) can rarely crash with AccessViolation exception.

Testing

Coreclr and libraries tests, @333fred has tested a drop-in replacement of a libcoreclr.so with this fix in an installer repo test that was crashing for him in 8 out of 10 cases, with this fix it was passing ok.

Risk

Very low, the change just makes writeable memory mapping larger than before (so that it covers the area of memory that was just allocated for the holder) and we only access memory range of the holder.

The size of this holder is dynamic, but when we are creating the writeable
mapping of this holder to initialize its code, we don't take that into account.
So in case the holder is located at the end of a memory page and crosses its
boundary, the writeable mapping covers only the beginning of the holder and
so we either crash during the initialization if the following memory page is
not mapped or read only, or we corrupt a completely unrelated memory page
in case it is mapped and writeable.

The fix is to use the real size of the holder instead of sizeof(...).
@ghost ghost added the area-VM-coreclr label Jun 1, 2022
@mmitche
Copy link
Copy Markdown
Member

mmitche commented Jun 1, 2022

@mangod9 @janvorli can you bring this for servicing?

@janvorli janvorli added the Servicing-consider Issue for next servicing release review label Jun 1, 2022
@janvorli janvorli self-assigned this Jun 1, 2022
Copy link
Copy Markdown
Member

@jeffschwMSFT jeffschwMSFT left a comment

Choose a reason for hiding this comment

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

Approved. We will take for consideration in preview5

@carlossanlop carlossanlop added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Jun 1, 2022
@carlossanlop
Copy link
Copy Markdown
Contributor

Approved by Tactics via email.

@carlossanlop
Copy link
Copy Markdown
Contributor

Test failure is unrelated: System.Text.RegularExpressions.Unit.Tests

@carlossanlop carlossanlop merged commit e8dfdb0 into release/7.0-preview5 Jun 2, 2022
@carlossanlop carlossanlop deleted the backport/pr-70093-to-release/7.0-preview5 branch June 2, 2022 00:58
@ghost ghost locked as resolved and limited conversation to collaborators Jul 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-VM-coreclr Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants