lkml.org 
[lkml]   [2008]   [Mar]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] x86 Fix text_poke for vmalloced pages

* Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> wrote:

> The shadow vmap for DEBUG_RODATA kernel text modification uses
> virt_to_page to get the pages from the pointer address.
>
> However, I think vmalloc_to_page would be required in case the page is
> used for modules.
>
> Since only the core kernel text is marked read-only, use
> core_kernel_text() to make sure we only shadow map the core kernel
> text, not modules.
>
> This is an incremental change to make the DEBUG_RODATA and text_poke
> play together nicely. A future step will be to make the module text
> read-only too, which will require changes to load module, module free
> and text_poke. The idea is to fix the current x86 git tree quickly.

> + if (core_kernel_text((unsigned long)addr)) {
> struct page *pages[2] = { virt_to_page(addr),
> virt_to_page(addr + PAGE_SIZE) };
> if (!pages[1])
> @@ -522,6 +522,13 @@ void *__kprobes text_poke(void *addr, co
> memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
> local_irq_restore(flags);
> vunmap(vaddr);
> + } else {
> + /*
> + * modules are in vmalloc'ed memory, always writable.
> + */
> + local_irq_save(flags);
> + memcpy(addr, opcode, len);
> + local_irq_restore(flags);

hm, this looks ugly, and the whole text_poke() function looks ugly. For
example why the extra code block + indentation here:

+void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
+{
+ unsigned long flags;
+ char *vaddr;
+ int nr_pages = 2;
+
+ BUG_ON(len > sizeof(long));
+ BUG_ON((((long)addr + len - 1) & ~(sizeof(long) - 1))
+ - ((long)addr & ~(sizeof(long) - 1)));
+ {
+ struct page *pages[2] = { virt_to_page(addr),
+ virt_to_page(addr + PAGE_SIZE) };

also, more fundamentally - why not introduce a proper, generic "look up
kernel text struct page *" method, instead of open-coding various
assumptions about which kernel text is readonly and which isnt?

Ingo


\
 
 \ /
  Last update: 2008-03-21 10:41    [W:0.071 / U:0.132 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site