The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ipc: Validate device IDs

To prevent bad IPC arguments crashing the service.

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2426>

averyv b92280c2 f9e81d9f

+57 -38
+57 -38
src/xrt/ipc/server/ipc_server_handler.c
··· 50 50 return XRT_SUCCESS; 51 51 } 52 52 53 + #define GET_XDEV_OR_RETURN(ics, device_id, out_device) \ 54 + do { \ 55 + xrt_result_t res = validate_device_id(ics, device_id, &out_device); \ 56 + if (res != XRT_SUCCESS) { \ 57 + return res; \ 58 + } \ 59 + } while (0) 60 + 61 + 53 62 static xrt_result_t 54 63 validate_origin_id(volatile struct ipc_client_state *ics, int64_t origin_id, struct xrt_tracking_origin **out_xtrack) 55 64 { ··· 546 555 struct xrt_space_overseer *xso = ics->server->xso; 547 556 548 557 struct xrt_device *xdev = NULL; 549 - xrt_result_t xret = validate_device_id(ics, xdev_id, &xdev); 550 - if (xret != XRT_SUCCESS) { 551 - U_LOG_E("Invalid device_id!"); 552 - return xret; 553 - } 558 + GET_XDEV_OR_RETURN(ics, xdev_id, xdev); 554 559 555 560 struct xrt_space *xs = NULL; 556 - xret = xrt_space_overseer_create_pose_space(xso, xdev, name, &xs); 561 + xrt_result_t xret = xrt_space_overseer_create_pose_space(xso, xdev, name, &xs); 557 562 if (xret != XRT_SUCCESS) { 558 563 return xret; 559 564 } ··· 1025 1030 { 1026 1031 // xdev 1027 1032 uint32_t device_id = layer->xdev_id; 1028 - struct xrt_device *xdev = get_xdev(ics, device_id); 1033 + struct xrt_device *xdev = NULL; 1034 + GET_XDEV_OR_RETURN(ics, device_id, xdev); 1029 1035 1030 1036 if (xdev == NULL) { 1031 1037 U_LOG_E("Invalid xdev for projection layer!"); ··· 1065 1071 // Cast away volatile. 1066 1072 struct xrt_layer_data *data = (struct xrt_layer_data *)&layer->data; 1067 1073 1068 - struct xrt_device *xdev = get_xdev(ics, xdevi); 1074 + struct xrt_device *xdev = NULL; 1075 + GET_XDEV_OR_RETURN(ics, xdevi, xdev); 1069 1076 if (xdev == NULL) { 1070 1077 U_LOG_E("Invalid xdev for projection layer #%u!", i); 1071 1078 return false; ··· 1104 1111 uint32_t device_id = layer->xdev_id; 1105 1112 uint32_t sci = layer->swapchain_ids[0]; 1106 1113 1107 - struct xrt_device *xdev = get_xdev(ics, device_id); 1114 + struct xrt_device *xdev = NULL; 1115 + GET_XDEV_OR_RETURN(ics, device_id, xdev); 1108 1116 struct xrt_swapchain *xcs = ics->xscs[sci]; 1109 1117 1110 1118 if (xcs == NULL) { ··· 1231 1239 // xdev 1232 1240 uint32_t xdevi = layer->xdev_id; 1233 1241 1234 - struct xrt_device *xdev = get_xdev(ics, xdevi); 1242 + struct xrt_device *xdev = NULL; 1243 + GET_XDEV_OR_RETURN(ics, xdevi, xdev); 1235 1244 1236 1245 if (xdev == NULL) { 1237 1246 U_LOG_E("Invalid xdev for passthrough layer #%u!", i); ··· 1952 1961 1953 1962 // To make the code a bit more readable. 1954 1963 uint32_t device_id = id; 1955 - struct xrt_device *xdev = get_xdev(ics, device_id); 1964 + struct xrt_device *xdev = NULL; 1965 + GET_XDEV_OR_RETURN(ics, device_id, xdev); 1956 1966 1957 1967 // Get the pose. 1958 1968 return xrt_device_get_hand_tracking(xdev, name, at_timestamp, out_value, out_timestamp); ··· 1972 1982 1973 1983 // To make the code a bit more readable. 1974 1984 uint32_t device_id = id; 1975 - struct xrt_device *xdev = get_xdev(ics, device_id); 1985 + struct xrt_device *xdev = NULL; 1986 + GET_XDEV_OR_RETURN(ics, device_id, xdev); 1976 1987 1977 1988 1978 1989 if (view_count == 0 || view_count > IPC_MAX_RAW_VIEWS) { ··· 2041 2052 { 2042 2053 // To make the code a bit more readable. 2043 2054 uint32_t device_id = id; 2044 - struct xrt_device *xdev = get_xdev(ics, device_id); 2055 + struct xrt_device *xdev = NULL; 2056 + GET_XDEV_OR_RETURN(ics, device_id, xdev); 2045 2057 return xrt_device_get_view_poses( // 2046 2058 xdev, // 2047 2059 default_eye_relation, // ··· 2063 2075 { 2064 2076 // To make the code a bit more readable. 2065 2077 uint32_t device_id = id; 2066 - struct xrt_device *xdev = get_xdev(ics, device_id); 2078 + struct xrt_device *xdev = NULL; 2079 + GET_XDEV_OR_RETURN(ics, device_id, xdev); 2067 2080 2068 2081 bool ret = xrt_device_compute_distortion(xdev, view, u, v, out_triplet); 2069 2082 *out_ret = ret; ··· 2079 2092 { 2080 2093 // To make the code a bit more readable. 2081 2094 uint32_t device_id = id; 2082 - struct xrt_device *xdev = get_xdev(ics, device_id); 2095 + struct xrt_device *xdev = NULL; 2096 + GET_XDEV_OR_RETURN(ics, device_id, xdev); 2083 2097 2084 2098 uint64_t new_count = ics->plane_detection_count + 1; 2085 2099 ··· 2118 2132 { 2119 2133 // To make the code a bit more readable. 2120 2134 uint32_t device_id = id; 2121 - struct xrt_device *xdev = get_xdev(ics, device_id); 2135 + struct xrt_device *xdev = NULL; 2136 + GET_XDEV_OR_RETURN(ics, device_id, xdev); 2122 2137 2123 2138 enum xrt_result xret = xrt_device_destroy_plane_detection_ext(xdev, plane_detection_id); 2124 2139 ··· 2156 2171 { 2157 2172 // To make the code a bit more readable. 2158 2173 uint32_t device_id = id; 2159 - struct xrt_device *xdev = get_xdev(ics, device_id); 2174 + struct xrt_device *xdev = NULL; 2175 + GET_XDEV_OR_RETURN(ics, device_id, xdev); 2160 2176 2161 2177 xrt_result_t xret = xrt_device_get_plane_detection_state_ext(xdev, plane_detection_id, out_state); 2162 2178 if (xret != XRT_SUCCESS) { ··· 2179 2195 2180 2196 // To make the code a bit more readable. 2181 2197 uint32_t device_id = id; 2182 - struct xrt_device *xdev = get_xdev(ics, device_id); 2198 + struct xrt_device *xdev = NULL; 2199 + GET_XDEV_OR_RETURN(ics, device_id, xdev); 2183 2200 2184 2201 struct xrt_plane_detections_ext out = {0}; 2185 2202 ··· 2244 2261 xrt_result_t 2245 2262 ipc_handle_device_get_presence(volatile struct ipc_client_state *ics, uint32_t id, bool *presence) 2246 2263 { 2247 - struct xrt_device *xdev = get_xdev(ics, id); 2264 + struct xrt_device *xdev = NULL; 2265 + GET_XDEV_OR_RETURN(ics, id, xdev); 2248 2266 return xrt_device_get_presence(xdev, presence); 2249 2267 } 2250 2268 ··· 2256 2274 { 2257 2275 // To make the code a bit more readable. 2258 2276 uint32_t device_id = id; 2259 - struct xrt_device *xdev = get_xdev(ics, device_id); 2277 + struct xrt_device *xdev = NULL; 2278 + GET_XDEV_OR_RETURN(ics, device_id, xdev); 2260 2279 2261 2280 // Set the output. 2262 2281 return xrt_device_set_output(xdev, name, value); ··· 2276 2295 2277 2296 // To make the code a bit more readable. 2278 2297 uint32_t device_id = id; 2279 - struct xrt_device *xdev = get_xdev(ics, device_id); 2298 + struct xrt_device *xdev = NULL; 2299 + GET_XDEV_OR_RETURN(ics, device_id, xdev); 2280 2300 2281 2301 os_mutex_lock(&ics->server->global_state.lock); 2282 2302 ··· 2341 2361 { 2342 2362 // To make the code a bit more readable. 2343 2363 uint32_t device_id = id; 2344 - struct xrt_device *xdev = get_xdev(ics, device_id); 2364 + struct xrt_device *xdev = NULL; 2365 + GET_XDEV_OR_RETURN(ics, device_id, xdev); 2345 2366 2346 2367 // Set the output. 2347 2368 return xrt_device_get_output_limits(xdev, limits); ··· 2359 2380 xrt_result_t xret; 2360 2381 2361 2382 // @todo verify 2362 - struct xrt_device *xdev = get_xdev(ics, device_id); 2383 + struct xrt_device *xdev = NULL; 2384 + GET_XDEV_OR_RETURN(ics, device_id, xdev); 2363 2385 struct xrt_visibility_mask *mask = NULL; 2364 2386 if (xdev->get_visibility_mask) { 2365 2387 xret = xrt_device_get_visibility_mask(xdev, type, view_index, &mask); ··· 2404 2426 { 2405 2427 // To make the code a bit more readable. 2406 2428 uint32_t device_id = id; 2407 - struct xrt_device *xdev = get_xdev(ics, device_id); 2429 + struct xrt_device *xdev = NULL; 2430 + GET_XDEV_OR_RETURN(ics, device_id, xdev); 2408 2431 *out_available = xrt_device_is_form_factor_available(xdev, form_factor); 2409 2432 return XRT_SUCCESS; 2410 2433 } ··· 2480 2503 struct xrt_facial_expression_set *out_value) 2481 2504 { 2482 2505 const uint32_t device_id = id; 2483 - struct xrt_device *xdev = get_xdev(ics, device_id); 2506 + struct xrt_device *xdev = NULL; 2507 + GET_XDEV_OR_RETURN(ics, device_id, xdev); 2484 2508 // Get facial expression data. 2485 2509 return xrt_device_get_face_tracking(xdev, facial_expression_type, at_timestamp_ns, out_value); 2486 2510 } ··· 2491 2515 enum xrt_input_name body_tracking_type, 2492 2516 struct xrt_body_skeleton *out_value) 2493 2517 { 2494 - struct xrt_device *xdev = get_xdev(ics, id); 2518 + struct xrt_device *xdev = NULL; 2519 + GET_XDEV_OR_RETURN(ics, id, xdev); 2495 2520 return xrt_device_get_body_skeleton(xdev, body_tracking_type, out_value); 2496 2521 } 2497 2522 ··· 2502 2527 int64_t desired_timestamp_ns, 2503 2528 struct xrt_body_joint_set *out_value) 2504 2529 { 2505 - struct xrt_device *xdev = get_xdev(ics, id); 2530 + struct xrt_device *xdev = NULL; 2531 + GET_XDEV_OR_RETURN(ics, id, xdev); 2506 2532 return xrt_device_get_body_joints(xdev, body_tracking_type, desired_timestamp_ns, out_value); 2507 2533 } 2508 2534 ··· 2510 2536 ipc_handle_device_get_battery_status( 2511 2537 volatile struct ipc_client_state *ics, uint32_t id, bool *out_present, bool *out_charging, float *out_charge) 2512 2538 { 2513 - struct xrt_device *xdev = get_xdev(ics, id); 2539 + struct xrt_device *xdev = NULL; 2540 + GET_XDEV_OR_RETURN(ics, id, xdev); 2514 2541 return xrt_device_get_battery_status(xdev, out_present, out_charging, out_charge); 2515 2542 } 2516 2543 ··· 2518 2545 ipc_handle_device_get_brightness(volatile struct ipc_client_state *ics, uint32_t id, float *out_brightness) 2519 2546 { 2520 2547 struct xrt_device *xdev = NULL; 2521 - xrt_result_t xret = validate_device_id(ics, id, &xdev); 2522 - if (xret != XRT_SUCCESS) { 2523 - U_LOG_E("Invalid device_id!"); 2524 - return xret; 2525 - } 2548 + GET_XDEV_OR_RETURN(ics, id, xdev); 2526 2549 2527 2550 if (!xdev->supported.brightness_control) { 2528 2551 return XRT_ERROR_FEATURE_NOT_SUPPORTED; ··· 2535 2558 ipc_handle_device_set_brightness(volatile struct ipc_client_state *ics, uint32_t id, float brightness, bool relative) 2536 2559 { 2537 2560 struct xrt_device *xdev = NULL; 2538 - xrt_result_t xret = validate_device_id(ics, id, &xdev); 2539 - if (xret != XRT_SUCCESS) { 2540 - U_LOG_E("Invalid device_id!"); 2541 - return xret; 2542 - } 2561 + GET_XDEV_OR_RETURN(ics, id, xdev); 2543 2562 2544 2563 if (!xdev->supported.brightness_control) { 2545 2564 return XRT_ERROR_FEATURE_NOT_SUPPORTED;