From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7932) id 8A9383858024; Mon, 2 Oct 2023 12:56:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8A9383858024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1696251415; bh=OUtdWj3KrdvP2zqS8xb1UuZ6zkPdNzZiBnIEVEuhJA8=; h=From:To:Subject:Date:From; b=UeNI66BptE8mJe95KyItWCYnJnNWJ33tGU0PceRmPORhybOQMTnZ/B1KgnMpnLwun veEuFsBedLHCdcp7DK85YI2WBTefmc/Ovm0jFIU79XbPnlBU679LJyme46Jj4IC/8H pz0doCup8Zm5kmm0fEqabpS006tponUhuntdS1BQ= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Joe Simmons-Talbott To: glibc-cvs@sourceware.org Subject: [glibc] mips: dl-machine-reject-phdr: Get rid of alloca. X-Act-Checkin: glibc X-Git-Author: Joe Simmons-Talbott X-Git-Refname: refs/heads/master X-Git-Oldrev: d90b43a4ed475dac5b0cd6e01ceb35c7b0f7f2ff X-Git-Newrev: 08e9a60a1ad34425a849c37611e55dd9fb4d3618 Message-Id: <20231002125655.8A9383858024@sourceware.org> Date: Mon, 2 Oct 2023 12:56:55 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=08e9a60a1ad34425a849c37611e55dd9fb4d3618 commit 08e9a60a1ad34425a849c37611e55dd9fb4d3618 Author: Joe Simmons-Talbott Date: Mon Oct 2 12:55:27 2023 +0000 mips: dl-machine-reject-phdr: Get rid of alloca. Read directly into the mips_abiflags struct rather than reading the entire segment and using alloca when the passed buffer is not big enough. Checked with build-many-glibcs.py on mips-linux-gnu Tested-by: Ying Huang Reviewed-by: Adhemerval Zanella Diff: --- sysdeps/mips/dl-machine-reject-phdr.h | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/sysdeps/mips/dl-machine-reject-phdr.h b/sysdeps/mips/dl-machine-reject-phdr.h index 104b590661..b784697fc1 100644 --- a/sysdeps/mips/dl-machine-reject-phdr.h +++ b/sysdeps/mips/dl-machine-reject-phdr.h @@ -161,7 +161,7 @@ elf_machine_reject_phdr_p (const ElfW(Phdr) *phdr, unsigned int phnum, Lmid_t nsid; int in_abi = -1; struct abi_req in_req; - Elf_MIPS_ABIFlags_v0 *mips_abiflags = NULL; + Elf_MIPS_ABIFlags_v0 mips_abiflags; bool perfect_match = false; #if _MIPS_SIM == _ABIO32 unsigned int cur_mode = -1; @@ -176,25 +176,19 @@ elf_machine_reject_phdr_p (const ElfW(Phdr) *phdr, unsigned int phnum, /* Read the attributes section. */ if (ph != NULL) { - ElfW(Addr) size = ph->p_filesz; + ElfW(Addr) size = sizeof (Elf_MIPS_ABIFlags_v0); - if (ph->p_offset + size <= len) - mips_abiflags = (Elf_MIPS_ABIFlags_v0 *) (buf + ph->p_offset); - else - { - mips_abiflags = alloca (size); - __lseek (fd, ph->p_offset, SEEK_SET); - if (__libc_read (fd, (void *) mips_abiflags, size) != size) - REJECT (" unable to read PT_MIPS_ABIFLAGS\n"); - } - - if (size < sizeof (Elf_MIPS_ABIFlags_v0)) + if (ph->p_filesz < size) REJECT (" contains malformed PT_MIPS_ABIFLAGS\n"); - if (__glibc_unlikely (mips_abiflags->flags2 != 0)) - REJECT (" unknown MIPS.abiflags flags2: %u\n", mips_abiflags->flags2); + __lseek (fd, ph->p_offset, SEEK_SET); + if (__libc_read (fd, (void *) &mips_abiflags, size) != size) + REJECT (" unable to read PT_MIPS_ABIFLAGS\n"); + + if (__glibc_unlikely (mips_abiflags.flags2 != 0)) + REJECT (" unknown MIPS.abiflags flags2: %u\n", mips_abiflags.flags2); - in_abi = mips_abiflags->fp_abi; + in_abi = mips_abiflags.fp_abi; } /* ANY is compatible with anything. */