mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-11-16 19:04:53 +08:00
rtems_regulator_create() calls _Regulator_Free_helper() on every error path. The helper deletes the task, the message queue and the partition without a check. An error before the create of one of them leaves its identifier at REGULATOR_NO_ID; the delete then returns RTEMS_INVALID_ID and a debug build fails an assertion. The helper also loses the storage of the message queue when the construct of the queue fails. In addition, the output thread ends itself when it cannot create its period. The helper then attempts to delete a task which no longer exists. Furthermore, rtems_regulator_delete() with zero ticks deletes the output thread before it reaches the exit path, leaking the rate monotonic period. Finally, the exit path of the output thread previously marked delivery_thread_is_running as false before finishing clean up and signaling that it has exited, exposing a race window to the helper on SMP systems. Define REGULATOR_NO_ID as ((rtems_id) UINT32_MAX) and initialize delivery_thread_id, queue_id, and messages_partition_id to REGULATOR_NO_ID in rtems_regulator_create(). Guard deletions in _Regulator_Free_helper() against REGULATOR_NO_ID and delivery_thread_has_exited. Free message_queue_storage directly if queue creation failed. Delete the rate monotonic period in the helper if the thread was deleted before exiting. On the output thread exit path, delete the period and set delivery_thread_has_exited before setting delivery_thread_is_running to false. Close #5747. Close #5760.