Skip to contentSkip to conversation

double free() with grub-probe

DISCUSSION Robert Millan 4 participants 7 messages May 16, 2007 – May 18, 2007 5 messages not in the archive

lore
Share & tools
lore

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]

#4 lore raw

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) run

Starting program: /home/leflo/src/grub2-1.95+20070515/grub-probe ext2_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 rwxp 0805d000 00:00 0 [heap]
b7c00000-b7c21000 rwxp b7c00000 00:00 0
b7c21000-b7d00000 ---p b7c21000 00:00 0
b7d96000-b7da1000 r-xp 00000000 08:01 172230 /lib/libgcc_s.so.1
b7da1000-b7da2000 rwxp 0000a000 08:01 172230 /lib/libgcc_s.so.1
b7da2000-b7dd3000 rwxp b7da2000 00:00 0

b7dd3000-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.
0xffffe410 in __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 0x08059368 in grub_lvm_scan_device (name=0x8064068 "hd0,2") at disk/lvm.c:262
#8 0x0804b47e in iterate_partition (disk=0x8064008, partition=0xbfd138a4) at kern/device.c:133
#9 0x0804fa4c in pc_partition_map_iterate (disk=0x8064008, hook=0xbfd139ae) at partmap/pc.c:154
#10 0x0804f5ef in grub_partition_iterate (disk=0x8064008, hook=0xbfd139ae) at kern/partition.c:127
#11 0x0804b5ff in iterate_disk (disk_name=0xbfd13952 "hd0") at kern/device.c:102
#12 0x08049720 in grub_util_biosdisk_iterate (hook=0xbfd139a4) at util/i386/pc/biosdisk.c:133
#13 0x0804b704 in grub_disk_dev_iterate (hook=0xbfd139a4) at kern/disk.c:203 #14 0x0804b3f4 in grub_device_iterate (hook=0x8059220 <grub_lvm_scan_device>) at kern/device.c:139
#15 0x08058e92 in grub_mod_init (mod=0x0) at disk/lvm.c:489
#16 0x08058eb2 in grub_lvm_init () at disk/lvm.c:487
#17 0x080491aa in main (argc=Cannot access memory at address 0x3bd8 ) at util/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.
#5 lore raw

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.
0xffffe410 in __kernel_vsyscall ()
(gdb) bt
#0 0xffffe410 in __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]

#7 lore raw

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

#8 lore raw
In reply to Robert Millan

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

#9 lore raw

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
diff -u -p -r1.17 -r1.18
@@ -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 ();

============================================================

#10 lore raw
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

#11 lore raw

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