-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vk: Use-after-free coverage #8273
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
#include "vulkan/memory/ResourceManager.h" | ||
|
||
#include <backend/Handle.h> | ||
#include <utils/compiler.h> | ||
|
||
#include <utility> | ||
|
||
|
@@ -59,6 +60,11 @@ struct resource_ptr { | |
static enabled_resource_ptr<B> cast(ResourceManager* resManager, | ||
Handle<B> const& handle) noexcept { | ||
D* ptr = resManager->handle_cast<D*, B>(handle); | ||
if (UTILS_UNLIKELY(ptr->isHandleConsideredDestroyed())) { | ||
FILAMENT_CHECK_PRECONDITION(!ptr->isHandleConsideredDestroyed()) | ||
<< "Handle id=" << ptr->id << " (" << getTypeStr(ptr->restype) | ||
<< ") is being used after it has been freed"; | ||
} | ||
return {ptr}; | ||
} | ||
|
||
|
@@ -156,6 +162,8 @@ struct resource_ptr { | |
// only be used from VulkanDriver. | ||
inline void dec() { | ||
assert_invariant(mRef); | ||
assert_invariant(!mRef->isHandleConsiderDestroyed()); | ||
mRef->setHandleConsiderDestroyed(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we at least There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
mRef->dec(); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need the
if
here,FILAMENT_CHECK_PRECONDITION
already does all thelikely/unlikely
shenanigansThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to avoid hitting the switch in
getTypeStr
unless necessary, hence the roundabout logic here.Do you think it's worth it or not? (or maybe it just going to be speculatively executed anyways?).