From 09d9859c80b272fe64b76f028e72ecadfd7f8f76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20B=C3=A9rat?= Date: Fri, 10 Jan 2025 19:00:11 +0100 Subject: [PATCH] Avoid uninitialized result in sem_open when file does not exist Resolves: RHEL-69633 --- glibc-RHEL-69633-1.patch | 87 ++++++++++++++++++++++++++++++++++++++++ glibc-RHEL-69633-2.patch | 45 +++++++++++++++++++++ glibc.spec | 3 ++ 3 files changed, 135 insertions(+) create mode 100644 glibc-RHEL-69633-1.patch create mode 100644 glibc-RHEL-69633-2.patch diff --git a/glibc-RHEL-69633-1.patch b/glibc-RHEL-69633-1.patch new file mode 100644 index 0000000..bfe625f --- /dev/null +++ b/glibc-RHEL-69633-1.patch @@ -0,0 +1,87 @@ +commit f745d78e2628cd5b13ca119ae0c0e21d08ad1906 +Author: Joseph Myers +Date: Fri Nov 8 01:53:48 2024 +0000 + + Avoid uninitialized result in sem_open when file does not exist + + A static analyzer apparently reported an uninitialized use of the + variable result in sem_open in the case where the file is required to + exist but does not exist. + + The report appears to be correct; set result to SEM_FAILED in that + case, and add a test for it. + + Note: the test passes for me even without the sem_open fix, I guess + because result happens to get value SEM_FAILED (i.e. 0) when + uninitialized. + + Tested for x86_64. + +Conflicts: + sysdeps/pthread/Makefile (new test added) + +diff --git a/sysdeps/pthread/Makefile b/sysdeps/pthread/Makefile +index 2d4cb1ac62d15f4c..de8b66bc3b6bf6ad 100644 +--- a/sysdeps/pthread/Makefile ++++ b/sysdeps/pthread/Makefile +@@ -128,6 +128,7 @@ tests += tst-cnd-basic tst-mtx-trylock tst-cnd-broadcast \ + tst-pthread_kill-exiting \ + tst-cancel30 \ + tst-spin5 \ ++ tst-sem17 \ + tst-sem19 \ + tst-join16 \ + # tests +diff --git a/sysdeps/pthread/sem_open.c b/sysdeps/pthread/sem_open.c +index 770ab17cdbb47b83..124d95dce4186ae7 100644 +--- a/sysdeps/pthread/sem_open.c ++++ b/sysdeps/pthread/sem_open.c +@@ -75,6 +75,7 @@ __sem_open (const char *name, int oflag, ...) + goto try_create; + + /* Return. errno is already set. */ ++ result = SEM_FAILED; + } + else + /* Check whether we already have this semaphore mapped and +diff --git a/sysdeps/pthread/tst-sem17.c b/sysdeps/pthread/tst-sem17.c +new file mode 100644 +index 0000000000000000..c3f05d196f4ef17a +--- /dev/null ++++ b/sysdeps/pthread/tst-sem17.c +@@ -0,0 +1,35 @@ ++/* Test sem_open with missing file. ++ Copyright (C) 2024 Free Software Foundation, Inc. ++ This file is part of the GNU C Library. ++ ++ The GNU C Library is free software; you can redistribute it and/or ++ modify it under the terms of the GNU Lesser General Public ++ License as published by the Free Software Foundation; either ++ version 2.1 of the License, or (at your option) any later version. ++ ++ The GNU C Library is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ Lesser General Public License for more details. ++ ++ You should have received a copy of the GNU Lesser General Public ++ License along with the GNU C Library; if not, see ++ . */ ++ ++#include ++#include ++ ++#include ++ ++int ++do_test (void) ++{ ++ sem_unlink ("/glibc-tst-sem17"); ++ errno = 0; ++ sem_t *s = sem_open ("/glibc-tst-sem17", 0); ++ TEST_VERIFY (s == SEM_FAILED); ++ TEST_COMPARE (errno, ENOENT); ++ return 0; ++} ++ ++#include diff --git a/glibc-RHEL-69633-2.patch b/glibc-RHEL-69633-2.patch new file mode 100644 index 0000000..9bc9060 --- /dev/null +++ b/glibc-RHEL-69633-2.patch @@ -0,0 +1,45 @@ +commit c7dcf594f4c52fa7e2cc76918c8aa9abb98e9625 +Author: Joseph Myers +Date: Fri Nov 8 17:08:09 2024 +0000 + + Rename new tst-sem17 test to tst-sem18 + + As noted by Adhemerval, we already have a tst-sem17 in nptl. + + Tested for x86_64. + +Conflicts: + sysdeps/pthread/Makefile (renamed test) + +diff --git a/sysdeps/pthread/Makefile b/sysdeps/pthread/Makefile +index de8b66bc3b6bf6ad..43fcdf1182e735e1 100644 +--- a/sysdeps/pthread/Makefile ++++ b/sysdeps/pthread/Makefile +@@ -128,7 +128,7 @@ tests += tst-cnd-basic tst-mtx-trylock tst-cnd-broadcast \ + tst-pthread_kill-exiting \ + tst-cancel30 \ + tst-spin5 \ +- tst-sem17 \ ++ tst-sem18 \ + tst-sem19 \ + tst-join16 \ + # tests +diff --git a/sysdeps/pthread/tst-sem17.c b/sysdeps/pthread/tst-sem18.c +similarity index 92% +rename from sysdeps/pthread/tst-sem17.c +rename to sysdeps/pthread/tst-sem18.c +index c3f05d196f4ef17a..1be207bcbeeb56f1 100644 +--- a/sysdeps/pthread/tst-sem17.c ++++ b/sysdeps/pthread/tst-sem18.c +@@ -24,9 +24,9 @@ + int + do_test (void) + { +- sem_unlink ("/glibc-tst-sem17"); ++ sem_unlink ("/glibc-tst-sem18"); + errno = 0; +- sem_t *s = sem_open ("/glibc-tst-sem17", 0); ++ sem_t *s = sem_open ("/glibc-tst-sem18", 0); + TEST_VERIFY (s == SEM_FAILED); + TEST_COMPARE (errno, ENOENT); + return 0; diff --git a/glibc.spec b/glibc.spec index be2c2a0..259b7b3 100644 --- a/glibc.spec +++ b/glibc.spec @@ -1072,6 +1072,8 @@ Patch764: glibc-RHEL-58989-2.patch Patch765: glibc-RHEL-62716-1.patch Patch766: glibc-RHEL-62716-2.patch Patch767: glibc-RHEL-68857.patch +Patch768: glibc-RHEL-69633-1.patch +Patch769: glibc-RHEL-69633-2.patch ############################################################################## # Continued list of core "glibc" package information: @@ -3069,6 +3071,7 @@ update_gconv_modules_cache () - Additional TLS test cases (RHEL-58989) - Additional mremap test cases (RHEL-62716) - Fix pthread_timedjoin_np error handling and increase test coverage (RHEL-68857) +- Avoid uninitialized result in sem_open when file does not exist (RHEL-69633) * Fri Jan 10 2025 Frédéric Bérat - 2.34-151 - Lock all stdio streams during exit