From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1792) id 137FA3858C53; Thu, 29 Dec 2022 23:42:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 137FA3858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1672357326; bh=uHMEwgP9lOD2v5+yHKeoHe43+x+lUCfn7nJjMBcLSEg=; h=From:To:Subject:Date:From; b=xJmQB7SiQT8ZOQy9YitkoT4Q0og9aHJcs9dMN42tJC5WD9D+CF0EGl2wMzRRwW+Hm UAY/uPP6GyoNqpgw9j/2HjmLKmbJyVdzwXXUuBBigx3qjLVKZeV8gcD5mV316XiLo2 7TjhHfOqlLQVfqqMIuDIb0MLHoDYAw9EnO7kIGa4= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Samuel Thibault To: glibc-cvs@sourceware.org Subject: [glibc] htl: Fix sem_wait race between read and gsync_wait X-Act-Checkin: glibc X-Git-Author: Samuel Thibault X-Git-Refname: refs/heads/master X-Git-Oldrev: c923cd8c496c7f253f327361a65c737233c7ebbd X-Git-Newrev: 289b098c9e21e2805e3835f9b5780235ab14a290 Message-Id: <20221229234206.137FA3858C53@sourceware.org> Date: Thu, 29 Dec 2022 23:42:06 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=289b098c9e21e2805e3835f9b5780235ab14a290 commit 289b098c9e21e2805e3835f9b5780235ab14a290 Author: Samuel Thibault Date: Fri Dec 30 00:40:18 2022 +0100 htl: Fix sem_wait race between read and gsync_wait If the value changes between sem_wait's read and the gsync_wait call, the kernel will return KERN_INVALID_ARGUMENT, which we have to interpret as the value having already changed. This fixes applications (e.g. libgo) seeing sem_wait erroneously return KERN_INVALID_ARGUMENT. Diff: --- sysdeps/htl/sem-timedwait.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sysdeps/htl/sem-timedwait.c b/sysdeps/htl/sem-timedwait.c index 1b1eec9f59..c610804b08 100644 --- a/sysdeps/htl/sem-timedwait.c +++ b/sysdeps/htl/sem-timedwait.c @@ -79,7 +79,7 @@ __sem_timedwait_internal (sem_t *restrict sem, ((unsigned int *) &sem->data) + SEM_VALUE_OFFSET, 0, flags); - if (err != 0) + if (err != 0 && err != KERN_INVALID_ARGUMENT) { /* Error, interruption or timeout, abort. */ if (err == KERN_TIMEDOUT) @@ -138,7 +138,7 @@ __sem_timedwait_internal (sem_t *restrict sem, err = __lll_wait_intr (&isem->value, SEM_NWAITERS_MASK, flags); - if (err != 0) + if (err != 0 && err != KERN_INVALID_ARGUMENT) { /* Error, interruption or timeout, abort. */ if (err == KERN_TIMEDOUT)