GPU: hold SHADER_HEAPS across descriptor mirror and check query offsets

mirror() previously dropped the SHADER_HEAPS lock inside shader_slot() before using the returned &Heap, allowing a concurrent Heap::drop to free the heap while mirror() accessed it. Also guards copy_simple() against invalid descriptor kinds, rejects placed heaps whose address+size wraps u64, and checks offset+count*bytes in resolve_queries() against overflow (with a regression test).

(cherry picked from commit 628b95da5e738046d00995743e07137e48936ba6)
This commit is contained in:
Manuel Pérez authored and local committed 2026-11-25 01:02:56 -06:00
1 parent f1650b7e45
commit 51b9d09b34
3 files changed
+84 -16

No files matched your search

+28 -1
View File
@@ -1372,7 +1372,10 @@ extern "system" fn resolve_queries(
PIPELINE_STATISTICS => (Written::Value(0), 88),
_ => (Written::Value(0), 16),
};
if offset + u64::from(count) * bytes > size {
let Some(end) = offset.checked_add(u64::from(count) * bytes) else {
return;
};
if end > size {
return;
}
for i in 0..u64::from(count) {
@@ -2257,4 +2260,28 @@ mod tests {
assert_eq!(release(list), 0);
assert_eq!(release(allocator), 0);
}
/// An offset near `u64::MAX` must not overflow and write outside the
/// query destination buffer.
#[test]
fn resolve_queries_rejects_overflowing_offset() {
let null = std::ptr::null();
let mut allocator = null;
assert_eq!(
create_allocator(null, 0, &ALLOCATOR_IIDS[0], &mut allocator),
S_OK
);
let mut list = null;
assert_eq!(
create_list(null, 0, 0, allocator, null, &LIST_IIDS[1], &mut list),
S_OK
);
let buffer = crate::resource::test_buffer(64);
// Used to overflow `offset + count * 8` (panic in debug, wrap in release).
resolve_queries(list, null, 0, 0, 2, buffer, u64::MAX - 8);
let release = |o: This| slot::<extern "system" fn(This) -> u32>(o, 0x10)(o);
for object in [buffer, list, allocator] {
assert_eq!(release(object), 0);
}
}
}