From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 41F903858C74; Fri, 3 Nov 2023 18:46:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 41F903858C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1699037198; bh=paqt2KpwmSG+q1ozpSQjuIlOTRcahKeApy6hPB7z+1k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=lD/Zb0Ef5L04gjG3abBZnStY2d9Fy7lu24gX0rPL4nYAGOv1hyeTkq5W6ehmPmDEK FRUejHRSSYGfxlXAM3uMu6tr3BA+zobTIs8tP4wkPSZPR33WP6NdgvC1bQvD+ao5d5 qL8rXOoXvgx6tQmj0IHmJ1PWBhN+n07O29EE5kg0= From: "cvs-commit at gcc dot gnu.org" To: glibc-bugs@sourceware.org Subject: [Bug libc/30789] [2.38 Regression] sem_open will fail on multithreaded scenarios when semaphore file doesn't exist (O_CREAT) Date: Fri, 03 Nov 2023 18:46:37 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: libc X-Bugzilla-Version: 2.38 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D30789 --- Comment #3 from cvs-commit at gcc dot gnu.org --- The master branch has been updated by Adhemerval Zanella : https://sourceware.org/git/gitweb.cgi?p=3Dglibc.git;h=3Df957f47df75b9fab995= 754011491edebc6feb147 commit f957f47df75b9fab995754011491edebc6feb147 Author: Sergio Durigan Junior Date: Wed Nov 1 18:15:23 2023 -0400 sysdeps: sem_open: Clear O_CREAT when semaphore file is expected to exi= st [BZ #30789] When invoking sem_open with O_CREAT as one of its flags, we'll end up in the second part of sem_open's "if ((oflag & O_CREAT) =3D=3D 0 || (of= lag & O_EXCL) =3D=3D 0)", which means that we don't expect the semaphore fi= le to exist. In that part, open_flags is initialized as "O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC" and there's an attempt to open(2) the file, which will likely fail because it won't exist. After that first (expected) failure, some cleanup is done and we go back to the label "try_again", which lives in the first part of the aforementioned "if". The problem is that, in that part of the code, we expect the semaphore file to exist, and as such O_CREAT (this time the flag we pass to open(2)) needs to be cleaned from open_flags, otherwise we'll see another failure (this time unexpected) when trying to open the file, which will lead the call to sem_open to fail as well. This can cause very strange bugs, especially with OpenMPI, which makes extensive use of semaphores. Fix the bug by simplifying the logic when choosing open(2) flags and making sure O_CREAT is not set when the semaphore file is expected to exist. A regression test for this issue would require a complex and cpu time consuming logic, since to trigger the wrong code path is not straightforward due the racy condition. There is a somewhat reliable reproducer in the bug, but it requires using OpenMPI. This resolves BZ #30789. See also: https://bugs.launchpad.net/ubuntu/+source/h5py/+bug/2031912 Signed-off-by: Sergio Durigan Junior Co-Authored-By: Simon Chopin Co-Authored-By: Adhemerval Zanella Netto Fixes: 533deafbdf189f5fbb280c28562dd43ace2f4b0f ("Use O_CLOEXEC in more places (BZ #15722)") --=20 You are receiving this mail because: You are on the CC list for the bug.=