Summary: | Signals can lead to an inconsistency in PI mutex ownership | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Product: | Base System | Reporter: | eric | ||||||||||||||||
Component: | kern | Assignee: | Eric van Gyzen <vangyzen> | ||||||||||||||||
Status: | Closed FIXED | ||||||||||||||||||
Severity: | Affects Some People | CC: | dab, emaste, kib, vangyzen | ||||||||||||||||
Priority: | --- | ||||||||||||||||||
Version: | CURRENT | ||||||||||||||||||
Hardware: | Any | ||||||||||||||||||
OS: | Any | ||||||||||||||||||
Attachments: |
|
Description
eric
2015-02-24 21:20:00 UTC
Created attachment 153475 [details]
Proposed patch
With this patch, all of my tests pass. Created attachment 153476 [details]
Patch to restore owner after umtx_pi_claim fails
Created attachment 153477 [details]
Patch to return errors from _thr_umutex_unlock2
Here are two more patches to fix minor issues that I found during this bug-hunt. Created attachment 153485 [details]
Deterministic test case
Created attachment 153486 [details]
Randomized, racy test case
Created attachment 153487 [details]
Test case for r277970
This is a test case for the bug fixed by r277970. I'm attaching it here just for reference and completeness. The present bug is the reason that I found the one fixed by r277970. (There is no Bugzilla bug for it.)
I agree with all three patches, with one detail. In the first patch, which does umtx_pi_disown() for empty queue, shouldn't the case of pi->pi_owner != curthread be handled the same as it is done in the non-empty queue case ? The 'might' condition from the the comment really means that the umutex and the kernel state are un-synchronized, and the 'userland messed the mutex' situation is applicable in the same way there. I considered this, but I'm indecisive. The current "userland messed the mutex" error path compounds the problem by leaving the umutex owned by the current thread, while libthr already disowned the pthread_mutex. I wonder if it should disown the umutex. This might allow the mutex owner fields to regain consistency. On the other hand, maybe we should let it stay inconsistent to make the failure more permanent; this might prevent the application from corrupting its state even further. Regardless, you're right that the empty case should be consistent with the non-empty case when another thread owns the umtx_pi, since I believe this is still an error. Note that the umtx_pi could legitimately be unowned in the empty case, such as immediately after umtx_pi_alloc. I'm testing an updated patch now. (In reply to eric from comment #10) I do not have an opinion which case currently is handled more correctly. I tend to agree with notion that empty case handling of silent ignore of the foreign owner is probably more appropriate. Also, it took me some time to understand how pi_owner could be NULL. Probably, a comment should be added. I also suggest to split the comment in if (pi != NULL) into two. The first sentence should go before if (pi != NULL) test, and the second sentence left as is. (In reply to Konstantin Belousov from comment #11) OK, we can ignore the foreign owner. I've tested that code quite a bit already. I'll change the comments, as you suggest. Created attachment 153524 [details]
Proposed patch
Adjust comments based on Konstantin's feedback.
These fixes were committed by kib@ as r279282, r279283, and r279284. |