mmap'ed robust mutexes and possible undefined behaviour

Marcos Dione mdione@grulic.org.ar
Mon Nov 24 20:34:00 GMT 2014


        Hello everybody. First of all, I'm not subscribed to the mailing 
list, so please CC me any responses.

        We found a situation where a robust mutex cannot be recovered
from a stale lock and we're wondering if it's simply an undefined
situation or  a bug in the kernel. Attached you will find the sample
code, which is loosely based on a glibc's test case.The gist of it is as
follows:

1. we open a file.
2. we mmap it and use that mem to store a robust mutex.
3. we lock the mutex.
4. we munmap the file.
5. we close the file.

        The example does steps 1 and 2, then creates creates tw children
who will try  to do steps 3 to 5. Of course only one gets the lock while
the other waits. If the child who  has the lock does the 4th step, then
the other child never recovers the stale lock. In any  other situation
(that is, commenting/removing the code) it works fine.

    This looks suspiciously like undefined behaviour, because it's like
we're pulling  the rug from under the mutex' feet, but in the other hand
looks like a kernel bug because  it doesn't really recover from the
situation. What do you think? 

-- 
(Not so) Random fortune:
22:22 < m4rgin4l_> hendrix no tocaba la viola, violaba la toca
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mmap_robust_mutex.c
Type: text/x-csrc
Size: 2581 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-help/attachments/20141124/2e60d57f/attachment.bin>


More information about the Libc-help mailing list