glibc/sysdeps
Sergio Durigan Junior f957f47df7 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)")
2023-11-03 15:19:38 -03:00
..
aarch64 AArch64: Cleanup ifuncs 2023-11-01 13:41:59 +00:00
alpha Remove references to the defunct db2 subdir 2023-08-21 18:20:53 +02: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 string: Add internal memswap implementation 2023-10-31 14:17:33 -03: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 htl: move pthread_attr_setdetachstate into libc 2023-08-24 01:57:22 +02:00
hurd hurd: Fix using interposable hurd_thread_self 2023-05-19 20:45:51 +02:00
i386 i686: Fix build with --disable-multiarch 2023-08-10 10:29:29 -03:00
ia64 configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
ieee754 Avoid maybe-uninitialized warning in __kernel_rem_pio2 2023-10-16 09:59:32 +02:00
loongarch LoongArch: Delete excessively allocated memory. 2023-10-26 17:29:55 +08:00
m68k m68k: Use M68K_SCALE_AVAILABLE on __mpn_lshift and __mpn_rshift 2023-08-25 10:07:24 -03:00
mach Use correct subdir when building tst-rfc3484* for mach and arm 2023-11-01 11:53:03 +01:00
microblaze configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
mips mips: dl-machine-reject-phdr: Get rid of alloca. 2023-10-02 12:55:27 +00:00
nios2 configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
nptl Fix misspellings in sysdeps/ -- BZ 25337 2023-05-30 23:02:29 +00:00
or1k configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
posix Move getaddrinfo from 'posix' into 'nss' 2023-10-24 12:31:00 +02:00
powerpc fegetenv_and_set_rn now uses the builtins provided by GCC. 2023-09-27 13:55:36 -03:00
pthread sysdeps: sem_open: Clear O_CREAT when semaphore file is expected to exist [BZ #30789] 2023-11-03 15:19:38 -03:00
riscv riscv: Add support for XTheadBb in string-fz[a,i].h 2023-09-06 09:27:43 -03:00
s390 s390: Fix undefined behaviour in feenableexcept, fedisableexcept [BZ #30960] 2023-10-19 14:28:22 +02:00
sh configure: Use autoconf 2.71 2023-07-17 10:08:10 -04:00
sparc sparc: Remove optimize md5, sha256, and sha512 2023-10-30 13:03:59 -03:00
unix Add SEGV_CPERR from Linux 6.6 to bits/siginfo-consts.h 2023-11-03 16:36:35 +00:00
wordsize-32 Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
wordsize-64 hurd: Fix tst-writev test 2023-05-01 13:01:30 +02:00
x86 x86: Add support for AVX10 preset and vec size in cpu-features 2023-09-29 14:18:42 -05:00
x86_64 x86: Prepare strrchr-evex and strrchr-evex512 for AVX10 2023-10-06 00:18:55 -05:00