vkr: validate object ids

Add vkr_context_validate_object_id to validate object ids are non-zero
and unique.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
macos/master
Chia-I Wu 3 years ago
parent a77af35cd4
commit 058fa04b1d
  1. 15
      src/venus/vkr_context.h
  2. 3
      src/venus/vkr_physical_device.c
  3. 2
      src/venus/vkr_queue.c

@ -65,6 +65,17 @@ struct vkr_context {
char *instance_name; char *instance_name;
}; };
static inline bool
vkr_context_validate_object_id(struct vkr_context *ctx, vkr_object_id id)
{
if (unlikely(!id || util_hash_table_get_u64(ctx->object_table, id))) {
vkr_cs_decoder_set_fatal(&ctx->decoder);
return false;
}
return true;
}
static inline void * static inline void *
vkr_context_alloc_object(UNUSED struct vkr_context *ctx, vkr_context_alloc_object(UNUSED struct vkr_context *ctx,
size_t size, size_t size,
@ -72,6 +83,9 @@ vkr_context_alloc_object(UNUSED struct vkr_context *ctx,
const void *id_handle) const void *id_handle)
{ {
const vkr_object_id id = vkr_cs_handle_load_id((const void **)id_handle, type); const vkr_object_id id = vkr_cs_handle_load_id((const void **)id_handle, type);
if (!vkr_context_validate_object_id(ctx, id))
return NULL;
return vkr_object_alloc(size, type, id); return vkr_object_alloc(size, type, id);
} }
@ -79,7 +93,6 @@ static inline void
vkr_context_add_object(struct vkr_context *ctx, struct vkr_object *obj) vkr_context_add_object(struct vkr_context *ctx, struct vkr_object *obj)
{ {
assert(vkr_is_recognized_object_type(obj->type)); assert(vkr_is_recognized_object_type(obj->type));
/* TODO we might hit these at the moment */
assert(obj->id); assert(obj->id);
assert(!util_hash_table_get_u64(ctx->object_table, obj->id)); assert(!util_hash_table_get_u64(ctx->object_table, obj->id));

@ -197,6 +197,9 @@ vkr_dispatch_vkEnumeratePhysicalDevices(struct vn_dispatch_context *dispatch,
continue; continue;
} }
if (!vkr_context_validate_object_id(ctx, id))
break;
physical_dev = physical_dev =
vkr_object_alloc(sizeof(*physical_dev), VK_OBJECT_TYPE_PHYSICAL_DEVICE, id); vkr_object_alloc(sizeof(*physical_dev), VK_OBJECT_TYPE_PHYSICAL_DEVICE, id);
if (!physical_dev) { if (!physical_dev) {

@ -290,6 +290,8 @@ vkr_queue_assign_object_id(struct vkr_context *ctx,
vkr_cs_decoder_set_fatal(&ctx->decoder); vkr_cs_decoder_set_fatal(&ctx->decoder);
return; return;
} }
if (!vkr_context_validate_object_id(ctx, id))
return;
queue->base.id = id; queue->base.id = id;

Loading…
Cancel
Save