-
Notifications
You must be signed in to change notification settings - Fork 130
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
[Plat-9721] Fix race condition in KSMachHeaders #1529
Conversation
Generated by 🚫 Danger |
a605239
to
7b45362
Compare
BSG_Mach_Header_Info *oldTail = atomic_load(&g_images_tail); | ||
atomic_store(&g_images_tail, newImage); | ||
atomic_store(&oldTail->next, newImage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're missing a CAS operation here to make sure the load/store don't race?
Something like:
BSG_Mach_Header_Info *oldTail = atomic_load(&g_images_tail); | |
atomic_store(&g_images_tail, newImage); | |
atomic_store(&oldTail->next, newImage); | |
BSG_Mach_Header_Info *oldTail = atomic_load(&g_images_tail); | |
for(;;) { | |
if(atomic_compare_exchange_strong(&g_images_tail, &oldTail, newImage)) { | |
atomic_store(&oldTail->next, newImage); | |
break; | |
} | |
} |
7b45362
to
845f2e2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Goal
This PR fixes some race conditions in KSMachHeaders
Changeset
bsg_mach_headers_get_images()
.Testing
Updated unit tests to capture more edge cases.