linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* __init poisoning for i386, too
@ 2004-10-06 22:18 Pavel Machek
  2004-10-06 22:29 ` Andrew Morton
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Pavel Machek @ 2004-10-06 22:18 UTC (permalink / raw)
  To: Andrew Morton, kernel list

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

--- tmp/linux/arch/i386/Kconfig.debug	2004-10-01 00:29:59.000000000 +0200
+++ linux/arch/i386/Kconfig.debug	2004-10-07 00:11:09.000000000 +0200
@@ -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
--- tmp/linux/arch/i386/mm/init.c	2004-10-01 00:29:59.000000000 +0200
+++ linux/arch/i386/mm/init.c	2004-10-07 00:09:04.000000000 +0200
@@ -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);

-- 
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: __init poisoning for i386, too
  2004-10-06 22:18 Pavel Machek
@ 2004-10-06 22:29 ` Andrew Morton
  2004-10-07  8:22   ` Geert Uytterhoeven
  2004-10-06 23:56 ` Nigel Cunningham
  2004-10-07  6:16 ` William Lee Irwin III
  2 siblings, 1 reply; 10+ messages in thread
From: Andrew Morton @ 2004-10-06 22:29 UTC (permalink / raw)
  To: Pavel Machek; +Cc: linux-kernel

Pavel Machek <pavel@ucw.cz> wrote:
>
> 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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: __init poisoning for i386, too
  2004-10-06 22:18 Pavel Machek
  2004-10-06 22:29 ` Andrew Morton
@ 2004-10-06 23:56 ` Nigel Cunningham
  2004-10-07  8:02   ` Pavel Machek
  2004-10-07  6:16 ` William Lee Irwin III
  2 siblings, 1 reply; 10+ messages in thread
From: Nigel Cunningham @ 2004-10-06 23:56 UTC (permalink / raw)
  To: Pavel Machek; +Cc: Andrew Morton, Linux Kernel Mailing List

Hi.

On Thu, 2004-10-07 at 08:18, Pavel Machek wrote:
>  		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
-- 
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.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: __init poisoning for i386, too
  2004-10-06 22:18 Pavel Machek
  2004-10-06 22:29 ` Andrew Morton
  2004-10-06 23:56 ` Nigel Cunningham
@ 2004-10-07  6:16 ` William Lee Irwin III
  2004-10-07 21:05   ` H. Peter Anvin
  2 siblings, 1 reply; 10+ messages in thread
From: William Lee Irwin III @ 2004-10-07  6:16 UTC (permalink / raw)
  To: Pavel Machek; +Cc: Andrew Morton, kernel list

On Thu, Oct 07, 2004 at 12:18:55AM +0200, Pavel Machek wrote:
> 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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: __init poisoning for i386, too
  2004-10-06 23:56 ` Nigel Cunningham
@ 2004-10-07  8:02   ` Pavel Machek
  0 siblings, 0 replies; 10+ messages in thread
From: Pavel Machek @ 2004-10-07  8:02 UTC (permalink / raw)
  To: Nigel Cunningham; +Cc: Andrew Morton, Linux Kernel Mailing List

Hi!

> On Thu, 2004-10-07 at 08:18, Pavel Machek wrote:
> >  		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
-- 
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: __init poisoning for i386, too
  2004-10-06 22:29 ` Andrew Morton
@ 2004-10-07  8:22   ` Geert Uytterhoeven
  0 siblings, 0 replies; 10+ messages in thread
From: Geert Uytterhoeven @ 2004-10-07  8:22 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Pavel Machek, Linux Kernel Development

On Wed, 6 Oct 2004, Andrew Morton wrote:
> Pavel Machek <pavel@ucw.cz> wrote:
> > 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 -- geert@linux-m68k.org

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: __init poisoning for i386, too
       [not found] ` <20041007061610.GU9106@holomorphy.com.suse.lists.linux.kernel>
@ 2004-10-07 11:28   ` Andi Kleen
  0 siblings, 0 replies; 10+ messages in thread
From: Andi Kleen @ 2004-10-07 11:28 UTC (permalink / raw)
  To: William Lee Irwin III; +Cc: linux-kernel

William Lee Irwin III <wli@holomorphy.com> writes:

> On Thu, Oct 07, 2004 at 12:18:55AM +0200, Pavel Machek wrote:
> > 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

0xcc is an int3, that already causes an oops.

> (b) poison __initdata, memsetting to some bit pattern oopsable to dereference

Would be a good idea yes. I will add it to x86-64.

-Andi

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: __init poisoning for i386, too
  2004-10-07  6:16 ` William Lee Irwin III
@ 2004-10-07 21:05   ` H. Peter Anvin
  2004-10-08 11:08     ` William Lee Irwin III
  0 siblings, 1 reply; 10+ messages in thread
From: H. Peter Anvin @ 2004-10-07 21:05 UTC (permalink / raw)
  To: linux-kernel

Followup to:  <20041007061610.GU9106@holomorphy.com>
By author:    William Lee Irwin III <wli@holomorphy.com>
In newsgroup: linux.dev.kernel
>
> On Thu, Oct 07, 2004 at 12:18:55AM +0200, Pavel Machek wrote:
> > 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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: __init poisoning for i386, too
  2004-10-07 21:05   ` H. Peter Anvin
@ 2004-10-08 11:08     ` William Lee Irwin III
  2004-10-08 11:23       ` Ryan Cumming
  0 siblings, 1 reply; 10+ messages in thread
From: William Lee Irwin III @ 2004-10-08 11:08 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: linux-kernel

At some point in the past, I wrote:
>> 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

On Thu, Oct 07, 2004 at 09:05:45PM +0000, H. Peter Anvin wrote:
> 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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: __init poisoning for i386, too
  2004-10-08 11:08     ` William Lee Irwin III
@ 2004-10-08 11:23       ` Ryan Cumming
  0 siblings, 0 replies; 10+ messages in thread
From: Ryan Cumming @ 2004-10-08 11:23 UTC (permalink / raw)
  To: William Lee Irwin III; +Cc: linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 404 bytes --]

On Friday 08 October 2004 04:08, you wrote:
> On Thu, Oct 07, 2004 at 09:05:45PM +0000, H. Peter Anvin wrote:
> > 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

[-- Attachment #1.2: trivial-initmem-tweak.diff --]
[-- Type: text/x-diff, Size: 502 bytes --]

--- linux-2.6.9-rc3-mm3/arch/i386/mm/init.c	2004-10-08 04:19:46.645395667 -0700
+++ linux-2.6.9-rc3-mm3-new/arch/i386/mm/init.c	2004-10-08 04:21:51.933318774 -0700
@@ -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++;
 	}

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2004-10-08 11:28 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20041006221854.GA1622@elf.ucw.cz.suse.lists.linux.kernel>
     [not found] ` <20041007061610.GU9106@holomorphy.com.suse.lists.linux.kernel>
2004-10-07 11:28   ` __init poisoning for i386, too Andi Kleen
2004-10-06 22:18 Pavel Machek
2004-10-06 22:29 ` Andrew Morton
2004-10-07  8:22   ` Geert Uytterhoeven
2004-10-06 23:56 ` Nigel Cunningham
2004-10-07  8:02   ` Pavel Machek
2004-10-07  6:16 ` William Lee Irwin III
2004-10-07 21:05   ` H. Peter Anvin
2004-10-08 11:08     ` William Lee Irwin III
2004-10-08 11:23       ` Ryan Cumming

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).