From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by sourceware.org (Postfix) with ESMTPS id 39D163858C5E for ; Mon, 2 Oct 2023 12:13:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 39D163858C5E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1c752caeaa6so11575625ad.1 for ; Mon, 02 Oct 2023 05:13:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696248832; x=1696853632; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=eBX3nV429z451IzOPE6Py8QvzKJpQ32EeK7GTsngNdA=; b=k8wwHpy+S3Ho7nlr1n2fcARedPxbde4vas3B5MGjid+rddYpGgPoEJ4eFJgsnnkqL5 Zg5JlUb2PKgeZL3Me6QueiT5pQ816EyZl3kWuJKu3sXSh1FR4/pAP30ysc74cleIIipL EyDmEnolDreH5v+28zAoUJWHg8pYh50gDdewGSyfvP6JyhT88GRqqckKAOYVgyDJ3FQO jWFdZR8j8aXyAHQBdPid5Lk/Ep2usN9IXrioUm8rNJ5inJNzwVTsGewwGqwy3IZ+7U49 p83xadfYw0vPPEHCvXrTYp5xSP30XGFKVUI7vumbcjNaJL7hXcsBqkDsxXWrAoqxaIAo DLpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696248832; x=1696853632; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eBX3nV429z451IzOPE6Py8QvzKJpQ32EeK7GTsngNdA=; b=VAYmZKQx+BYHt8wyzOXiu5YlROpa/BwXHxkkeI9n6nDDmK59wSI8IwtWGwmDrRRB3D TeFP2bqWigV3VovYPx0071S5NRCWkDetRol/ALlZoVVOq8akd6jqZc5TBfLzystr1AzF rCKKF5vA0ahgZNxgCzvBuaxoyuOT8415HJlkjIvXyGlMb55MlbF47i0eYxfvJldUCsmU PgCgbOXWnWfwFaMoSRpbyWIlKEfnxaPyBjbCuLylZF52kOlClGQmOiZ586NCZdixF5VI oi+ymoWHWqmGiFIMvmUnTbQMQqAaeWT6PR/KkEiOitS0R6lbmewDAzAKaJD3OOi6Ojdg 8Xmg== X-Gm-Message-State: AOJu0YxNeLdo+S4rQcMsnx42ZyRG2bSjgP3T9BVZW4eSfU8L5P3AMjks sYmCh8S0ZC9w9tDdeBOPzbJN0l26NQLep0gthq1JMA== X-Google-Smtp-Source: AGHT+IEeu+30MxGe55PwNQQ8SbDA3zrwsrrVIzBI/P6HiSMTcgRpvAVGr8Z0kfVeBY1IvWO1CW8hwQ== X-Received: by 2002:a17:902:db02:b0:1c5:fe75:b304 with SMTP id m2-20020a170902db0200b001c5fe75b304mr11545157plx.59.1696248832143; Mon, 02 Oct 2023 05:13:52 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c1:feaf:9c9c:46fb:1bba:fa15? ([2804:1b3:a7c1:feaf:9c9c:46fb:1bba:fa15]) by smtp.gmail.com with ESMTPSA id n9-20020a170902e54900b001bc21222e34sm21670994plf.285.2023.10.02.05.13.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 02 Oct 2023 05:13:51 -0700 (PDT) Message-ID: <5d28a31b-a918-47c7-9fd3-7c8bd2720bef@linaro.org> Date: Mon, 2 Oct 2023 09:13:50 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] mips: dl-machine-reject-phdr: Get rid of alloca. Content-Language: en-US To: Joe Simmons-Talbott , libc-alpha@sourceware.org References: <20230626131621.763381-1-josimmon@redhat.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <20230626131621.763381-1-josimmon@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 > > 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. */