mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] vm lock needed in mprotect?
@ 2023-05-25 16:53 Markus Wichmann
  2023-05-26  2:38 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Markus Wichmann @ 2023-05-25 16:53 UTC (permalink / raw)
  To: musl

Hi all,

I'm wondering if the vm lock is needed in mprotect(), similar to
munmap(). Reason for the vm lock was that if an application had two
threads waiting on a process-shared barrier, and one thread came out of
it to immediately unmap the SHM segment, then the other thread might not
yet have had a change to exit pthread_barrier_wait(), and since that
function accesses the barrier object after the last futex wait call, it
would crash.

So what if that first thread, instead of unmapping the SHM, just changes
its protection to read-only? That would also crash. Or is that somehow
not valid? If so, why?

Ciao,
Markus

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [musl] vm lock needed in mprotect?
  2023-05-25 16:53 [musl] vm lock needed in mprotect? Markus Wichmann
@ 2023-05-26  2:38 ` Rich Felker
  0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2023-05-26  2:38 UTC (permalink / raw)
  To: Markus Wichmann; +Cc: musl

On Thu, May 25, 2023 at 06:53:19PM +0200, Markus Wichmann wrote:
> Hi all,
> 
> I'm wondering if the vm lock is needed in mprotect(), similar to
> munmap(). Reason for the vm lock was that if an application had two
> threads waiting on a process-shared barrier, and one thread came out of
> it to immediately unmap the SHM segment, then the other thread might not
> yet have had a change to exit pthread_barrier_wait(), and since that
> function accesses the barrier object after the last futex wait call, it
> would crash.
> 
> So what if that first thread, instead of unmapping the SHM, just changes
> its protection to read-only? That would also crash. Or is that somehow
> not valid? If so, why?

Thanks! I'll have to think about it more, but offhand I think your
reasoning is correct for pthread_barrier_wait. We might want to
reconsider whether this use of vm_lock is needed or if there's another
way to do things. The essential use that can't be eliminated is
handling the pending slot for robust mutexes, and that use is not
subject to the issue you're asking about.

Rich

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-26  2:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-25 16:53 [musl] vm lock needed in mprotect? Markus Wichmann
2023-05-26  2:38 ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).