server: Unlock objects_mutex before locking connection_mutex to avoid deadlock 80/310580/1 accepted/tizen_unified_toolchain accepted/tizen_unified_x_asan accepted/tizen/unified/20240503.070737 accepted/tizen/unified/dev/20240620.011205 accepted/tizen/unified/toolchain/20240508.012400 accepted/tizen/unified/x/20240507.050949 accepted/tizen/unified/x/asan/20240625.092204
authorSeunghun Lee <shiin.lee@samsung.com>
Thu, 2 May 2024 06:16:36 +0000 (15:16 +0900)
committerSeunghun Lee <shiin.lee@samsung.com>
Thu, 2 May 2024 06:16:36 +0000 (15:16 +0900)
In wl_client_connection_data, threads may try to acquire two locks in
different orders, potentially causing deadlock.

Change-Id: I4acde7c0a93b4774632d3283a6fa1c946d498de8

src/wayland-server.c

index 2106451..eca5f1e 100644 (file)
@@ -2222,15 +2222,15 @@ wl_resource_create(struct wl_client *client,
        pthread_mutex_lock(&client->objects_mutex);
 //TIZEN_ONLY : END
        if (wl_map_insert_at(&client->objects, 0, id, resource) < 0) {
+//TIZEN_ONLY(20231208) : Add lock/unlock when adding resource id to wl_map
+               pthread_mutex_unlock(&client->objects_mutex);
+//TIZEN_ONLY : END
                if (errno == EINVAL) {
                        wl_resource_post_error(client->display_resource,
                                               WL_DISPLAY_ERROR_INVALID_OBJECT,
                                               "invalid new id %d", id);
                }
                free(resource);
-//TIZEN_ONLY(20231208) : Add lock/unlock when adding resource id to wl_map
-               pthread_mutex_unlock(&client->objects_mutex);
-//TIZEN_ONLY : END
                return NULL;
        }
 //TIZEN_ONLY(20231208) : Add lock/unlock when adding resource id to wl_map
@@ -2716,15 +2716,15 @@ wl_client_add_resource(struct wl_client *client,
                }
        } else if (wl_map_insert_at(&client->objects, WL_MAP_ENTRY_LEGACY,
                                  resource->object.id, resource) < 0) {
+//TIZEN_ONLY(20231208) : Add lock/unlock when adding resource id to wl_map
+               pthread_mutex_unlock(&client->objects_mutex);
+//TIZEN_ONLY : END
                if (errno == EINVAL) {
                        wl_resource_post_error(client->display_resource,
                                               WL_DISPLAY_ERROR_INVALID_OBJECT,
                                               "invalid new id %d",
                                               resource->object.id);
                }
-//TIZEN_ONLY(20231208) : Add lock/unlock when adding resource id to wl_map
-               pthread_mutex_unlock(&client->objects_mutex);
-//TIZEN_ONLY : END
                return 0;
        }
 //TIZEN_ONLY(20231208) : Add lock/unlock when adding resource id to wl_map