lkml.org 
[lkml]   [2008]   [Apr]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    Subject[patch 05/17] x86 Fix text_poke for vmalloced pages
    The shadow vmap for DEBUG_RODATA kernel text modification uses virt_to_page to
    get the pages from the pointer address and vmalloc_to_page for vmalloc'ed
    pages.

    - Changelog:
    Deal with read-only module text.

    Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
    CC: Ingo Molnar <mingo@elte.hu>
    ---
    arch/x86/kernel/alternative.c | 27 ++++++++++++++++-----------
    1 file changed, 16 insertions(+), 11 deletions(-)

    Index: linux-2.6-lttng/arch/x86/kernel/alternative.c
    ===================================================================
    --- linux-2.6-lttng.orig/arch/x86/kernel/alternative.c 2008-03-24 10:00:30.000000000 -0400
    +++ linux-2.6-lttng/arch/x86/kernel/alternative.c 2008-03-24 10:18:19.000000000 -0400
    @@ -507,22 +507,27 @@ void *__kprobes text_poke(void *addr, co
    unsigned long flags;
    char *vaddr;
    int nr_pages = 2;
    + struct page *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) };
    - if (!pages[1])
    - nr_pages = 1;
    - vaddr = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL);
    - WARN_ON(!vaddr);
    - local_irq_save(flags);
    - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
    - local_irq_restore(flags);
    - vunmap(vaddr);
    + if (is_vmalloc_addr(addr)) {
    + pages[0] = vmalloc_to_page(addr);
    + pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
    + } else {
    + pages[0] = virt_to_page(addr);
    + pages[1] = virt_to_page(addr + PAGE_SIZE);
    }
    + BUG_ON(!pages[0]);
    + if (!pages[1])
    + nr_pages = 1;
    + vaddr = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL);
    + BUG_ON(!vaddr);
    + local_irq_save(flags);
    + memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
    + local_irq_restore(flags);
    + vunmap(vaddr);
    sync_core();
    /* Could also do a CLFLUSH here to speed up CPU recovery; but
    that causes hangs on some VIA CPUs. */
    --
    Mathieu Desnoyers
    Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
    OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68


    \
     
     \ /
      Last update: 2008-04-09 18:23    [W:0.028 / U:61.012 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site