[PATCH] mips: dl-machine-reject-phdr: Get rid of alloca.

Joe Simmons-Talbott josimmon@redhat.com
Fri Jun 23 13:26:32 GMT 2023


On Thu, Jun 22, 2023 at 12:06:25PM -0400, Joe Simmons-Talbott wrote:
> Use a scratch_buffer rather than alloca to avoid potential stack overflow.
> 
> Checked with build-many-glibcs.py on mips-linux-gnu
> ---
>  sysdeps/mips/dl-machine-reject-phdr.h | 80 +++++++++++++++++++++------
>  1 file changed, 62 insertions(+), 18 deletions(-)
> 
> diff --git a/sysdeps/mips/dl-machine-reject-phdr.h b/sysdeps/mips/dl-machine-reject-phdr.h
> index 104b590661..7217d2d439 100644
> --- a/sysdeps/mips/dl-machine-reject-phdr.h
> +++ b/sysdeps/mips/dl-machine-reject-phdr.h
> @@ -20,6 +20,7 @@
>  #define _DL_MACHINE_REJECT_PHDR_H 1
>  
>  #include <unistd.h>
> +#include <scratch_buffer.h>
>  #include <sys/prctl.h>
>  
>  #if defined PR_GET_FP_MODE && defined PR_SET_FP_MODE
> @@ -167,6 +168,8 @@ elf_machine_reject_phdr_p (const ElfW(Phdr) *phdr, unsigned int phnum,
>    unsigned int cur_mode = -1;
>  # if HAVE_PRCTL_FP_MODE
>    bool cannot_mode_switch = false;
> +  struct scratch_buffer sbuf;
> +  scratch_buffer_init (&sbuf);
>  
>    /* Get the current hardware mode.  */
>    cur_mode = __prctl (PR_GET_FP_MODE);
> @@ -182,17 +185,29 @@ elf_machine_reject_phdr_p (const ElfW(Phdr) *phdr, unsigned int phnum,
>  	mips_abiflags = (Elf_MIPS_ABIFlags_v0 *) (buf + ph->p_offset);
>        else
>  	{
> -	  mips_abiflags = alloca (size);
> +	  if (!scratch_buffer_set_array_size (&buf, 1, size))
                                              &sbuf
> +	    REJECT ("   unable to allocate memory\n");
> +	  mips_abiflags = buf.data;
                          sbuf.data

v2 will be posted soon.

Thanks,
Joe



More information about the Libc-alpha mailing list