2012-02-03 18:03:58 +00:00
|
|
|
diff -rup a/elf/dl-load.c b/elf/dl-load.c
|
|
|
|
--- a/elf/dl-load.c 2012-02-03 10:59:58.917870716 -0700
|
|
|
|
+++ b/elf/dl-load.c 2012-02-03 11:01:01.796580644 -0700
|
2015-07-15 12:19:08 +00:00
|
|
|
@@ -880,7 +880,8 @@ _dl_map_object_from_fd (const char *name, int fd, struct filebuf *fbp,
|
|
|
|
|
|
|
|
/* Get file information. */
|
|
|
|
struct r_file_id id;
|
|
|
|
- if (__glibc_unlikely (!_dl_get_file_id (fd, &id)))
|
|
|
|
+ struct stat64 st;
|
|
|
|
+ if (__glibc_unlikely (!_dl_get_file_id (fd, &id, &st)))
|
|
|
|
{
|
|
|
|
errstring = N_("cannot stat shared object");
|
|
|
|
call_lose_errno:
|
2012-02-03 18:03:58 +00:00
|
|
|
@@ -1130,6 +1130,16 @@ _dl_map_object_from_fd (const char *name
|
|
|
|
= N_("ELF load command address/offset not properly aligned");
|
|
|
|
goto call_lose;
|
|
|
|
}
|
2014-04-10 16:10:30 +00:00
|
|
|
+ if (__glibc_unlikely (ph->p_offset + ph->p_filesz > st.st_size))
|
2012-02-03 18:03:58 +00:00
|
|
|
+ {
|
|
|
|
+ /* If the segment requires zeroing of part of its last
|
|
|
|
+ page, we'll crash when accessing the unmapped page.
|
|
|
|
+ There's still a possibility of a race, if the shared
|
|
|
|
+ object is truncated between the fxstat above and the
|
|
|
|
+ memset below. */
|
|
|
|
+ errstring = N_("ELF load command past end of file");
|
|
|
|
+ goto call_lose;
|
|
|
|
+ }
|
|
|
|
|
2014-04-10 16:10:30 +00:00
|
|
|
struct loadcmd *c = &loadcmds[nloadcmds++];
|
2012-02-03 18:03:58 +00:00
|
|
|
c->mapstart = ph->p_vaddr & ~(GLRO(dl_pagesize) - 1);
|
2015-07-15 12:19:08 +00:00
|
|
|
diff --git a/sysdeps/generic/dl-fileid.h b/sysdeps/generic/dl-fileid.h
|
|
|
|
index 2cbd21d..9b7f410 100644
|
|
|
|
--- a/sysdeps/generic/dl-fileid.h
|
|
|
|
+++ b/sysdeps/generic/dl-fileid.h
|
|
|
|
@@ -29,7 +29,8 @@ struct r_file_id
|
|
|
|
On error, returns false, with errno set. */
|
|
|
|
static inline bool
|
|
|
|
_dl_get_file_id (int fd __attribute__ ((unused)),
|
|
|
|
- struct r_file_id *id __attribute__ ((unused)))
|
|
|
|
+ struct r_file_id *id __attribute__ ((unused)),
|
|
|
|
+ struct stat64_t *st __attribute__((unused)))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
diff --git a/sysdeps/posix/dl-fileid.h b/sysdeps/posix/dl-fileid.h
|
|
|
|
index d0d5436..7115c3b 100644
|
|
|
|
--- a/sysdeps/posix/dl-fileid.h
|
|
|
|
+++ b/sysdeps/posix/dl-fileid.h
|
|
|
|
@@ -27,18 +27,16 @@ struct r_file_id
|
|
|
|
ino64_t ino;
|
|
|
|
};
|
|
|
|
|
|
|
|
-/* Sample FD to fill in *ID. Returns true on success.
|
|
|
|
+/* Sample FD to fill in *ID and *ST. Returns true on success.
|
|
|
|
On error, returns false, with errno set. */
|
|
|
|
static inline bool
|
|
|
|
-_dl_get_file_id (int fd, struct r_file_id *id)
|
|
|
|
+_dl_get_file_id (int fd, struct r_file_id *id, struct stat64 *st)
|
|
|
|
{
|
|
|
|
- struct stat64 st;
|
|
|
|
-
|
|
|
|
- if (__glibc_unlikely (__fxstat64 (_STAT_VER, fd, &st) < 0))
|
|
|
|
+ if (__glibc_unlikely (__fxstat64 (_STAT_VER, fd, st) < 0))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
- id->dev = st.st_dev;
|
|
|
|
- id->ino = st.st_ino;
|
|
|
|
+ id->dev = st->st_dev;
|
|
|
|
+ id->ino = st->st_ino;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|