double free() with grub-probe
A message that is not in the archive (sent off-list or not yet received): 20070514090937.GA10895@aragorn
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): 20070516155526.GA24614@aragorn
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi there,
We got this bug report from Debian BTS. It seems to be related to LVM.
The argc address in last line looks very suspicious; stack corruption?
More details (with full log) available at http://bugs.debian.org/423409
Quoted 84 lines · Florian Kriener
(gdb) set args ext2_mod-fs_ext2.d
(gdb) runStarting program:
/home/leflo/src/grub2-1.95+20070515/grub-probeext2_mod-fs_ext2.d
*** glibc detected ***/home/leflo/src/grub2-1.95+20070515/grub-probe: double free or corruption (!prev):0x08067188***
======= Backtrace: =========
/lib/i686/cmov/libc.so.6[0xb7e3aeed] /lib/i686/cmov/libc.so.6(cfree+0x90)[0xb7e3e530] /home/leflo/src/grub2-1.95+20070515/grub-probe[0x804bc8f] /home/leflo/src/grub2-1.95+20070515/grub-probe[0x8059368] /home/leflo/src/grub2-1.95+20070515/grub-probe[0x804b47e] /home/leflo/src/grub2-1.95+20070515/grub-probe[0x804fa4c] /home/leflo/src/grub2-1.95+20070515/grub-probe[0x804f5ef] /home/leflo/src/grub2-1.95+20070515/grub-probe[0x804b5ff] /home/leflo/src/grub2-1.95+20070515/grub-probe[0x8049720] /home/leflo/src/grub2-1.95+20070515/grub-probe[0x804b704] /home/leflo/src/grub2-1.95+20070515/grub-probe[0x804b3f4] /home/leflo/src/grub2-1.95+20070515/grub-probe[0x8058e92] /home/leflo/src/grub2-1.95+20070515/grub-probe[0x8058eb2] /home/leflo/src/grub2-1.95+20070515/grub-probe[0x80491aa] /lib/i686/cmov/libc.so.6(__libc_start_main+0xdc)[0xb7de8ebc] /home/leflo/src/grub2-1.95+20070515/grub-probe[0x8048eb1]
======= Memory map: ========
08048000-0805c000 r-xp 00000000 fe:01
177294/home/leflo/src/grub2-1.95+20070515/grub-probe
0805c000-0805d000 rwxp 00014000 fe:01
177294/home/leflo/src/grub2-1.95+20070515/grub-probe
0805d000-08085000 rwxp0805d00000:00 0 [heap]
b7c00000-b7c21000 rwxpb7c0000000:00 0
b7c21000-b7d00000 ---pb7c2100000:00 0
b7d96000-b7da1000 r-xp 00000000 08:01 172230/lib/libgcc_s.so.1
b7da1000-b7da2000 rwxp0000a00008:01 172230/lib/libgcc_s.so.1
b7da2000-b7dd3000 rwxpb7da200000:00 0b7dd3000-b7f10000 r-xp 00000000 08:01 204158 /lib/i686/cmov/libc-2.5.so b7f10000-b7f11000 r-xp 0013d000 08:01 204158 /lib/i686/cmov/libc-2.5.so b7f11000-b7f13000 rwxp 0013e000 08:01 204158 /lib/i686/cmov/libc-2.5.so b7f13000-b7f17000 rwxp b7f13000 00:00 0 b7f33000-b7f34000 rwxp b7f33000 00:00 0 b7f34000-b7f4f000 r-xp 00000000 08:01 172367 /lib/ld-2.5.so b7f4f000-b7f51000 rwxp 0001b000 08:01 172367 /lib/ld-2.5.so bfd01000-bfd17000 rwxp bfd01000 00:00 0 [stack] ffffe000-fffff000 r-xp 00000000 00:00 0 [vdso]Program received signal SIGABRT, Aborted.
0xffffe410in__kernel_vsyscall()
(gdb) bt#0 0xffffe410 in __kernel_vsyscall () #1 0xb7dfcd60 in raise () from /lib/i686/cmov/libc.so.6 #2 0xb7dfe5b1 in abort () from /lib/i686/cmov/libc.so.6 #3 0xb7e3308b in __libc_message () from /lib/i686/cmov/libc.so.6 #4 0xb7e3aeed in _int_free () from /lib/i686/cmov/libc.so.6 #5 0xb7e3e530 in free () from /lib/i686/cmov/libc.so.6 #6 0x0804bc8f in grub_disk_read (disk=0x8064078, sector=4000189, offset=0, size=194560, buf=0xb7da2008 "") at kern/disk.c:480#7
0x08059368ingrub_lvm_scan_device(name=0x8064068 "hd0,2") atdisk/lvm.c:262
#80x0804b47einiterate_partition(disk=0x8064008, partition=0xbfd138a4) atkern/device.c:133
#90x0804fa4cinpc_partition_map_iterate(disk=0x8064008, hook=0xbfd139ae) atpartmap/pc.c:154
#100x0804f5efingrub_partition_iterate(disk=0x8064008, hook=0xbfd139ae) atkern/partition.c:127
#110x0804b5ffiniterate_disk(disk_name=0xbfd13952 "hd0") atkern/device.c:102
#120x08049720ingrub_util_biosdisk_iterate(hook=0xbfd139a4) atutil/i386/pc/biosdisk.c:133
#130x0804b704ingrub_disk_dev_iterate(hook=0xbfd139a4) atkern/disk.c:203#140x0804b3f4ingrub_device_iterate(hook=0x8059220 <grub_lvm_scan_device>) atkern/device.c:139
#150x08058e92ingrub_mod_init(mod=0x0) atdisk/lvm.c:489
#160x08058eb2ingrub_lvm_init() atdisk/lvm.c:487
#170x080491aain main (argc=Cannot access memory at address0x3bd8) atutil/i386/pc/grub-probe.c:273--snapp--
Doesn't matter at all what I set args to. Even good old asdf throws this error. Plus it does not matter if run as root or not.
BTW: Thats about everything I can do debugging c apps. So if you need more please tell me how to do it.
Signature · 4 lines
Robert Millan My spam trap is [email protected]. Note: this address is only intended for spam harvesters. Writing to it will get you added to my black list.
At Wed, 16 May 2007 22:01:01 +0200,
Quoted 4 lines · Robert Millan
We got this bug report from Debian BTS. It seems to be related to LVM.
The argc address in last line looks very suspicious; stack corruption?
It's possible, but it can also be a compiler optimalisation that confuses gdb.
Quoted 4 lines
Quoted 4 lines
Program received signal SIGABRT, Aborted.
0xffffe410in__kernel_vsyscall()
(gdb) bt
#00xffffe410in__kernel_vsyscall()
Quoted 8 lines
Quoted 8 lines
#1 0xb7dfcd60 in raise () from /lib/i686/cmov/libc.so.6 #2 0xb7dfe5b1 in abort () from /lib/i686/cmov/libc.so.6 #3 0xb7e3308b in __libc_message () from /lib/i686/cmov/libc.so.6 #4 0xb7e3aeed in _int_free () from /lib/i686/cmov/libc.so.6 #5 0xb7e3e530 in free () from /lib/i686/cmov/libc.so.6 #6 0x0804bc8f in grub_disk_read (disk=0x8064078, sector=4000189, offset=0, size=194560, buf=0xb7da2008 "") at kern/disk.c:480
That's the free of tmp_buf, but I just looked at the code and as far as I can see the only place where tmp_buf can get freed is at that place. So I'm a bit puzzled how a double free() can happen there.
Jeroen Dekkers
A message that is not in the archive (sent off-list or not yet received): [email protected]
At Wed, 16 May 2007 22:38:25 +0200,
Quoted 7 lines · Florian Kriener
Quoted 5 lines · On Wednesday 16 May 2007 22:29:17 Jeroen Dekkers wrote:
At Wed, 16 May 2007 22:01:01 +0200,
Quoted 2 lines · Robert Millan
We got this bug report from Debian BTS. It seems to be related to LVM.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
The argc address in last line looks very suspicious; stack corruption?
It's possible, but it can also be a compiler optimalisation that confuses gdb.
No, it's not that, I get that error with the standard debian package (grub-pc), with a self-compiled version (using debian sources), in gdb and (just tested it) even when compiled with empty CCFLAGS.
If it's stack corruption, I guess gcc's stack protection should detect that. Can you try to recompile with -fstack-protector-all?
Jeroen Dekkers
Robert Millan <[email protected]> writes:
Hi Robert,
Quoted 3 lines
We got this bug report from Debian BTS. It seems to be related to LVM.
The argc address in last line looks very suspicious; stack corruption?
Can you try valgrind? The older valgrinds didn't work with GRUB 2, but the newer ones do.
--
Marco
At Thu, 17 May 2007 11:58:54 +0200,
Quoted 8 lines · Marco Gerards
Hi Robert,
Quoted 3 lines
We got this bug report from Debian BTS. It seems to be related to LVM.
The argc address in last line looks very suspicious; stack corruption?
Can you try valgrind? The older valgrinds didn't work with GRUB 2, but the newer ones do.
I could reproduce this on one of my machines and ran it through valgrind. I've just committed a fix to the grub2 CVS repository (as well as another memory bug valgrind spotted). A copy of the patch is below.
Jeroen Dekkers
Index: kern/disk.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/disk.c,v
retrieving revision 1.17
retrieving revision 1.18
disk.c +3 -1
@@ -1,6 +1,6 @@/* * GRUB -- GRand Unified Bootloader -* Copyright (C) 2002,2003,2004,2006 Free Software Foundation, Inc. +* Copyright (C) 2002,2003,2004,2006,2007 Free Software Foundation, Inc. * * GRUB is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -414,6 +414,8 @@ grub_disk_read (grub_disk_t disk, grub_d num = ((size +GRUB_DISK_SECTOR_SIZE -1 ) >>GRUB_DISK_SECTOR_BITS ); + + tmp_buf =grub_realloc (tmp_buf, num <<GRUB_DISK_SECTOR_BITS );if ((disk->dev->read) (disk, sector, num, tmp_buf)) {grub_error_push ();
============================================================
Quoted 4 lines · Jeroen Dekkers
I could reproduce this on one of my machines and ran it through valgrind. I've just committed a fix to the grub2 CVS repository (as well as another memory bug valgrind spotted). A copy of the patch is below.
Thank you for your fix. Just a small thing, but isn't it better to check the return value from grub_realloc?
Okuji
At Fri, 18 May 2007 20:36:40 +0200,
Quoted 9 lines · Yoshinori K. Okuji
Quoted 4 lines · Jeroen Dekkers
I could reproduce this on one of my machines and ran it through valgrind. I've just committed a fix to the grub2 CVS repository (as well as another memory bug valgrind spotted). A copy of the patch is below.
Thank you for your fix. Just a small thing, but isn't it better to check the return value from
grub_realloc?
Oops... fixed it.
Jeroen Dekkers