lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20080321093821.GG20420@elte.hu>
Date:	Fri, 21 Mar 2008 10:38:21 +0100
From:	Ingo Molnar <mingo@...e.hu>
To:	Mathieu Desnoyers <mathieu.desnoyers@...ymtl.ca>
Cc:	linux-kernel@...r.kernel.org,
	Arjan van de Ven <arjan@...radead.org>,
	Thomas Gleixner <tglx@...utronix.de>
Subject: Re: [PATCH] x86 Fix text_poke for vmalloced pages


* Mathieu Desnoyers <mathieu.desnoyers@...ymtl.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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ