LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Cc: linux-kernel@vger.kernel.org,
	Arjan van de Ven <arjan@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH] x86 Fix text_poke for vmalloced pages
Date: Fri, 21 Mar 2008 10:38:21 +0100	[thread overview]
Message-ID: <20080321093821.GG20420@elte.hu> (raw)
In-Reply-To: <20080320003908.GA4988@Krystal>


* 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

  reply	other threads:[~2008-03-21  9:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-20  0:39 Mathieu Desnoyers
2008-03-21  9:38 ` Ingo Molnar [this message]
2008-03-24 17:02   ` Mathieu Desnoyers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080321093821.GG20420@elte.hu \
    --to=mingo@elte.hu \
    --cc=arjan@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@polymtl.ca \
    --cc=tglx@linutronix.de \
    --subject='Re: [PATCH] x86 Fix text_poke for vmalloced pages' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).