From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc36.google.com (mail-oo1-xc36.google.com [IPv6:2607:f8b0:4864:20::c36]) by sourceware.org (Postfix) with ESMTPS id C6D4D388982C for ; Mon, 5 Jun 2023 18:14:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C6D4D388982C 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-oo1-xc36.google.com with SMTP id 006d021491bc7-558cf19575dso960126eaf.3 for ; Mon, 05 Jun 2023 11:14:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1685988850; x=1688580850; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=c219/1Hh5DiAA9pTfM1vZv65rChSGeOwLxJPQJpL9iI=; b=ZslB0Z5SjLH0Hk93zvPJe7xfaxixLSVK1emedvhEcj4YRllT9V6R86NPXDQ8xhsxx0 E3bbryz6ssnukdWYuc0MM+hQ13hIJNfHQ8nDF9+AZXbEBi6ayHcGLe43rU58EfP7h8Ni nLMai37/MF5NZq2PpttTY6Vupbo2EmmNkzyW716JJYpmAlIFmte5ZUqQ2pME8t77HZY1 nciIU+yGoW/QpL8oiArHHXaPhB2yl5eFbCMjwKpdypfZHHmCi3IG9LgVv4Fndo4ZU4jA WxVEfTpzOZhF5Xs7Cm3oT8IZN1eJA+WnaDxe0Dy83doLnEE73+Hg5sAWAxduwEtTPDf/ 6x9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685988850; x=1688580850; h=content-transfer-encoding:in-reply-to:organization:from:references :cc: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=c219/1Hh5DiAA9pTfM1vZv65rChSGeOwLxJPQJpL9iI=; b=llHzXRWMLhaSK4vBqPyb35ShTMbVm/+WpgUMo4wBcgdYbGlZnEWmETmXjg9o3WKljE VJX6a/R9Iff7bkW6ic1e8yHJ0450N8GAMbcW1h1oFT8etyKWgC30j0ZNGg98qcJrIhGO RLPPKG1GnIZ+c4xVsSy/wBecKIUYGNAdmhGPZr81ZlDxTNbdkwXZgr+ueq6wbd3n03XS JFH4dEOIxqW9GOQnJDMQn2eo2Ihb4dDD94QrfKDJzrPdCDNXiF62Z1/VXUjdIjePcJ/V kVRUKoRvwDddBU8/iIoA7VhWcnnSJSqf0w5YkaDe7O0sJ2yWmq9wR+ayps45kCSkZnad jf3Q== X-Gm-Message-State: AC+VfDz+4m4JwmA0TK5/FldK9S9y32Up2RWpGINkxi+HN547eWdaah46 8RKKOlstR32IQb6GoCeR5Xa9bpfIRj9F5HRC7519Sg== X-Google-Smtp-Source: ACHHUZ4swqGZVC/IA9pefa9v57gOKuusWaK7YcJ0mOQFaLY41BQClZhmlvH4GGpoIRY1U0svDYxUvA== X-Received: by 2002:a4a:bb16:0:b0:558:b779:5e4e with SMTP id f22-20020a4abb16000000b00558b7795e4emr471697oop.3.1685988850033; Mon, 05 Jun 2023 11:14:10 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c1:fe49:680c:a97a:ffe6:9a8f? ([2804:1b3:a7c1:fe49:680c:a97a:ffe6:9a8f]) by smtp.gmail.com with ESMTPSA id bn15-20020a056820180f00b005559f182cd6sm3396730oob.12.2023.06.05.11.14.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Jun 2023 11:14:09 -0700 (PDT) Message-ID: Date: Mon, 5 Jun 2023 15:14:06 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.11.2 Subject: Re: [PATCH] grantpt: Get rid of alloca Content-Language: en-US To: Joe Simmons-Talbott , Florian Weimer , Siddhesh Poyarekar Cc: Joe Simmons-Talbott via Libc-alpha , Samuel Thibault , Sergey Bugaev References: <20230601195817.3251303-1-josimmon@redhat.com> <87ttvmyr3q.fsf@oldenburg.str.redhat.com> <20230605133734.GU176347@oak> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <20230605133734.GU176347@oak> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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 05/06/23 10:37, Joe Simmons-Talbott via Libc-alpha wrote: > On Mon, Jun 05, 2023 at 03:29:45PM +0200, Florian Weimer wrote: >> * Joe Simmons-Talbott via Libc-alpha: >> >>> Replace alloca with a scratch_buffer to avoid potential stack overflows. >>> --- >>> sysdeps/unix/grantpt.c | 12 +++++++++++- >>> 1 file changed, 11 insertions(+), 1 deletion(-) >>> >>> diff --git a/sysdeps/unix/grantpt.c b/sysdeps/unix/grantpt.c >>> index 38fce52576..e5d2390bf2 100644 >>> --- a/sysdeps/unix/grantpt.c >>> +++ b/sysdeps/unix/grantpt.c >>> @@ -20,6 +20,7 @@ >>> #include >>> #include >>> #include >>> +#include >>> #include >>> #include >>> #include >>> @@ -147,7 +148,14 @@ grantpt (int fd) >>> /* `sysconf' does not support _SC_GETGR_R_SIZE_MAX. >>> Try a moderate value. */ >>> grbuflen = 1024; >>> - grtmpbuf = (char *) __alloca (grbuflen); >>> + struct scratch_buffer sbuf; >>> + scratch_buffer_init (&sbuf); >>> + if (!scratch_buffer_set_array_size (&sbuf, 1, grbuflen)) >>> + { >>> + retval -1; >>> + goto cleanup; >>> + } >>> + grtmpbuf = sbuf.data; >>> __getgrnam_r (TTY_GROUP, &grbuf, grtmpbuf, grbuflen, &p); >>> if (p != NULL) >>> tty_gid = p->gr_gid; >>> @@ -255,6 +263,8 @@ grantpt (int fd) >>> if (buf != _buf) >>> free (buf); >>> >>> + scratch_buffer_free(sbuf); >>> + >>> return retval; >>> } >>> libc_hidden_def (grantpt) >> >> How did you test this? This code is only used on Hurd due to the >> override in sysdeps/unix/sysv/linux/grantpt.c. > > The only testing I did was a 'make && make check' on x86_64 and i686 linux. You will need to build for i686-gnu (Hurd) to actually enable this code. Which leads to another, which Siddheash has brough, which is --enable-pt_chown does make sense to be provided as a configure switch. I think we should just move all pt_chown to be Hurd specific, and remove the --enable-pt_chown option.