public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Paul Eggert <eggert@cs.ucla.edu>, Florian Weimer <fw@deneb.enyo.de>
Cc: Xiaoming Ni <nixiaoming@huawei.com>,
	libc-alpha@sourceware.org, drepper.fsp@gmail.com, roland@gnu.org,
	carlos@redhat.com, wangle6@huawei.com, yukeji@huawei.com
Subject: Re: [PATCH v2] stdlib: realpath use malloc replace __alloca to reduce stack overflow risks [BZ #26341]
Date: Mon, 10 Aug 2020 10:40:57 -0300	[thread overview]
Message-ID: <9fe6ee87-129b-29fa-d9df-eca359bd866f@linaro.org> (raw)
In-Reply-To: <d9f7f387-3918-5533-7852-487f71d64e31@cs.ucla.edu>



On 09/08/2020 14:22, Paul Eggert wrote:
> On 8/9/20 5:38 AM, Florian Weimer wrote:
>> I have seen a report that the temporary buffer in vfprintf on an
>> unbuffered stream causes crashes because after a hardware upgrade, the
>> available stack space was insufficient.  That on-stack buffer is 8 KiB
>> as well.
> 
> I have no doubt that there are more bug reports about stack overflows "caused" by vfprintf's 8 KiB stack than about those "caused" by getchar's 2 KiB stack. But this doesn't mean we should worry overmuch about these small stack allocations. It's a fact of life that library routines use a small amount of stack space, and on today's processors 8 KiB in a leaf I/O function counts as "small" even in multithreaded apps. We shouldn't waste valuable development time (or user CPU time) trying to shrink such a function's stack space further.
> 
> It's easy to shrink 164 KiB (as in the original bug report) down to 8 KiB, so let's do that. The need to shrink stack further does not outweigh the need to avoid pressuring the memory allocator and worrying about leaks, so let's quit while we're ahead.
> 
> If (despite my advice) there is a push to shrink the stack space below 8 KiB, at the very least we should introduce no new call to malloc when all processing can be done in a single buffer containing only PATH_MAX bytes (which describes the overwhelming majority of real-world cases).

Could we remove alloca as well? We can make 4k stack usage on most cases use the
extra 4k only where link are seeing the path. 

  reply	other threads:[~2020-08-10 13:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-07 10:16 Xiaoming Ni
2020-08-07 19:43 ` Adhemerval Zanella
2020-08-08  0:00   ` Paul Eggert
2020-08-08  9:14   ` Xiaoming Ni
2020-08-07 23:56 ` Paul Eggert
2020-08-08  8:54   ` Xiaoming Ni
2020-08-09  8:44     ` Paul Eggert
2020-08-09 12:38       ` Florian Weimer
2020-08-09 17:22         ` Paul Eggert
2020-08-10 13:40           ` Adhemerval Zanella [this message]
2020-08-11  9:54             ` Paul Eggert

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=9fe6ee87-129b-29fa-d9df-eca359bd866f@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=carlos@redhat.com \
    --cc=drepper.fsp@gmail.com \
    --cc=eggert@cs.ucla.edu \
    --cc=fw@deneb.enyo.de \
    --cc=libc-alpha@sourceware.org \
    --cc=nixiaoming@huawei.com \
    --cc=roland@gnu.org \
    --cc=wangle6@huawei.com \
    --cc=yukeji@huawei.com \
    /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).