From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967759AbYCTAnP (ORCPT ); Wed, 19 Mar 2008 20:43:15 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1762712AbYCTAjR (ORCPT ); Wed, 19 Mar 2008 20:39:17 -0400 Received: from tomts16.bellnexxia.net ([209.226.175.4]:34520 "EHLO tomts16-srv.bellnexxia.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933799AbYCTAjO (ORCPT ); Wed, 19 Mar 2008 20:39:14 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmcFAAJP4UdMQWoK/2dsb2JhbACBWqkDgg4 Date: Wed, 19 Mar 2008 20:39:09 -0400 From: Mathieu Desnoyers To: Ingo Molnar , linux-kernel@vger.kernel.org Subject: [PATCH] x86 Fix text_poke for vmalloced pages Message-ID: <20080320003908.GA4988@Krystal> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Editor: vi X-Info: http://krystal.dyndns.org:8080 X-Operating-System: Linux/2.6.21.3-grsec (i686) X-Uptime: 20:36:30 up 19 days, 20:47, 6 users, load average: 5.48, 5.27, 5.18 User-Agent: Mutt/1.5.16 (2007-06-11) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. - Changelog: kernel_text_address() -> core_kernel_text(). It applies on top of the x86 git tree, 2.6.25-rc6. Signed-off-by: Mathieu Desnoyers CC: Ingo Molnar --- arch/x86/kernel/alternative.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) Index: linux-2.6-lttng/arch/x86/kernel/alternative.c =================================================================== --- linux-2.6-lttng.orig/arch/x86/kernel/alternative.c 2008-03-19 18:57:29.000000000 -0400 +++ linux-2.6-lttng/arch/x86/kernel/alternative.c 2008-03-19 20:01:10.000000000 -0400 @@ -511,7 +511,7 @@ void *__kprobes text_poke(void *addr, co BUG_ON(len > sizeof(long)); BUG_ON((((long)addr + len - 1) & ~(sizeof(long) - 1)) - ((long)addr & ~(sizeof(long) - 1))); - { + 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); } sync_core(); /* Could also do a CLFLUSH here to speed up CPU recovery; but -- Mathieu Desnoyers Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68