Skip to content

Bugfix device memory report bind path hardening - #34

Merged
olehkuznetsov merged 15 commits into
android-graphics:mainfrom
jimblacklercorp:bugfix-device-memory-report-bind-path-hardening
Sep 17, 2026
Merged

olehkuznetsov merged 15 commits into
android-graphics:mainfrom
jimblacklercorp:bugfix-device-memory-report-bind-path-hardening

Conversation

@jimblacklercorp

Copy link
Copy Markdown

No description provided.

Guard the vkBind*Memory entry points against absent dispatch table
entries instead of calling through unconditionally, returning
VK_ERROR_EXTENSION_NOT_PRESENT when the underlying function was not
loaded.

Proactively query vkGet{Buffer,Image}MemoryRequirements at bind time for
resources whose size has not been recorded yet, so suballocations are
sized correctly even when the application never triggered a size
recording path.

Fall back to the owning allocation's total size in BindResourceMemory
when a resource has no recorded size, and track resources bound without
a prior create call, so these bindings are no longer silently dropped.
Add test_DeviceMemoryReport_dispatch, a test binary that links the layer
sources directly and drives its vk* entry points against a stub dispatch
table, so the interception logic can be exercised without a Vulkan ICD. The
Vulkan loader is deliberately not linked: the layer defines the entry points
itself, and the existing test_DeviceMemoryReport_layer binary loads the layer
as a shared module, so the layer's DeviceMemoryReport singleton is a
different instance from the one it can inspect.

Covers the bind path hardening:

- vkBindBufferMemory / vkBindImageMemory and the four vkBind*Memory2[KHR]
  entry points query vkGet{Buffer,Image}MemoryRequirements for resources
  whose size has not been recorded yet, so those bindings are sized instead
  of dropped.
- Sizes that are already known are neither re-queried nor overwritten.
- All six bind entry points return VK_ERROR_EXTENSION_NOT_PRESENT when the
  driver below the layer does not provide the command, rather than calling
  through a null dispatch table entry.

Against the previous implementation the size tests report 0 bytes and the
missing dispatch entry test crashes with SIGSEGV.
Comment thread layersvt/device_memory_report/device_memory_report.cpp Outdated
Comment thread layersvt/device_memory_report/device_memory_report.cpp Outdated
Comment thread layersvt/device_memory_report/device_memory_report_handwritten_functions.h Outdated
Comment thread layersvt/device_memory_report/device_memory_report_handwritten_functions.h Outdated
Comment thread layersvt/test/test_devicememoryreport_dispatch.cpp
…mory

Revert dummy resource synthesis and allocation size fallback, returning
early when a resource was not previously created or has zero recorded size.
…ries

Assert dispatch table entry presence for core 1.0 vkBind*Memory commands
instead of returning VK_ERROR_EXTENSION_NOT_PRESENT. Avoid calling legacy
vkGetImageMemoryRequirements for multi-planar disjoint image plane bindings.
…cution

Add DeviceMemoryReport::Reset() and invoke it in SetUp() and TearDown()
of DeviceMemoryReportDispatchTests so tests are hermetic under shuffling
and repetition. Update dispatch tests to match the hardened entry points.

@olehkuznetsov olehkuznetsov left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice hardening pass — the proactive vkGet*MemoryRequirements lookup closes a real gap where resources bound without a prior vkCreate* interception were never sized, and moving the core 1.0 bind paths to assertions is the right direction.

Two things I'd like resolved before merge, both in device_memory_report_handwritten_functions.h:

  1. The vkBind*Memory2{,KHR} entry points return VK_ERROR_EXTENSION_NOT_PRESENT, which is out of contract for those commands — and there's a new test pinning that behaviour.
  2. The disjoint-image guard added in c41b3bc3e only inspects the first pNext element, so it doesn't reliably do what the commit title says.

The rest are small consistency nits. Neither blocker is a crash or memory-safety issue.

Comment thread layersvt/device_memory_report/device_memory_report_handwritten_functions.h Outdated
Comment thread layersvt/test/test_devicememoryreport_dispatch.cpp Outdated
Comment thread layersvt/device_memory_report/device_memory_report_handwritten_functions.h Outdated
Comment thread layersvt/device_memory_report/device_memory_report_handwritten_functions.h Outdated
Comment thread layersvt/device_memory_report/device_memory_report_handwritten_functions.h Outdated
Comment thread layersvt/device_memory_report/device_memory_report.cpp Outdated
@olehkuznetsov
olehkuznetsov merged commit 6448cc4 into android-graphics:main Sep 17, 2026
15 checks passed
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.

2 participants