diff options
author | Paul Pluzhnikov <ppluzhnikov@google.com> | 2018-05-05 18:08:27 -0700 |
---|---|---|
committer | Paul Pluzhnikov <ppluzhnikov@google.com> | 2018-05-05 18:08:27 -0700 |
commit | 0065aaaaae51cd60210ec3a7e13dddd8e01ffe2c (patch) | |
tree | fb1f587dbe38029797cdf5b3779b51b7cea3d680 /elf/dl-load.c | |
parent | b289cd9db8286fa6c670104dd5dfcfc68d5d00d6 (diff) | |
download | glibc-0065aaaaae51cd60210ec3a7e13dddd8e01ffe2c.tar.gz glibc-0065aaaaae51cd60210ec3a7e13dddd8e01ffe2c.tar.xz glibc-0065aaaaae51cd60210ec3a7e13dddd8e01ffe2c.zip |
Fix BZ 20419. A PT_NOTE in a binary could be arbitratily large, so using
alloca for it may cause stack overflow. If the note is larger than __MAX_ALLOCA_CUTOFF, use dynamically allocated memory to read it in. 2018-05-05 Paul Pluzhnikov <ppluzhnikov@google.com> [BZ #20419] * elf/dl-load.c (open_verify): Fix stack overflow. * elf/Makefile (tst-big-note): New test. * elf/tst-big-note-lib.S: New. * elf/tst-big-note.c: New.
Diffstat (limited to 'elf/dl-load.c')
-rw-r--r-- | elf/dl-load.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/elf/dl-load.c b/elf/dl-load.c index a5e3a25462..431236920f 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1462,6 +1462,7 @@ open_verify (const char *name, int fd, ElfW(Ehdr) *ehdr; ElfW(Phdr) *phdr, *ph; ElfW(Word) *abi_note; + ElfW(Word) *abi_note_malloced = NULL; unsigned int osversion; size_t maplength; @@ -1633,10 +1634,25 @@ open_verify (const char *name, int fd, abi_note = (void *) (fbp->buf + ph->p_offset); else { - abi_note = alloca (size); + /* Note: __libc_use_alloca is not usable here, because + thread info may not have been set up yet. */ + if (size < __MAX_ALLOCA_CUTOFF) + abi_note = alloca (size); + else + { + /* There could be multiple PT_NOTEs. */ + abi_note_malloced = realloc (abi_note_malloced, size); + if (abi_note_malloced == NULL) + goto read_error; + + abi_note = abi_note_malloced; + } __lseek (fd, ph->p_offset, SEEK_SET); if (__libc_read (fd, (void *) abi_note, size) != size) - goto read_error; + { + free (abi_note_malloced); + goto read_error; + } } while (memcmp (abi_note, &expected_note, sizeof (expected_note))) @@ -1671,6 +1687,7 @@ open_verify (const char *name, int fd, break; } + free (abi_note_malloced); } return fd; |