glibc/sysdeps
Sergio Durigan Junior 63dbbc5c52 sysdeps: sem_open: Clear O_CREAT when semaphore file is expected to exist [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) == 0 || (oflag
& O_EXCL) == 0)", which means that we don't expect the semaphore file
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 <sergiodj@sergiodj.net>
Co-Authored-By: Simon Chopin <simon.chopin@canonical.com>
Co-Authored-By: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Fixes: 533deafbdf ("Use O_CLOEXEC in more places (BZ #15722)")
(cherry picked from commit f957f47df7)
2023-11-25 21:46:18 +01:00
..
aarch64 configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
alpha configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
arc configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
arm configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
csky configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
generic Revert "elf: Always call destructors in reverse constructor order (bug 30785)" 2023-10-18 14:25:46 +02:00
gnu configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
hppa configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
htl
hurd
i386 i686: Fix build with --disable-multiarch 2023-08-17 23:38:14 +02:00
ia64 configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
ieee754 configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
loongarch configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
m68k configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
mach configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
microblaze configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
mips MIPS: Update mips32 and mip64 libm test ulps 2023-07-25 22:20:57 +02:00
nios2 configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
nptl
or1k configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
posix Fix leak in getaddrinfo introduced by the fix for CVE-2023-4806 [BZ #30843] 2023-09-26 10:14:37 -04:00
powerpc powerpc: Fix powerpc64 strchrnul build with old gcc 2023-07-26 09:45:22 -03:00
pthread sysdeps: sem_open: Clear O_CREAT when semaphore file is expected to exist [BZ #30789] 2023-11-25 21:46:18 +01:00
riscv riscv: Update rvd libm test ulps 2023-07-22 15:55:33 +02:00
s390 configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
sh configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
sparc configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
unix io: Fix record locking contants for powerpc64 with __USE_FILE_OFFSET64 2023-09-07 22:45:43 +02:00
wordsize-32
wordsize-64
x86 x86: Fix incorrect scope of setting `shared_per_thread` [BZ# 30745] 2023-08-12 23:59:04 -05:00
x86_64 x86_64: Fix build with --disable-multiarch (BZ 30721) 2023-08-17 23:37:28 +02:00