Skip to contentSkip to conversation

__init poisoning for i386, too

PATCH Pavel Machek 8 participants 9 messages Oct 6, 2004 – Oct 8, 2004

lore
Share & tools
lore
#0 lore raw

Hi!

Overwrite __init section so calls to __init functions from normal code are catched, reliably. I wonder if this should be configurable... but it is configurable on x86-64 so I copied it. Please apply,

Pavel

arch/i386/Kconfig.debug renamed from linux/arch/i386/Kconfig.debug +7 -0
@@ -15,6 +15,13 @@
 	  with klogd/syslogd or the X server. You should normally N here,
 	  unless you want to debug such a crash.
 
+config INIT_DEBUG
+	bool "Debug __init statements"
+	depends on DEBUG_KERNEL
+	help
+	  Fill __init and __initdata at the end of boot. This helps debugging
+	  illegal uses of __init and __initdata after initialization.
+
 config DEBUG_STACKOVERFLOW
 	bool "Check for stack overflows"
 	depends on DEBUG_KERNEL
arch/i386/mm/init.c renamed from linux/arch/i386/mm/init.c +3 -0
@@ -705,6 +705,9 @@
 		ClearPageReserved(virt_to_page(addr));
 		set_page_count(virt_to_page(addr), 1);
 		free_page(addr);
+#ifdef CONFIG_INIT_DEBUG
+		memset((void *)(addr & ~(PAGE_SIZE-1)), 0xcc, PAGE_SIZE); 
+#endif
 		totalram_pages++;
 	}
 	printk (KERN_INFO "Freeing unused kernel memory: %dk freed\n", (__init_end - __init_begin) >> 10);
Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#1 lore raw
Quoted 4 lines · Pavel Machek

Overwrite __init section so calls to __init functions from normal code are catched, reliably. I wonder if this should be configurable... but it is configurable on x86-64 so I copied it. Please apply,

No, I'll change it to just enable the thing unconditionally.

#2 lore raw
Quoted 6 lines · Andrew Morton
Quoted 3 lines · Pavel Machek

Overwrite __init section so calls to __init functions from normal code are catched, reliably. I wonder if this should be configurable... but it is configurable on x86-64 so I copied it. Please apply,

No, I'll change it to just enable the thing unconditionally.

And can't such things be done in architecture-neutral code, to avoid code duplication and out-of-sync code among different architectures?

The magic value that corresponds to an illegal instruction (as suggested by wli) is arch-dependent, of course.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#3 lore raw
In reply to Pavel Machek

Hi.

arch/i386/mm/init.c line 710

Quoted 4 lines · Pavel Machek
arch/i386/mm/init.c renamed from linux/arch/i386/mm/init.c +3 -0
 		free_page(addr);
+#ifdef CONFIG_INIT_DEBUG
+		memset((void *)(addr & ~(PAGE_SIZE-1)), 0xcc, PAGE_SIZE); 
+#endif

Shouldn't the memset be before the free_page? (Changing freed pages?)

Regards,

Nigel

Signature · 7 lines
Nigel Cunningham
Pastoral Worker
Christian Reformed Church of Tuggeranong
PO Box 1004, Tuggeranong, ACT 2901

Many today claim to be tolerant. True tolerance, however, can cope with others
being intolerant.
#4 lore raw

Hi!

Quoted 7 lines · Pavel Machek

arch/i386/mm/init.c line 710

Quoted 4 lines
arch/i386/mm/init.c renamed from linux/arch/i386/mm/init.c +3 -0
 		free_page(addr);
+#ifdef CONFIG_INIT_DEBUG
+		memset((void *)(addr & ~(PAGE_SIZE-1)), 0xcc, PAGE_SIZE); 
+#endif

Shouldn't the memset be before the free_page? (Changing freed pages?)

Ouch, you are right. Interrupt could come and grab them. Yes, we need first memset, then free_page().
Pavel

Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#5 lore raw
In reply to Pavel Machek
Quoted 3 lines · Pavel Machek

Overwrite __init section so calls to __init functions from normal code are catched, reliably. I wonder if this should be configurable... but it is configurable on x86-64 so I copied it. Please apply,

Any chance we could:
(a) set the stuff to 0x0f0b so illegal instructions come of it; jumps are most often aligned to something > 16 bits anyway
(b) poison __initdata, memsetting to some bit pattern oopsable to dereference

-- wli

#6 lore raw
Followup to:  <[email protected]>
By author:    William Lee Irwin III <[email protected]>
In newsgroup: linux.dev.kernel
Quoted 11 lines · Pavel Machek
Quoted 3 lines

Overwrite __init section so calls to __init functions from normal code are catched, reliably. I wonder if this should be configurable... but it is configurable on x86-64 so I copied it. Please apply,

Any chance we could:
(a) set the stuff to 0x0f0b so illegal instructions come of it; jumps are most often aligned to something > 16 bits anyway
(b) poison __initdata, memsetting to some bit pattern oopsable to dereference

What's wrong with using 0xCC (breakpoint instruction)?

If you want an illegal instruction, 0xFF 0xFF is an illegal instruction, so filling memory with 0xFF will do what you want.

-hpa

#7 lore raw
Quoted 4 lines · At some point in the past, I wrote:
Quoted 4 lines

Any chance we could:
(a) set the stuff to 0x0f0b so illegal instructions come of it; jumps are most often aligned to something > 16 bits anyway
(b) poison __initdata, memsetting to some bit pattern oopsable to dereference

Quoted 3 lines · H. Peter Anvin

What's wrong with using 0xCC (breakpoint instruction)? If you want an illegal instruction, 0xFF 0xFF is an illegal instruction, so filling memory with 0xFF will do what you want.

That sounds better than what I suggested.

-- wli

#8 lore raw
Quoted 7 lines · you
Quoted 3 lines · H. Peter Anvin

What's wrong with using 0xCC (breakpoint instruction)? If you want an illegal instruction, 0xFF 0xFF is an illegal instruction, so filling memory with 0xFF will do what you want.

That sounds better than what I suggested.

Here's the trivial patch against 2.4.9-rc3-mm3

-Ryan

arch/i386/mm/init.c +1 -1
@@ -723,7 +723,7 @@
 	for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) {
 		ClearPageReserved(virt_to_page(addr));
 		set_page_count(virt_to_page(addr), 1);
-		memset((void *)(addr & ~(PAGE_SIZE-1)), 0xcc, PAGE_SIZE);
+		memset((void *)(addr & ~(PAGE_SIZE-1)), 0xff, PAGE_SIZE);
 		free_page(addr);
 		totalram_pages++;
 	}