Skip to content

[Native] Fix use-after-free in HTTP callbacks (#19863)#19865

Merged
pranjalssh merged 1 commit intoprestodb:masterfrom
pranjalssh:export-D46674355
Jun 15, 2023
Merged

[Native] Fix use-after-free in HTTP callbacks (#19863)#19865
pranjalssh merged 1 commit intoprestodb:masterfrom
pranjalssh:export-D46674355

Conversation

@pranjalssh
Copy link
Contributor

@pranjalssh pranjalssh commented Jun 13, 2023

Summary:

In the HTTPClient, callbacks are scheduled on an eventBase. HTTPClient is kept alive using a shared_ptr, but it contains a raw pointer to MemoryPool. This MemoryPool may be freed if Task is aborted earlier, but a callback is executed much later.
We see crashes related to this when the batch cluster is under heavy load.

So the fix here is to keep shared_ptr to MemoryPool isntead of a raw pointer

Differential Revision: D46674355

== NO RELEASE NOTE ==

@pranjalssh pranjalssh requested a review from a team as a code owner June 13, 2023 05:02
@facebook-github-bot
Copy link
Collaborator

This pull request was exported from Phabricator. Differential Revision: D46674355

@facebook-github-bot
Copy link
Collaborator

This pull request was exported from Phabricator. Differential Revision: D46674355

@facebook-github-bot
Copy link
Collaborator

This pull request was exported from Phabricator. Differential Revision: D46674355

@facebook-github-bot
Copy link
Collaborator

This pull request was exported from Phabricator. Differential Revision: D46674355

@facebook-github-bot
Copy link
Collaborator

This pull request was exported from Phabricator. Differential Revision: D46674355

@majetideepak majetideepak changed the title Fix use-after-free in HTTP callbacks (#19863) [Native] Fix use-after-free in HTTP callbacks (#19863) Jun 14, 2023
Copy link
Collaborator

@majetideepak majetideepak left a comment

Choose a reason for hiding this comment

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

@pranjalssh Changes look good to me. Can you please update the commit message with [native] prefix and add a description?
@xiaoxmeng can you take another look? Thanks.

@facebook-github-bot
Copy link
Collaborator

@pranjalssh has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Summary:
In the HTTPClient, callbacks are scheduled on an eventBase. HTTPClient is kept alive using a shared_ptr, but it contains a raw pointer to MemoryPool. This MemoryPool may be freed if Task is aborted earlier, but a callback is executed much later.
We see crashes related to this when the batch cluster is under heavy load.

So the fix here is to keep shared_ptr to MemoryPool isntead of a raw pointer

```
== NO RELEASE NOTE ==
```

Pull Request resolved: prestodb#19865

Reviewed By: xiaoxmeng

Differential Revision: D46674355

Pulled By: pranjalssh

fbshipit-source-id: 9b53deb6357ff87b8e1a992f3205d0ce9d79c05c
@facebook-github-bot
Copy link
Collaborator

This pull request was exported from Phabricator. Differential Revision: D46674355

Copy link
Contributor

@xiaoxmeng xiaoxmeng left a comment

Choose a reason for hiding this comment

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

@pranjalssh Thanks for the fix!

@pranjalssh pranjalssh merged commit 4e020ff into prestodb:master Jun 15, 2023
@wanglinsong wanglinsong mentioned this pull request Jul 27, 2023
28 tasks
wypb pushed a commit to wypb/presto that referenced this pull request Dec 22, 2023
Summary:
In the HTTPClient, callbacks are scheduled on an eventBase. HTTPClient is kept alive using a shared_ptr, but it contains a raw pointer to MemoryPool. This MemoryPool may be freed if Task is aborted earlier, but a callback is executed much later.
We see crashes related to this when the batch cluster is under heavy load.

So the fix here is to keep shared_ptr to MemoryPool isntead of a raw pointer

```
== NO RELEASE NOTE ==
```

Pull Request resolved: prestodb#19865

Reviewed By: xiaoxmeng

Differential Revision: D46674355

Pulled By: pranjalssh

fbshipit-source-id: 9b53deb6357ff87b8e1a992f3205d0ce9d79c05c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants