From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:46824) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QwsF6-00026C-7T for qemu-devel@nongnu.org; Fri, 26 Aug 2011 04:58:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QwsF4-0004rC-Qz for qemu-devel@nongnu.org; Fri, 26 Aug 2011 04:58:24 -0400 Received: from eu1sys200aog114.obsmtp.com ([207.126.144.137]:55917) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QwsF4-0004qf-Je for qemu-devel@nongnu.org; Fri, 26 Aug 2011 04:58:22 -0400 From: =?UTF-8?q?C=C3=A9dric=20VINCENT?= Date: Fri, 26 Aug 2011 10:56:50 +0200 Message-ID: <1314349010-22408-1-git-send-email-cedric.vincent@st.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH] linux-user: Fix initialization of the heap contents when allocating new pages List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Laurent ALFONSI , =?UTF-8?q?C=C3=A9dric=20VINCENT?= , Riku Voipio Technically the new mmapped pages are already initialized to zero since they are anonymous, however we have to take care with the contents that come from the remaining part of the previous page: it may contains garbage data due to a previous heap usage (grown then shrunken). This patch completes commit 55f08c84. The problem could be reproduced when emulating the build process of Perl 5.12.3 on ARMedSlack 13.37: make[1]: Entering directory `/tmp/perl-5.12.3/cpan/Compress-Raw-Bzip2' cc -c -I. -fno-strict-aliasing -pipe -fstack-protector \ -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 \ -O2 -DVERSION=\"2.024\" -DXS_VERSION=\"2.024\" -fPIC "-I../.." \ -DBZ_NO_STDIO decompress.c decompress.c: In function 'BZ2_decompress': decompress.c:621:1: internal compiler error: Segmentation fault Signed-off-by: Laurent ALFONSI Signed-off-by: Cédric VINCENT --- linux-user/syscall.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 6bdf4e6..ae08c9e 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -797,6 +797,15 @@ abi_long do_brk(abi_ulong new_brk) MAP_ANON|MAP_PRIVATE, 0, 0)); if (mapped_addr == brk_page) { + /* Heap contents are initialized to zero, as for anonymous + * mapped pages. Technically the new pages are already + * initialized to zero since they *are* anonymous mapped + * pages, however we have to take care with the contents that + * come from the remaining part of the previous page: it may + * contains garbage data due to a previous heap usage (grown + * then shrunken). */ + memset(g2h(target_brk), 0, brk_page - target_brk); + target_brk = new_brk; brk_page = HOST_PAGE_ALIGN(target_brk); DEBUGF_BRK("%#010x (mapped_addr == brk_page)\n", target_brk); -- 1.7.5.1