public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] Ensure standard file descriptors are open on start
@ 2020-08-19 12:41 Arsen Arsenović
  2020-08-19 16:28 ` Joseph Myers
  0 siblings, 1 reply; 21+ messages in thread
From: Arsen Arsenović @ 2020-08-19 12:41 UTC (permalink / raw)
  To: libc-alpha

ISO C requires that standard input, output and error are always open on
program startup.
---
I've removed the changes to the access mode used when opening the three standard
file descriptors, to address Paul's concerns.

 csu/check_fds.c  | 4 ++--
 csu/libc-start.c | 9 +++------
 elf/dl-sysdep.c  | 7 ++-----
 3 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/csu/check_fds.c b/csu/check_fds.c
index 30634b81..d2bca0a3 100644
--- a/csu/check_fds.c
+++ b/csu/check_fds.c
@@ -58,8 +58,8 @@ check_one_fd (int fd, int mode)
 	}
 
       /* Something is wrong with this descriptor, it's probably not
-	 opened.  Open /dev/null so that the SUID program we are
-	 about to start does not accidentally use this descriptor.  */
+	 opened.  Open /dev/null so that the program we are about to
+	 start does not accidentally use this descriptor.  */
       int nullfd = __open_nocancel (name, mode, 0);
 
       /* We are very paranoid here.  With all means we try to ensure
diff --git a/csu/libc-start.c b/csu/libc-start.c
index 4005caf8..f99efda0 100644
--- a/csu/libc-start.c
+++ b/csu/libc-start.c
@@ -253,12 +253,9 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
   if (fini)
     __cxa_atexit ((void (*) (void *)) fini, NULL, NULL);
 
-  /* Some security at this point.  Prevent starting a SUID binary where
-     the standard file descriptors are not opened.  We have to do this
-     only for statically linked applications since otherwise the dynamic
-     loader did the work already.  */
-  if (__builtin_expect (__libc_enable_secure, 0))
-    __libc_check_standard_fds ();
+  /* Ensure the standard streams are opened, as required by POSIX and C. For
+     dynamic programs this is already handled in the dynamic loader.  */
+  __libc_check_standard_fds ();
 #endif
 
   /* Call the initializer of the program, if any.  */
diff --git a/elf/dl-sysdep.c b/elf/dl-sysdep.c
index 85457082..83070413 100644
--- a/elf/dl-sysdep.c
+++ b/elf/dl-sysdep.c
@@ -243,11 +243,8 @@ _dl_sysdep_start (void **start_argptr,
     __sbrk (GLRO(dl_pagesize)
 	    - ((_end - (char *) 0) & (GLRO(dl_pagesize) - 1)));
 
-  /* If this is a SUID program we make sure that FDs 0, 1, and 2 are
-     allocated.  If necessary we are doing it ourself.  If it is not
-     possible we stop the program.  */
-  if (__builtin_expect (__libc_enable_secure, 0))
-    __libc_check_standard_fds ();
+  /* Ensure all the standard streams are open (C and POSIX require this) */
+  __libc_check_standard_fds ();
 
   (*dl_main) (phdr, phnum, &user_entry, GLRO(dl_auxv));
   return user_entry;
-- 
2.26.2


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2020-09-11  7:47 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-19 12:41 [PATCH v2] Ensure standard file descriptors are open on start Arsen Arsenović
2020-08-19 16:28 ` Joseph Myers
2020-08-19 17:46   ` Zack Weinberg
2020-08-19 17:50     ` Joseph Myers
2020-08-19 18:20     ` Adhemerval Zanella
2020-08-19 19:13       ` Florian Weimer
2020-08-19 19:25         ` Adhemerval Zanella
2020-08-19 19:27           ` Florian Weimer
2020-08-19 19:35             ` Adhemerval Zanella
2020-08-19 19:40   ` Arsen Arsenović
2020-08-19 21:04     ` Michael Morrell
2020-08-19 22:32     ` Joseph Myers
2020-08-19 23:45       ` Arsen Arsenović
2020-08-20 22:00         ` Paul Eggert
2020-08-20 23:25           ` Arsen Arsenović
2020-08-27 15:56           ` Zack Weinberg
2020-08-27 18:21             ` Paul Eggert
2020-08-28  0:12               ` Arsen Arsenović
2020-09-04 17:49                 ` Arsen Arsenović
2020-09-11  7:47                 ` ping^2 " Arsen Arsenović
2020-08-19 23:16     ` Rich Felker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).