From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
To: Joe Simmons-Talbott <josimmon@redhat.com>, libc-alpha@sourceware.org
Subject: Re: [PATCH v3] mips: dl-machine-reject-phdr: Get rid of alloca.
Date: Mon, 2 Oct 2023 09:13:50 -0300 [thread overview]
Message-ID: <5d28a31b-a918-47c7-9fd3-7c8bd2720bef@linaro.org> (raw)
In-Reply-To: <20230626131621.763381-1-josimmon@redhat.com>
On 26/06/23 10:16, Joe Simmons-Talbott via Libc-alpha wrote:
> 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
> ---
> Changes to v2:
> * Rather than use a scratch buffer use the mips_abiflags struct itself
> for reading since we're now just reading that much data and not the
> whole segment.
>
> sysdeps/mips/dl-machine-reject-phdr.h | 26 ++++++++++----------------
> 1 file changed, 10 insertions(+), 16 deletions(-)
LGTM, thanks.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
>
> 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. */
prev parent reply other threads:[~2023-10-02 12:13 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-26 13:16 Joe Simmons-Talbott
2023-08-29 19:30 ` Joe Simmons-Talbott
2023-08-30 8:18 ` Ying Huang
2023-08-30 12:29 ` Joe Simmons-Talbott
2023-09-04 1:12 ` Ying Huang
2023-09-07 12:25 ` Joe Simmons-Talbott
2023-09-21 11:52 ` Joe Simmons-Talbott
2023-10-02 11:52 ` Joe Simmons-Talbott
2023-10-02 12:13 ` Adhemerval Zanella Netto [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5d28a31b-a918-47c7-9fd3-7c8bd2720bef@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=josimmon@redhat.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).