about summary refs log tree commit diff
path: root/elf
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2023-04-19 19:02:03 +0300
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-04-22 13:50:14 +0200
commit533deafbdf189f5fbb280c28562dd43ace2f4b0f (patch)
tree292d1cf07d52199a9dd247c6bb06f5566c218855 /elf
parent28a441cc577e31e95742b9ec5f1737b86749b712 (diff)
downloadglibc-533deafbdf189f5fbb280c28562dd43ace2f4b0f.tar.gz
glibc-533deafbdf189f5fbb280c28562dd43ace2f4b0f.tar.xz
glibc-533deafbdf189f5fbb280c28562dd43ace2f4b0f.zip
Use O_CLOEXEC in more places (BZ #15722)
When opening a temporary file without O_CLOEXEC we risk leaking the
file descriptor if another thread calls (fork and then) exec while we
have the fd open. Fix this by consistently passing O_CLOEXEC everywhere
where we open a file for internal use (and not to return it to the user,
in which case the API defines whether or not the close-on-exec flag
shall be set on the returned fd).

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-Id: <20230419160207.65988-4-bugaevc@gmail.com>
Diffstat (limited to 'elf')
-rw-r--r--elf/dl-profile.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/elf/dl-profile.c b/elf/dl-profile.c
index 2ecac05f8d..d8345da22e 100644
--- a/elf/dl-profile.c
+++ b/elf/dl-profile.c
@@ -324,7 +324,8 @@ _dl_start_profile (void)
   *cp++ = '/';
   __stpcpy (__stpcpy (cp, GLRO(dl_profile)), ".profile");
 
-  fd = __open64_nocancel (filename, O_RDWR|O_CREAT|O_NOFOLLOW, DEFFILEMODE);
+  fd = __open64_nocancel (filename, O_RDWR | O_CREAT | O_NOFOLLOW
+			  | O_CLOEXEC, DEFFILEMODE);
   if (fd == -1)
     {
       char buf[400];