Skip to content

Commit

Permalink
core/mbox: fix race condition
Browse files Browse the repository at this point in the history
The mbox code contains a race condition in `mbox_put()`: When it
waits for a slot in the queue to become available, it is woken up with
IRQs enabled. It disables IRQs again as first thing, but by then
another thread may already have preempted the running thread and filled
the queue back up. In this case, a message in the queue would be
silently overwritten.

(cherry picked from commit 42b9334)
  • Loading branch information
maribu authored and benpicco committed Nov 23, 2022
1 parent 70495b1 commit 75e34b3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion core/mbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int _mbox_put(mbox_t *mbox, msg_t *msg, int blocking)
return 1;
}
else {
if (cib_full(&mbox->cib)) {
while (cib_full(&mbox->cib)) {
if (blocking) {
_wait(&mbox->writers, irqstate);
irqstate = irq_disable();
Expand Down

0 comments on commit 75e34b3

Please sign in to comment.