Skip to content

Fix use-after-free crash when creating custom user messages#1298

Merged
dvander merged 1 commit intoalliedmodders:masterfrom
peace-maker:protobuf_crash
Jun 23, 2020
Merged

Fix use-after-free crash when creating custom user messages#1298
dvander merged 1 commit intoalliedmodders:masterfrom
peace-maker:protobuf_crash

Conversation

@peace-maker
Copy link
Member

When creating our own "owned and local" protobuf message in StartProtobufMessage, m_FakeEngineBuffer is used to track that message. In EndMessage the message is optionally converted to a "private" one with the right abi on osx and passed to the engine's SendUserMessage. On linux and windows the same message as in the m_FakeEngineBuffer is passed though without conversion. engine->SendUserMessage has a vtable hook which sets m_FakeEngineBuffer to the passed argument.

m_FakeEngineBuffer frees the message it previously held, since it's "owned" from StartProtobufMessage, but that's the same one that's passed in as argument so a use-after-free in the engine happens when the now-freed message pointer is forwarded to the real SendUserMessage in the engine.

The message created in StartProtobufMessage wasn't free'd at all when hooks are blocked too. This fix moves the message buffer into a local variable which is destroyed at the end of the function.

Fixes #1286 and #1296

When creating our own "owned and local" protobuf message in `StartProtobufMessage`, `m_FakeEngineBuffer` is used to track that message. In `EndMessage` the message is optionally converted to a "private" one with the right abi on osx and passed to the engine's `SendUserMessage`. On linux and windows the same message as in the `m_FakeEngineBuffer` is passed though without conversion. `engine->SendUserMessage` has a vtable hook which sets `m_FakeEngineBuffer` to the passed argument.

`m_FakeEngineBuffer` frees the message it previously held, since it's "owned" from `StartProtobufMessage`, but that's the same one that's passed in as argument so a use-after-free in the engine happens when the now-freed message pointer is forwarded to the real `SendUserMessage` in the engine.

The message created in `StartProtobufMessage` wasn't free'd at all when hooks are blocked too. This fix moves the message buffer into a local variable which is destroyed at the end of the function.

Fixes alliedmodders#1286 and alliedmodders#1296
Copy link
Member

@Headline Headline left a comment

Choose a reason for hiding this comment

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

Thanks PM! You’re awesome ❤️

@dvander dvander merged commit 15450a6 into alliedmodders:master Jun 23, 2020
@peace-maker peace-maker deleted the protobuf_crash branch June 23, 2020 17:42
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.

Issues from the recent builds [spcomp.exe especially, CS:GO Sv. OnClientPutInServer crash]

3 participants