From owner-freebsd-hackers@FreeBSD.ORG Mon Jun 13 19:31:56 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 586B116A41C for ; Mon, 13 Jun 2005 19:31:56 +0000 (GMT) (envelope-from mhunter@malcolm.berkeley.edu) Received: from malcolm.berkeley.edu (malcolm.Berkeley.EDU [128.32.206.239]) by mx1.FreeBSD.org (Postfix) with ESMTP id 26A5643D49 for ; Mon, 13 Jun 2005 19:31:53 +0000 (GMT) (envelope-from mhunter@malcolm.berkeley.edu) Received: from malcolm.berkeley.edu (localhost [127.0.0.1]) by malcolm.berkeley.edu (8.13.3/8.13.3) with ESMTP id j5DJVoNI076251 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 13 Jun 2005 12:31:50 -0700 (PDT) (envelope-from mhunter@malcolm.berkeley.edu) Received: (from mhunter@localhost) by malcolm.berkeley.edu (8.13.3/8.13.3/Submit) id j5DJVoA8076250; Mon, 13 Jun 2005 12:31:50 -0700 (PDT) (envelope-from mhunter) Date: Mon, 13 Jun 2005 12:31:50 -0700 From: Mike Hunter To: Dag-Erling =?unknown-8bit?Q?Sm=F8rgrav?= Message-ID: <20050613193150.GA75218@malcolm.berkeley.edu> References: <20050610224058.GA11336@malcolm.berkeley.edu> <86vf4lb110.fsf@xps.des.no> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <86vf4lb110.fsf@xps.des.no> User-Agent: Mutt/1.5.6i X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-1.6 (malcolm.berkeley.edu [127.0.0.1]); Mon, 13 Jun 2005 12:31:51 -0700 (PDT) Cc: freebsd-hackers@freebsd.org Subject: Re: unitialized memory is all zeros...why not garbage instead? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Jun 2005 19:31:56 -0000 On Jun 11, "Dag-Erling Smrgrav" wrote: > Mike Hunter 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