mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Markus Wichmann <nullplan@gmx.net>
Cc: musl@lists.openwall.com
Subject: Re: [musl] vm lock needed in mprotect?
Date: Thu, 25 May 2023 22:38:39 -0400	[thread overview]
Message-ID: <20230526023839.GK4163@brightrain.aerifal.cx> (raw)
In-Reply-To: <ZG+Sfzr1ZK0FQ1W/@voyager>

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

      reply	other threads:[~2023-05-26  2:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-25 16:53 Markus Wichmann
2023-05-26  2:38 ` Rich Felker [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230526023839.GK4163@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    --cc=nullplan@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).