From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_LOW,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 16525 invoked from network); 26 May 2023 02:38:56 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 26 May 2023 02:38:56 -0000 Received: (qmail 16190 invoked by uid 550); 26 May 2023 02:38:53 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 16152 invoked from network); 26 May 2023 02:38:52 -0000 Date: Thu, 25 May 2023 22:38:39 -0400 From: Rich Felker To: Markus Wichmann Cc: musl@lists.openwall.com Message-ID: <20230526023839.GK4163@brightrain.aerifal.cx> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] vm lock needed in mprotect? 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