Files
rtems/cpukit/libmisc/regulator
Sharvin Neve 80b1ba90a5 cpukit/libmisc: Clean up a partial regulator
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.
2026-09-17 17:48:39 -05:00
..