* Re: [patch] mark text section read-only
[not found] ` <57MrY-50s-39@gated-at.bofh.it>
@ 2005-11-11 23:03 ` Bodo Eggert
2005-11-12 4:42 ` Coywolf Qi Hunt
0 siblings, 1 reply; 13+ messages in thread
From: Bodo Eggert @ 2005-11-11 23:03 UTC (permalink / raw)
To: coywolf, linux-kernel, Arjan van de Ven, Josh Boyer, ak, akpm
Coywolf Qi Hunt <coywolf@sosdg.org> wrote:
> +++ 2.6.14-mm2-cy/init/main.c 2005-11-12 02:50:45.000000000 +0800
...
> +void mark_text_ro(void)
...
> + printk ("Write protecting the kernel text data: %luk\n",
> + (unsigned long)(_etext - _text) >> 10);
This message should have a priority level, shouldn't it?
--
Ich danke GMX dafür, die Verwendung meiner Adressen mittels per SPF
verbreiteten Lügen zu sabotieren.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [patch] mark text section read-only
2005-11-11 23:03 ` [patch] mark text section read-only Bodo Eggert
@ 2005-11-12 4:42 ` Coywolf Qi Hunt
0 siblings, 0 replies; 13+ messages in thread
From: Coywolf Qi Hunt @ 2005-11-12 4:42 UTC (permalink / raw)
To: 7eggert; +Cc: linux-kernel, Arjan van de Ven, Josh Boyer, ak, akpm
On Sat, Nov 12, 2005 at 12:03:51AM +0100, Bodo Eggert wrote:
> Coywolf Qi Hunt <coywolf@sosdg.org> wrote:
>
> > +++ 2.6.14-mm2-cy/init/main.c 2005-11-12 02:50:45.000000000 +0800
> ...
> > +void mark_text_ro(void)
> ...
> > + printk ("Write protecting the kernel text data: %luk\n",
> > + (unsigned long)(_etext - _text) >> 10);
>
> This message should have a priority level, shouldn't it?
It doesn't matter. It will fall back into the default level.
Coywolf
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [patch] mark text section read-only
2005-11-11 19:04 ` [patch] mark text section read-only Coywolf Qi Hunt
` (2 preceding siblings ...)
2005-11-11 21:43 ` Andi Kleen
@ 2005-11-14 13:34 ` Linh Dang
3 siblings, 0 replies; 13+ messages in thread
From: Linh Dang @ 2005-11-14 13:34 UTC (permalink / raw)
To: linux-kernel
on PPC32, the kernel uses memory thru BAT registers. How would this
works?
--
Linh Dang
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [patch] mark text section read-only
2005-11-12 16:34 ` Coywolf Qi Hunt
@ 2005-11-13 4:50 ` Keith Owens
0 siblings, 0 replies; 13+ messages in thread
From: Keith Owens @ 2005-11-13 4:50 UTC (permalink / raw)
To: coywolf; +Cc: akpm, Andi Kleen, linux-kernel, Arjan van de Ven, Josh Boyer
On Sat, 12 Nov 2005 11:34:55 -0500,
Coywolf Qi Hunt <coywolf@sosdg.org> wrote:
>+config DEBUG_ROTEXT
>+ bool "Write protect kernel text"
>+ depends on DEBUG_KERNEL
>+ help
>+ Mark the kernel text as write-protected in the pagetables,
>+ in order to catch accidental (and incorrect) writes to kernel text
>+ area. This option will increase TLB pressure thus impact performance.
>+ Note this may conflict with kprobes. If in doubt, say "N".
Also conflicts with kdb, kgdb, and any other kernel debugger that uses
software breakpoints.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [patch] mark text section read-only
2005-11-11 23:30 ` Nikita Danilov
@ 2005-11-12 17:26 ` Andi Kleen
0 siblings, 0 replies; 13+ messages in thread
From: Andi Kleen @ 2005-11-12 17:26 UTC (permalink / raw)
To: Nikita Danilov; +Cc: linux-kernel, Arjan van de Ven, Josh Boyer, akpm
On Saturday 12 November 2005 00:30, Nikita Danilov wrote:
> Andi Kleen writes:
>
> [...]
>
> >
> > Overall I doubt it is worth it even as a debugging option. I so far cannot
> > remember a single bug that was caused by overwriting kernel text.
>
> I wouldn't forget that one for a long time:
>
> http://marc.theaimsgroup.com/?l=linux-kernel&m=106503116306729&w=2
Ok then maybe as a debug CONFIG, but definitely not default.
-Andi
^ permalink raw reply [flat|nested] 13+ messages in thread
* [patch] mark text section read-only
2005-11-12 14:32 ` Coywolf Qi Hunt
@ 2005-11-12 16:34 ` Coywolf Qi Hunt
2005-11-13 4:50 ` Keith Owens
0 siblings, 1 reply; 13+ messages in thread
From: Coywolf Qi Hunt @ 2005-11-12 16:34 UTC (permalink / raw)
To: akpm; +Cc: Andi Kleen, linux-kernel, Arjan van de Ven, Josh Boyer, akpm
On Sat, Nov 12, 2005 at 10:32:34PM +0800, Coywolf Qi Hunt wrote:
> 2005/11/12, Andi Kleen <ak@suse.de>:
> > On Friday 11 November 2005 20:04, Coywolf Qi Hunt wrote:
> > > On Sat, Nov 12, 2005 at 02:57:02AM +0800, Coywolf Qi Hunt wrote:
> > > > And we could also mark text section read-only and data/stack section
> > > > noexec if NX is supported. But I doubt the whole thing would really
> > > > help much. Kill the kernel thread? We can't. We only run into a panic.
> > > > Anyway I'd attach a quick patch to mark text section read only in the
> > > > next mail.
> >
> >
> > I think this whole thing is only usable as a debugging option. It shouldn't
> > be used by default on production systems because it will increase TLB
> > pressure by splitting up the large pages used by kernel. And TLB pressure
> > is critical in many workloads.
> >
> > It definitely shouldn't be on by default.
> >
> > Then the text section will likely not be page aligned, so it would be
> > surprising if it even worked.
>
> It works. I have tested it with { c=_stext[0]; _stext[0]=c;}. No
> effect when it's disabled; panic when it's enabled.
>
> The symbol `_text' is always page aligned. `_etext' is not, but we don't care.
>
> (Bugs: It would conflict with kprobes.)
>
> >
> > At least on x86-64 it is pretty useless too because the .text section can
> > be accessed over its alias in the direct mapping.
>
> OK, for x86 only then.
>
> >
> > Overall I doubt it is worth it even as a debugging option. I so far cannot
> > remember a single bug that was caused by overwriting kernel text.
>
> I had the same concern basically. But I am convinced after seeing the
> bug Nikita Danilov points out.
Mark text section read-only for debug purpose. This is paranoid, but useful to
guard on some bugs.
Signed-off-by: Coywolf Qi Hunt <qiyong@fc-cn.com>
---
arch/i386/Kconfig.debug | 9 +++++++++
arch/i386/mm/init.c | 15 ++++++++++++++-
init/main.c | 10 +++++++++-
3 files changed, 32 insertions(+), 2 deletions(-)
diff -pruN 2.6.14-mm2/arch/i386/Kconfig.debug 2.6.14-mm2-cy/arch/i386/Kconfig.debug
--- 2.6.14-mm2/arch/i386/Kconfig.debug 2005-11-11 22:33:28.000000000 +0800
+++ 2.6.14-mm2-cy/arch/i386/Kconfig.debug 2005-11-12 23:10:23.000000000 +0800
@@ -42,6 +42,15 @@ config DEBUG_PAGEALLOC
This results in a large slowdown, but helps to find certain types
of memory corruptions.
+config DEBUG_ROTEXT
+ bool "Write protect kernel text"
+ depends on DEBUG_KERNEL
+ help
+ Mark the kernel text as write-protected in the pagetables,
+ in order to catch accidental (and incorrect) writes to kernel text
+ area. This option will increase TLB pressure thus impact performance.
+ Note this may conflict with kprobes. If in doubt, say "N".
+
config DEBUG_RODATA
bool "Write protect kernel read-only data structures"
depends on DEBUG_KERNEL
diff -pruN 2.6.14-mm2/arch/i386/mm/init.c 2.6.14-mm2-cy/arch/i386/mm/init.c
--- 2.6.14-mm2/arch/i386/mm/init.c 2005-11-11 22:33:29.000000000 +0800
+++ 2.6.14-mm2-cy/arch/i386/mm/init.c 2005-11-12 23:07:12.000000000 +0800
@@ -735,8 +735,21 @@ void free_initmem(void)
printk (KERN_INFO "Freeing unused kernel memory: %dk freed\n", (__init_end - __init_begin) >> 10);
}
-#ifdef CONFIG_DEBUG_RODATA
+#ifdef CONFIG_DEBUG_ROTEXT
+void mark_text_ro(void)
+{
+ unsigned long addr = (unsigned long)&_text;
+
+ for (; addr < (unsigned long)&_etext; addr += PAGE_SIZE)
+ change_page_attr(virt_to_page(addr), 1, PAGE_KERNEL_RO);
+
+ printk ("Write protecting the kernel text data: %luk\n",
+ (unsigned long)(_etext - _text) >> 10);
+ global_flush_tlb();
+}
+#endif
+#ifdef CONFIG_DEBUG_RODATA
extern char __start_rodata, __end_rodata;
void mark_rodata_ro(void)
{
diff -pruN 2.6.14-mm2/init/main.c 2.6.14-mm2-cy/init/main.c
--- 2.6.14-mm2/init/main.c 2005-11-11 22:34:21.000000000 +0800
+++ 2.6.14-mm2-cy/init/main.c 2005-11-12 23:07:12.000000000 +0800
@@ -100,8 +100,15 @@ extern void acpi_early_init(void);
#else
static inline void acpi_early_init(void) { }
#endif
+
+#ifdef CONFIG_DEBUG_ROTEXT
+ extern void mark_text_ro(void);
+#else
+ static inline void mark_text_ro(void) { }
+#endif
+
#ifndef CONFIG_DEBUG_RODATA
-inline void mark_rodata_ro(void) { }
+static inline void mark_rodata_ro(void) { }
#endif
#ifdef CONFIG_TC
@@ -716,6 +723,7 @@ static int init(void * unused)
*/
free_initmem();
unlock_kernel();
+ mark_text_ro();
mark_rodata_ro();
system_state = SYSTEM_RUNNING;
numa_default_policy();
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [patch] mark text section read-only
2005-11-11 21:43 ` Andi Kleen
2005-11-11 23:30 ` Nikita Danilov
@ 2005-11-12 14:32 ` Coywolf Qi Hunt
2005-11-12 16:34 ` Coywolf Qi Hunt
1 sibling, 1 reply; 13+ messages in thread
From: Coywolf Qi Hunt @ 2005-11-12 14:32 UTC (permalink / raw)
To: Andi Kleen; +Cc: coywolf, linux-kernel, Arjan van de Ven, Josh Boyer, akpm
2005/11/12, Andi Kleen <ak@suse.de>:
> On Friday 11 November 2005 20:04, Coywolf Qi Hunt wrote:
> > On Sat, Nov 12, 2005 at 02:57:02AM +0800, Coywolf Qi Hunt wrote:
> > > And we could also mark text section read-only and data/stack section
> > > noexec if NX is supported. But I doubt the whole thing would really
> > > help much. Kill the kernel thread? We can't. We only run into a panic.
> > > Anyway I'd attach a quick patch to mark text section read only in the
> > > next mail.
>
>
> I think this whole thing is only usable as a debugging option. It shouldn't
> be used by default on production systems because it will increase TLB
> pressure by splitting up the large pages used by kernel. And TLB pressure
> is critical in many workloads.
>
> It definitely shouldn't be on by default.
>
> Then the text section will likely not be page aligned, so it would be
> surprising if it even worked.
It works. I have tested it with { c=_stext[0]; _stext[0]=c;}. No
effect when it's disabled; panic when it's enabled.
The symbol `_text' is always page aligned. `_etext' is not, but we don't care.
(Bugs: It would conflict with kprobes.)
>
> At least on x86-64 it is pretty useless too because the .text section can
> be accessed over its alias in the direct mapping.
OK, for x86 only then.
>
> Overall I doubt it is worth it even as a debugging option. I so far cannot
> remember a single bug that was caused by overwriting kernel text.
I had the same concern basically. But I am convinced after seeing the
bug Nikita Danilov points out.
--
Coywolf Qi Hunt
http://sosdg.org/~coywolf/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [patch] mark text section read-only
2005-11-11 19:34 ` linux-os (Dick Johnson)
@ 2005-11-12 14:01 ` Coywolf Qi Hunt
0 siblings, 0 replies; 13+ messages in thread
From: Coywolf Qi Hunt @ 2005-11-12 14:01 UTC (permalink / raw)
To: linux-os (Dick Johnson)
Cc: Coywolf Qi Hunt, Linux kernel, Arjan van de Ven, Josh Boyer, ak, akpm
2005/11/12, linux-os (Dick Johnson) <linux-os@analogic.com>:
>
> On Fri, 11 Nov 2005, Coywolf Qi Hunt wrote:
>
> > On Sat, Nov 12, 2005 at 02:57:02AM +0800, Coywolf Qi Hunt wrote:
> >> And we could also mark text section read-only and data/stack section
> >> noexec if NX is supported. But I doubt the whole thing would really
> >> help much. Kill the kernel thread? We can't. We only run into a panic.
> >> Anyway I'd attach a quick patch to mark text section read only in the
> >> next mail.
> >>
> >> If it's ok, I'd add Kconfig support. Comments?
> >
> >
> > Signed-off-by: Coywolf Qi Hunt <qiyong@fc-cn.com>
> > ---
> >
> > diff -pruN 2.6.14-mm2/init/main.c 2.6.14-mm2-cy/init/main.c
> > --- 2.6.14-mm2/init/main.c 2005-11-11 22:34:21.000000000 +0800
> > +++ 2.6.14-mm2-cy/init/main.c 2005-11-12 02:50:45.000000000 +0800
> > @@ -660,6 +660,18 @@ static inline void fixup_cpu_present_map
> > #endif
> > }
> >
> > +void mark_text_ro(void)
> > +{
> > + unsigned long addr = (unsigned long)&_text;
> > +
> > + for (; addr < (unsigned long)&_etext; addr += PAGE_SIZE)
> > + change_page_attr(virt_to_page(addr), 1, PAGE_KERNEL_RO);
> > +
> > + printk ("Write protecting the kernel text data: %luk\n",
> > + (unsigned long)(_etext - _text) >> 10);
> > + global_flush_tlb();
> > +}
> > +
> > static int init(void * unused)
> > {
> > lock_kernel();
> > @@ -716,6 +728,7 @@ static int init(void * unused)
> > */
> > free_initmem();
> > unlock_kernel();
> > + mark_text_ro();
> > mark_rodata_ro();
> > system_state = SYSTEM_RUNNING;
> > numa_default_policy();
> > -
>
>
> Assuming ix86, what is read-only? Certainly the text section needs
> to be marked execute!
>
> So is it:
> Execute-Only
> Execute-Only, accessed
> Execute/Read
> Execute/Read, accessed
> Execute-only, conforming
> Execute-only, conforming, accessed
> Execute/Read-Only, conforming
> Execute/Read-Only, conforming, accessed.
> (all from page 5-12 of ix484 programmer's reference)
>
> ????
>
> You need to WRITE to the text segment to be able to load executables
> (modules) and kernel threads. The user-mode code, children of `init`
> need to have writable .text segments to be able to exec().
Ah, thanks, Mr Wrong.
>
> Cheers,
> Dick Johnson
> Penguin : Linux version 2.6.13.4 on an i686 machine (5589.48 BogoMips).
> Warning : 98.36% of all statistics are fiction.
> .
>
> ****************************************************************
> The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to DeliveryErrors@analogic.com - and destroy all copies of this information, including any attachments, without reading or disclosing them.
>
> Thank you.
>
--
Coywolf Qi Hunt
http://sosdg.org/~coywolf/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [patch] mark text section read-only
2005-11-11 21:43 ` Andi Kleen
@ 2005-11-11 23:30 ` Nikita Danilov
2005-11-12 17:26 ` Andi Kleen
2005-11-12 14:32 ` Coywolf Qi Hunt
1 sibling, 1 reply; 13+ messages in thread
From: Nikita Danilov @ 2005-11-11 23:30 UTC (permalink / raw)
To: Andi Kleen; +Cc: linux-kernel, Arjan van de Ven, Josh Boyer, akpm
Andi Kleen writes:
[...]
>
> Overall I doubt it is worth it even as a debugging option. I so far cannot
> remember a single bug that was caused by overwriting kernel text.
I wouldn't forget that one for a long time:
http://marc.theaimsgroup.com/?l=linux-kernel&m=106503116306729&w=2
>
> -Andi
>
Nikita.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [patch] mark text section read-only
2005-11-11 19:04 ` [patch] mark text section read-only Coywolf Qi Hunt
2005-11-11 19:09 ` Arjan van de Ven
2005-11-11 19:34 ` linux-os (Dick Johnson)
@ 2005-11-11 21:43 ` Andi Kleen
2005-11-11 23:30 ` Nikita Danilov
2005-11-12 14:32 ` Coywolf Qi Hunt
2005-11-14 13:34 ` Linh Dang
3 siblings, 2 replies; 13+ messages in thread
From: Andi Kleen @ 2005-11-11 21:43 UTC (permalink / raw)
To: coywolf; +Cc: linux-kernel, Arjan van de Ven, Josh Boyer, akpm
On Friday 11 November 2005 20:04, Coywolf Qi Hunt wrote:
> On Sat, Nov 12, 2005 at 02:57:02AM +0800, Coywolf Qi Hunt wrote:
> > And we could also mark text section read-only and data/stack section
> > noexec if NX is supported. But I doubt the whole thing would really
> > help much. Kill the kernel thread? We can't. We only run into a panic.
> > Anyway I'd attach a quick patch to mark text section read only in the
> > next mail.
I think this whole thing is only usable as a debugging option. It shouldn't
be used by default on production systems because it will increase TLB
pressure by splitting up the large pages used by kernel. And TLB pressure
is critical in many workloads.
It definitely shouldn't be on by default.
Then the text section will likely not be page aligned, so it would be
surprising if it even worked.
At least on x86-64 it is pretty useless too because the .text section can
be accessed over its alias in the direct mapping.
Overall I doubt it is worth it even as a debugging option. I so far cannot
remember a single bug that was caused by overwriting kernel text.
-Andi
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [patch] mark text section read-only
2005-11-11 19:04 ` [patch] mark text section read-only Coywolf Qi Hunt
2005-11-11 19:09 ` Arjan van de Ven
@ 2005-11-11 19:34 ` linux-os (Dick Johnson)
2005-11-12 14:01 ` Coywolf Qi Hunt
2005-11-11 21:43 ` Andi Kleen
2005-11-14 13:34 ` Linh Dang
3 siblings, 1 reply; 13+ messages in thread
From: linux-os (Dick Johnson) @ 2005-11-11 19:34 UTC (permalink / raw)
To: Coywolf Qi Hunt; +Cc: Linux kernel, Arjan van de Ven, Josh Boyer, ak, akpm
On Fri, 11 Nov 2005, Coywolf Qi Hunt wrote:
> On Sat, Nov 12, 2005 at 02:57:02AM +0800, Coywolf Qi Hunt wrote:
>> And we could also mark text section read-only and data/stack section
>> noexec if NX is supported. But I doubt the whole thing would really
>> help much. Kill the kernel thread? We can't. We only run into a panic.
>> Anyway I'd attach a quick patch to mark text section read only in the
>> next mail.
>>
>> If it's ok, I'd add Kconfig support. Comments?
>
>
> Signed-off-by: Coywolf Qi Hunt <qiyong@fc-cn.com>
> ---
>
> diff -pruN 2.6.14-mm2/init/main.c 2.6.14-mm2-cy/init/main.c
> --- 2.6.14-mm2/init/main.c 2005-11-11 22:34:21.000000000 +0800
> +++ 2.6.14-mm2-cy/init/main.c 2005-11-12 02:50:45.000000000 +0800
> @@ -660,6 +660,18 @@ static inline void fixup_cpu_present_map
> #endif
> }
>
> +void mark_text_ro(void)
> +{
> + unsigned long addr = (unsigned long)&_text;
> +
> + for (; addr < (unsigned long)&_etext; addr += PAGE_SIZE)
> + change_page_attr(virt_to_page(addr), 1, PAGE_KERNEL_RO);
> +
> + printk ("Write protecting the kernel text data: %luk\n",
> + (unsigned long)(_etext - _text) >> 10);
> + global_flush_tlb();
> +}
> +
> static int init(void * unused)
> {
> lock_kernel();
> @@ -716,6 +728,7 @@ static int init(void * unused)
> */
> free_initmem();
> unlock_kernel();
> + mark_text_ro();
> mark_rodata_ro();
> system_state = SYSTEM_RUNNING;
> numa_default_policy();
> -
Assuming ix86, what is read-only? Certainly the text section needs
to be marked execute!
So is it:
Execute-Only
Execute-Only, accessed
Execute/Read
Execute/Read, accessed
Execute-only, conforming
Execute-only, conforming, accessed
Execute/Read-Only, conforming
Execute/Read-Only, conforming, accessed.
(all from page 5-12 of ix484 programmer's reference)
????
You need to WRITE to the text segment to be able to load executables
(modules) and kernel threads. The user-mode code, children of `init`
need to have writable .text segments to be able to exec().
Cheers,
Dick Johnson
Penguin : Linux version 2.6.13.4 on an i686 machine (5589.48 BogoMips).
Warning : 98.36% of all statistics are fiction.
.
****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to DeliveryErrors@analogic.com - and destroy all copies of this information, including any attachments, without reading or disclosing them.
Thank you.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [patch] mark text section read-only
2005-11-11 19:04 ` [patch] mark text section read-only Coywolf Qi Hunt
@ 2005-11-11 19:09 ` Arjan van de Ven
2005-11-11 19:34 ` linux-os (Dick Johnson)
` (2 subsequent siblings)
3 siblings, 0 replies; 13+ messages in thread
From: Arjan van de Ven @ 2005-11-11 19:09 UTC (permalink / raw)
To: coywolf; +Cc: linux-kernel, Josh Boyer, ak, akpm
On Fri, 2005-11-11 at 14:04 -0500, Coywolf Qi Hunt wrote:
> On Sat, Nov 12, 2005 at 02:57:02AM +0800, Coywolf Qi Hunt wrote:
> > And we could also mark text section read-only and data/stack section
> > noexec if NX is supported. But I doubt the whole thing would really
> > help much. Kill the kernel thread? We can't. We only run into a panic.
> > Anyway I'd attach a quick patch to mark text section read only in the
> > next mail.
> >
> > If it's ok, I'd add Kconfig support. Comments?
>
change_page_attr() is only available on x86 and x86-64 so it needs to be
in arch/ somewhere...
^ permalink raw reply [flat|nested] 13+ messages in thread
* [patch] mark text section read-only
2005-11-11 18:57 ` Coywolf Qi Hunt
@ 2005-11-11 19:04 ` Coywolf Qi Hunt
2005-11-11 19:09 ` Arjan van de Ven
` (3 more replies)
0 siblings, 4 replies; 13+ messages in thread
From: Coywolf Qi Hunt @ 2005-11-11 19:04 UTC (permalink / raw)
To: linux-kernel; +Cc: Arjan van de Ven, Josh Boyer, ak, akpm
On Sat, Nov 12, 2005 at 02:57:02AM +0800, Coywolf Qi Hunt wrote:
> And we could also mark text section read-only and data/stack section
> noexec if NX is supported. But I doubt the whole thing would really
> help much. Kill the kernel thread? We can't. We only run into a panic.
> Anyway I'd attach a quick patch to mark text section read only in the
> next mail.
>
> If it's ok, I'd add Kconfig support. Comments?
Signed-off-by: Coywolf Qi Hunt <qiyong@fc-cn.com>
---
diff -pruN 2.6.14-mm2/init/main.c 2.6.14-mm2-cy/init/main.c
--- 2.6.14-mm2/init/main.c 2005-11-11 22:34:21.000000000 +0800
+++ 2.6.14-mm2-cy/init/main.c 2005-11-12 02:50:45.000000000 +0800
@@ -660,6 +660,18 @@ static inline void fixup_cpu_present_map
#endif
}
+void mark_text_ro(void)
+{
+ unsigned long addr = (unsigned long)&_text;
+
+ for (; addr < (unsigned long)&_etext; addr += PAGE_SIZE)
+ change_page_attr(virt_to_page(addr), 1, PAGE_KERNEL_RO);
+
+ printk ("Write protecting the kernel text data: %luk\n",
+ (unsigned long)(_etext - _text) >> 10);
+ global_flush_tlb();
+}
+
static int init(void * unused)
{
lock_kernel();
@@ -716,6 +728,7 @@ static int init(void * unused)
*/
free_initmem();
unlock_kernel();
+ mark_text_ro();
mark_rodata_ro();
system_state = SYSTEM_RUNNING;
numa_default_policy();
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2005-11-14 13:34 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <56cTZ-2PF-5@gated-at.bofh.it>
[not found] ` <56cTZ-2PF-3@gated-at.bofh.it>
[not found] ` <56fRE-7wr-21@gated-at.bofh.it>
[not found] ` <56gaT-7Un-17@gated-at.bofh.it>
[not found] ` <57DHW-jb-21@gated-at.bofh.it>
[not found] ` <57DHW-jb-19@gated-at.bofh.it>
[not found] ` <57Mia-4BG-5@gated-at.bofh.it>
[not found] ` <57MrY-50s-39@gated-at.bofh.it>
2005-11-11 23:03 ` [patch] mark text section read-only Bodo Eggert
2005-11-12 4:42 ` Coywolf Qi Hunt
2005-11-07 10:56 [patch 01/02] Debug option to write-protect rodata: change_page_attr fixes arjan
2005-11-07 10:58 ` [patch 02/02] Debug option to write-protect rodata: the write protect logic and config option arjan
2005-11-07 14:06 ` Josh Boyer
2005-11-07 14:20 ` Arjan van de Ven
2005-11-11 9:39 ` Coywolf Qi Hunt
2005-11-11 9:47 ` Arjan van de Ven
2005-11-11 18:57 ` Coywolf Qi Hunt
2005-11-11 19:04 ` [patch] mark text section read-only Coywolf Qi Hunt
2005-11-11 19:09 ` Arjan van de Ven
2005-11-11 19:34 ` linux-os (Dick Johnson)
2005-11-12 14:01 ` Coywolf Qi Hunt
2005-11-11 21:43 ` Andi Kleen
2005-11-11 23:30 ` Nikita Danilov
2005-11-12 17:26 ` Andi Kleen
2005-11-12 14:32 ` Coywolf Qi Hunt
2005-11-12 16:34 ` Coywolf Qi Hunt
2005-11-13 4:50 ` Keith Owens
2005-11-14 13:34 ` Linh Dang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®