Skip to contentSkip to conversation

Double free of initramfs

DISCUSSION Ralf Baechle 4 participants 6 messages Mar 16, 2005 – Mar 22, 2005 Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

In all linker scripts we currently have something like this:

__init_begin = .;
...
. = ALIGN(4096);
__initramfs_start = .;
.init.ramfs : { *(.init.ramfs) }
__initramfs_end = .;
...
__init_end = .;

It seems all 25 linker scripts in the current bk tree are suffering from this. Which mean with CONFIG_BLK_DEV_INITRD enabled first free_initrd_mem may be called to free the initram disk and just a little later free_initmem will try to free the entire range again, so either the linker scripts would need fixing or free_initrd_mem has become obsolete.

Ralf

#1 lore raw
Quoted 12 lines · Ralf Baechle

In all linker scripts we currently have something like this:

__init_begin = .;
...
. = ALIGN(4096);
__initramfs_start = .;
.init.ramfs : { *(.init.ramfs) }
__initramfs_end = .;
...
__init_end = .;

Quoted 6 lines

It seems all 25 linker scripts in the current bk tree are suffering from this. Which mean with CONFIG_BLK_DEV_INITRD enabled first free_initrd_mem may be called to free the initram disk and just a little later free_initmem will try to free the entire range again, so either the linker scripts would need fixing or free_initrd_mem has become obsolete.

Hard call. I'd be 51% inclined to change the linker scripts so that the freeing of the initram disk happens explicitly, rather than having it magically hidden inside the main initmem segment.

Any objections from anyone?

(cc'ed Adrian, who might be interested in raising a patch ;))

#2 lore raw
Quoted 2 lines · Andrew Morton

...
(cc'ed Adrian, who might be interested in raising a patch ;))

When did I get the MAINTAINERS entry
DOES ALL DUMB JOBS
? ;-)

If you two agree it's the correct solution I can prepare a patch.

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#3 lore raw
In reply to Andrew Morton
Quoted 7 lines · Andrew Morton
Quoted 6 lines

It seems all 25 linker scripts in the current bk tree are suffering from this. Which mean with CONFIG_BLK_DEV_INITRD enabled first free_initrd_mem may be called to free the initram disk and just a little later free_initmem will try to free the entire range again, so either the linker scripts would need fixing or free_initrd_mem has become obsolete.

Quoted 7 lines

Hard call. I'd be 51% inclined to change the linker scripts so that the freeing of the initram disk happens explicitly, rather than having it magically hidden inside the main initmem segment.

Any objections from anyone?

(cc'ed Adrian, who might be interested in raising a patch ;))

I've cooked that already. Let me check if I can dig it up from here - I'm supposed to be on vacation ;-)

Ralf

#4 lore raw
Quoted 15 lines · Ralf Baechle
Quoted 13 lines · Andrew Morton
Quoted 6 lines

It seems all 25 linker scripts in the current bk tree are suffering from this. Which mean with CONFIG_BLK_DEV_INITRD enabled first free_initrd_mem may be called to free the initram disk and just a little later free_initmem will try to free the entire range again, so either the linker scripts would need fixing or free_initrd_mem has become obsolete.

Hard call. I'd be 51% inclined to change the linker scripts so that the freeing of the initram disk happens explicitly, rather than having it magically hidden inside the main initmem segment.

Any objections from anyone?

Quoted 8 lines
Quoted 1 line

(cc'ed Adrian, who might be interested in raising a patch ;))

I've cooked that already. Let me check if I can dig it up from here - I'm supposed to be on vacation ;-)
. = ALIGN(4096);
__initramfs_start = .;
.init.ramfs : { *(.init.ramfs) }
__initramfs_end = .;

Hi Ralf.

When you anyway hack on thins in your vacation please move the definition of initramfs to asm-generic.

Sam

Something like this:

===== include/asm-generic/vmlinux.lds.h 1.18 vs edited =====

include/asm-generic/vmlinux.lds.h +9 -0
@@ -97,3 +97,12 @@
 		VMLINUX_SYMBOL(__lock_text_start) = .;			\
 		*(.spinlock.text)					\
 		VMLINUX_SYMBOL(__lock_text_end) = .;
+
+/* initramfs area. */
+# define INITRAMFS							\
+	. = ALIGN(4096);						\
+	.init.ramfs : {							\
+		VMLINUX_SYMBOL(__initramfs_start) = .;			\
+		*(.init.ramfs)						\
+		VMLINUX_SYMBOL(__initramfs_end) = .;			\
+	}
#5 lore raw

include/asm-generic/vmlinux.lds.h line 103

Quoted 13 lines · Sam Ravnborg

Something like this:

===== include/asm-generic/vmlinux.lds.h 1.18 vs edited =====

include/asm-generic/vmlinux.lds.h +4 -0
@@ -97,3 +97,12 @@
 		VMLINUX_SYMBOL(__lock_text_start) = .;			\
 		*(.spinlock.text)					\
 		VMLINUX_SYMBOL(__lock_text_end) = .;
+
+/* initramfs area. */
+# define INITRAMFS							\
+	. = ALIGN(4096);						\

Based on Tony's very valid comment this should read:

include/asm-generic/vmlinux.lds.h line 104

Quoted 1 line
include/asm-generic/vmlinux.lds.h +1 -0
+	. = ALIGN(PAGE_SIZE);						\

(Assuming the 4096 was a page alingment).

Sam