Move FD check to dl-sysdep.c
Mark Kettenis
kettenis@wins.uva.nl
Sun Jul 9 10:58:00 GMT 2000
The following patch moves the call to __libc_check_standard_fds() from
elf/rtld.c:dl_main() to sysdeps/generic/dl-sysdep.c:_dl_sysdep_start(),
just before the call to dl_main(). It would really help the Hurd if
this could be applied. The presence of the
__libc_check_standard_fds() call in dl_main() prevents me from writing
an elegant solution to check the FDs on the Hurd.
The Hurd doesn't need to call __libc_check_standard_fds(). The
concept of file descriptors doesn't exist outside libc, and we'd
better check the file descriptors right when we build the file
descriptor table for the Hurd. I'll check in a Hurd-specific
check_fds.c that takes care of that in the near future.
I think that sysdeps/generic/dl-sysdep.c conceptually is the right
place to put the call. The need for __libc_check_standard_fds() is
related to the way file descriptors behave in a generic Unix system.
Mark
2000-07-09 Mark Kettenis <kettenis@gnu.org>
* elf/rtld.c (dl_main): Move call to __libc_check_standard_fds...
* sysdeps/generic/dl-sysdep.c (_dl_sysdep_start): ... to here.
Index: elf/rtld.c
===================================================================
RCS file: /cvs/glibc/libc/elf/rtld.c,v
retrieving revision 1.173
diff -u -p -r1.173 rtld.c
--- elf/rtld.c 2000/06/10 03:58:55 1.173
+++ elf/rtld.c 2000/07/09 17:45:48
@@ -52,9 +52,6 @@ extern void *_dl_sysdep_read_whole_file
size_t *filesize_ptr,
int mmap_prot);
-/* Protec SUID program against misuse of file descriptors. */
-extern void __libc_check_standard_fds (void);
-
/* Helper function to handle errors while resolving symbols. */
static void print_unresolved (int errcode, const char *objname,
const char *errsting);
@@ -399,12 +396,6 @@ dl_main (const ElfW(Phdr) *phdr,
hp_timing_t stop;
hp_timing_t diff;
#endif
-
- /* First thing, 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 ();
/* Process the environment variable which control the behaviour. */
process_envvars (&mode, &_dl_lazy);
Index: sysdeps/generic/dl-sysdep.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/generic/dl-sysdep.c,v
retrieving revision 1.50
diff -u -p -r1.50 dl-sysdep.c
--- sysdeps/generic/dl-sysdep.c 2000/03/23 20:28:06 1.50
+++ sysdeps/generic/dl-sysdep.c 2000/07/09 17:45:48
@@ -45,6 +45,9 @@ extern fpu_control_t _dl_fpu_control;
extern void _end;
extern void ENTRY_POINT (void);
+/* Protect SUID program against misuse of file descriptors. */
+extern void __libc_check_standard_fds (void);
+
ElfW(Addr) _dl_base_addr;
int __libc_enable_secure;
int __libc_multiple_libcs = 0; /* Defining this here avoids the inclusion
@@ -166,6 +169,12 @@ _dl_sysdep_start (void **start_argptr,
break up that far. When the user program examines its break, it
will see this new value and not clobber our data. */
__sbrk (_dl_pagesize - ((&_end - (void *) 0) & (_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 ();
(*dl_main) (phdr, phnum, &user_entry);
return user_entry;
More information about the Libc-hacker
mailing list