From f875c3a288ddeeb363567cd17cc676d7436e4558 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 24 Aug 2020 14:24:34 -0700 Subject: [PATCH] virgl: more checks against init args Signed-off-by: Chia-I Wu Reviewed-by: Gurchetan Singh --- src/virglrenderer.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/virglrenderer.c b/src/virglrenderer.c index bf16cb2..bbf6416 100644 --- a/src/virglrenderer.c +++ b/src/virglrenderer.c @@ -44,7 +44,9 @@ #include "virgl_resource.h" struct global_state { + bool client_initialized; void *cookie; + int flags; const struct virgl_renderer_callbacks *cbs; bool resource_initialized; @@ -468,14 +470,22 @@ int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks { int ret; - if (!cookie || !cbs) - return -1; - - if (cbs->version < 1 || cbs->version > VIRGL_RENDERER_CALLBACKS_VERSION) - return -1; - - state.cookie = cookie; - state.cbs = cbs; + if (state.client_initialized && (state.cookie != cookie || + state.flags != flags || + state.cbs != cbs)) + return -EBUSY; + + if (!state.client_initialized) { + if (!cookie || !cbs) + return -1; + if (cbs->version < 1 || cbs->version > VIRGL_RENDERER_CALLBACKS_VERSION) + return -1; + + state.cookie = cookie; + state.flags = flags; + state.cbs = cbs; + state.client_initialized = true; + } if (!state.resource_initialized) { ret = virgl_resource_table_init(vrend_renderer_get_pipe_callbacks());