[U-Boot] env: fix potential stack overflow in environment functions

Wolfgang Denk wd at denx.de
Fri Apr 5 13:17:10 CEST 2013


Dear Tom Rini,

In message <20130403153014.GF7035 at bill-the-cat> you wrote:
> 
> On Fri, Mar 22, 2013 at 11:26:21AM -0000, Rob Herring wrote:
> 
> > From: Rob Herring <rob.herring at calxeda.com>
> > 
> > Most of the various environment functions create CONFIG_ENV_SIZE buffers on
> > the stack. At least on ARM and PPC which have 4KB stacks, this can overflow
> > the stack if we have large environment sizes. So move all the buffers off
> > the stack to static buffers.
> > 
> > Signed-off-by: Rob Herring <rob.herring at calxeda.com>
> 
> Applied to u-boot/master, thanks!

I'm unhappy about this.

The patch makes no sense to me, and in addition it causes build
warnings for some boards (PPC: debris, kvme080):

env_nvram.c: In function 'env_init':
env_nvram.c:124:16: warning: pointer targets in initialization differ
in signedness [-Wpointer-sign]


I tried to explain this before, but eventually you missed my remarks,
so here they go again:

* The functiuons we are talking about run after relocation, i. e. when
  we have a full standard C runtime environment.  In this situation we
  can assume to have virtually unlimited stack space available -
  actually limited only by the RAM size.

* Moving the buffers from the stack into BSS is bad, as this way we
  permanently lose the space for these buffers, nut we need them only
  for a very short time, so we are wasting lots of memory.

* If some board have for some reasons unreasonable small stack sizes,
  these need to be fixed.   Rob refers to LMB stack space in his
  previous message - if there are indeed such small stack sizes used
  there, this is a problem that needs to be fixed elsewhere, but NOT
  by adapting all the rest of the U-Boot code to an artifical small
  stack.


I hereby request to revert that commit.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
How long does it take a  DEC  field  service  engineer  to  change  a
lightbulb?       It depends on how many bad ones he brought with him.


More information about the U-Boot mailing list