Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 13 Jun 2005 12:31:50 -0700
From:      Mike Hunter <mhunter@ack.berkeley.edu>
To:        Dag-Erling =?unknown-8bit?Q?Sm=F8rgrav?= <des@des.no>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: unitialized memory is all zeros...why not garbage instead?
Message-ID:  <20050613193150.GA75218@malcolm.berkeley.edu>
In-Reply-To: <86vf4lb110.fsf@xps.des.no>
References:  <20050610224058.GA11336@malcolm.berkeley.edu> <86vf4lb110.fsf@xps.des.no>

next in thread | previous in thread | raw e-mail | index | archive | help
On Jun 11, "Dag-Erling Smrgrav" wrote:

> Mike Hunter <mhunter@ack.berkeley.edu> writes:
> > I have a feeling that I'm missing something really obvious, but I'm having
> > trouble understanding why the following program:
> > [...]
> > Never prints anything but "0"'s.
> 
> Because the kernel always hands processes pre-zeroed pages.
> 
> > I ran less up to my hw.physmem by feeding it /dev/random and watching
> > top, and then ran the program, so I "know" there was tons of non-zero
> > bits in memory.
> 
> If your program had been able to see leftovers from less in its own
> address space, we'd have a huge security hole on our hands.
> 
> > I'm curious because I am worried about information leaks between processes
> > on the same machine...did somebody decide to solve this problem while I
> > wasn't paying attention?  :)
> 
> It's always been this way.

Thanks for setting me straight.  I guess it wasn't this way on DOS where I
first learned C++ and I've assumed garbage ever since :)

Is the pre-zeroing of malloc'd memory documented somewhere?  By my reading 
of the malloc manapge...

     The calloc() function allocates space for number objects, each size 
     bytes in length.  The result is identical to calling malloc() with an
     argument of ``number * size'', with the exception that the allocated 
     memory is explicitly initialized to zero bytes.

...it seems like it's saying that malloc (as opposed to calloc) is NOT
pre-zeroed.  Is there a different document I should be reading?

Tussen Tak!

Mike



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050613193150.GA75218>