From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 4C37838582BF for ; Fri, 28 Oct 2022 05:31:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4C37838582BF Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666935080; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/3xm4LLy4RO4UzvKnSLwhZQ46g3LbCN0FM2uWnaKIpY=; b=XONaBBpqXo+ulnaePhlfAt+FO/LfbtrSGUxV8NqhfymTyHxaTfx+HCb21R6bTCe8/7HwcE NuKzQuGL63wZg92W7hhxQkBMkAw3vFjQl+NKQvUKQd8QcmOfv2C3AItCpQJeGG86Bv3M7E 33EZNZ91szZrDUlZWoE1cKVdoSW8p08= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-388-pXAjbeH9M3qaxzqNljnLJA-1; Fri, 28 Oct 2022 01:31:19 -0400 X-MC-Unique: pXAjbeH9M3qaxzqNljnLJA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 01260185A7AC; Fri, 28 Oct 2022 05:31:19 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.74]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 861B0492B16; Fri, 28 Oct 2022 05:31:18 +0000 (UTC) From: Florian Weimer To: Szabolcs Nagy via Libc-alpha Cc: Szabolcs Nagy Subject: Re: [PATCH 11/20] elf: Fix alloca size in _dl_debug_vdprintf References: <913439ddce2d33024fa0d0da5d9f4c6234a30cde.1666877952.git.szabolcs.nagy@arm.com> Date: Fri, 28 Oct 2022 07:31:16 +0200 In-Reply-To: <913439ddce2d33024fa0d0da5d9f4c6234a30cde.1666877952.git.szabolcs.nagy@arm.com> (Szabolcs Nagy via Libc-alpha's message of "Thu, 27 Oct 2022 16:33:06 +0100") Message-ID: <87h6zoikez.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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: * Szabolcs Nagy via Libc-alpha: > The alloca size did not consider the optional width parameter for > padding which could cause buffer underflow. The width is currently used > e.g. by _dl_map_object_from_fd which passes 2 * sizeof(void *) which > can be larger than the alloca buffer size on targets where > sizeof(void *) >= 2 * sizeof(unsigned long). > > Even if large width is not used on existing targets it is better to fix > the formatting code to avoid surprises. > --- > elf/dl-printf.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/elf/dl-printf.c b/elf/dl-printf.c > index 429d2e80c2..00c114002c 100644 > --- a/elf/dl-printf.c > +++ b/elf/dl-printf.c > @@ -163,8 +163,11 @@ _dl_debug_vdprintf (int fd, int tag_p, const char *fmt, va_list arg) > /* We use alloca() to allocate the buffer with the most > pessimistic guess for the size. Using alloca() allows > having more than one integer formatting in a call. */ > - char *buf = (char *) alloca (1 + 3 * sizeof (unsigned long int)); > - char *endp = &buf[1 + 3 * sizeof (unsigned long int)]; > + int size = 1 + 3 * sizeof (unsigned long int); > + if (width + 1 > size) > + size = width + 1; > + char *buf = (char *) alloca (size); > + char *endp = &buf[size]; > char *cp = _itoa (num, endp, *fmt == 'x' ? 16 : 10, 0); > > /* Pad to the width the user specified. */ This looks okay. Reviewed-by: Florian Weimer Thanks, Florian