This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH][BZ #13601] Retry read in ld.so if the entire ELF header isnot read in
- From: Siddhesh Poyarekar <siddhesh at redhat dot com>
- To: libc-alpha at sourceware dot org
- Date: Fri, 19 Oct 2012 20:14:44 +0530
- Subject: [PATCH][BZ #13601] Retry read in ld.so if the entire ELF header isnot read in
Hi,
We currently assume that the operation to read in the DSO in
open_verify always reads in the entire ELF header. This assumption is
wrong since the read syscall is free to return smaller chunks of data
and we ought to continue reading if that happens. Attached patch does
exactly that. I have verified that there are no regressions resulting
from this patch on x86_64 F-16, but I don't have a way to verify that
the split read works. OK to commit?
Regards,
Siddhesh
ChangeLog:
* elf/dl-load.c (open_verify): Retry read if the entire ELF
header is not read in.
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 0bfa74a..4b57879 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1722,10 +1722,20 @@ open_verify (const char *name, struct filebuf *fbp, struct link_map *loader,
/* We successfully openened the file. Now verify it is a file
we can use. */
__set_errno (0);
- fbp->len = __libc_read (fd, fbp->buf, sizeof (fbp->buf));
+ fbp->len = 0;
+ assert (sizeof (fbp->buf) > sizeof (ElfW(Ehdr)));
+ /* Read in the header. */
+ do
+ {
+ ssize_t retlen = __libc_read (fd, fbp->buf + fbp->len,
+ sizeof (fbp->buf) - fbp->len);
+ if (retlen <= 0)
+ break;
+ fbp->len += retlen;
+ }
+ while (__builtin_expect (fbp->len < sizeof (ElfW(Ehdr)), 0));
/* This is where the ELF header is loaded. */
- assert (sizeof (fbp->buf) > sizeof (ElfW(Ehdr)));
ehdr = (ElfW(Ehdr) *) fbp->buf;
/* Now run the tests. */