Skip to content

Conversation

@github-actions
Copy link

@github-actions github-actions bot commented Mar 29, 2025

Backport c05cfbf from #87235.

Fixes #89331

k_thread_priority_set() on a pended thread wasn't re-inserting into the
waitq, causing the incorrect thread to run based on priority. When using
the scalable waitq config, this can also break assumptions of the tree
and leave the owner of a waitq still being in the waitq tree, cycles in
the tree, or a crash.

Remove and re-add a thread to a waitq to ensure the waitq remains in
order and the tree's assumptions are not violated.

To illustrate the issue, consider 4 threads in decreasing priority
order: A, B, C, and D along with two mutexes, m0 and m1. This is
implemented in the new complex_inversion mutex_api test.
1. D locks m1
2. C locks m0
3. C pends on m1
4. B pends on m1
5. A pends on m0, boosts C's priority, now tree on m1 is not sorted
6. D unlocks m1, left-most thread on tree is B. When removing B from
   tree it cannot be found because it searches to the right of C due to
   C's boosted priority when the node is actually on the left. rb_remove
   silently fails.
7. B unlocks m1, left-most thread on tree is still B and it tries to
   unpend itself, resulting in a NULL pointer dereference on
   B->base.pended_on.

Signed-off-by: Josh DeWitt <[email protected]>
(cherry picked from commit c05cfbf)
@github-actions github-actions bot added the Backport Backport PR and backport failure issues label Mar 29, 2025
@github-project-automation github-project-automation bot moved this to To do in Backports Mar 29, 2025
@kartben kartben closed this Jul 11, 2025
@github-project-automation github-project-automation bot moved this from To do to Done in Backports Jul 11, 2025
@kartben kartben reopened this Jul 11, 2025
@github-project-automation github-project-automation bot moved this from Done to Needs more info in Backports Jul 11, 2025
@sonarqubecloud
Copy link

@kartben
Copy link
Contributor

kartben commented Jul 22, 2025

Zephyr 4.0 branch is EOL

@kartben kartben closed this Jul 22, 2025
@github-project-automation github-project-automation bot moved this from Needs more info to Done in Backports Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Kernel Backport Backport PR and backport failure issues

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants