Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/mbox: fix race condition #18955

Merged
merged 1 commit into from
Nov 23, 2022
Merged

Conversation

maribu
Copy link
Member

@maribu maribu commented Nov 22, 2022

Contribution description

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.

Testing procedure

Actually triggering the race condition would require some effort with a specially crafted test application, which I am unable to currently provide. It should however be quite easy to reason that the change fixes the potential race condition.

In addition, the usual regression tests may make sense.

Issues/PRs references

None

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.
@maribu maribu added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: core Area: RIOT kernel. Handle PRs marked with this with care! Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch labels Nov 22, 2022
@maribu maribu requested a review from kaspar030 as a code owner November 22, 2022 21:42
Copy link
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK.

@kaspar030 kaspar030 enabled auto-merge November 22, 2022 21:43
@maribu maribu added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Nov 23, 2022
@aabadie aabadie added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Nov 23, 2022
@riot-ci
Copy link

riot-ci commented Nov 23, 2022

Murdock results

✔️ PASSED

42b9334 core/mbox: fix race condition

Success Failures Total Runtime
117849 0 117849 01h:54m:09s

Artifacts

@kaspar030 kaspar030 merged commit ad5f02d into RIOT-OS:master Nov 23, 2022
@maribu maribu deleted the core/mbox/fix-race branch November 23, 2022 14:09
@maribu
Copy link
Member Author

maribu commented Nov 23, 2022

Thx :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: core Area: RIOT kernel. Handle PRs marked with this with care! CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants