All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2] powerpc: Fail remap_4k_pfn() if PFN doesn't fit inside PTE
@ 2014-07-10  8:42 Madhusudanan Kandasamy
  2014-07-10 13:59 ` Brian W Hart
  0 siblings, 1 reply; 2+ messages in thread
From: Madhusudanan Kandasamy @ 2014-07-10  8:42 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, linux-kernel,
	linuxppc-dev, Stephen Rothwell

V2 : Rewritten to avoid helper function as suggested by Stephen Rothwell.
remap_4k_pfn() silently truncates upper bits of input 4K PFN if
it cannot be contained in PTE. This leads invalid memory mapping
and could result in a system crash when the memory is accessed.
This patch fails remap_4k_pfn() and returns -EINVAL if the input
4K PFN cannot be contained in PTE.

Signed-off-by: Madhusudanan Kandasamy <kmadhu@linux.vnet.ibm.com>
---
 arch/powerpc/include/asm/pte-hash64-64k.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/pte-hash64-64k.h b/arch/powerpc/include/asm/pte-hash64-64k.h
index d836d94..b5178e4 100644
--- a/arch/powerpc/include/asm/pte-hash64-64k.h
+++ b/arch/powerpc/include/asm/pte-hash64-64k.h
@@ -75,7 +75,8 @@
 	(((pte) & _PAGE_COMBO)? MMU_PAGE_4K: MMU_PAGE_64K)

 #define remap_4k_pfn(vma, addr, pfn, prot)				\
-	remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE,		\
+	WARN_ON((pfn >= (1UL << (64 - PTE_RPN_SHIFT)))) ? -EINVAL :	\
+		remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE,	\
 			__pgprot(pgprot_val((prot)) | _PAGE_4K_PFN))

 #endif	/* __ASSEMBLY__ */
-- 
2.0.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH V2] powerpc: Fail remap_4k_pfn() if PFN doesn't fit inside PTE
  2014-07-10  8:42 [PATCH V2] powerpc: Fail remap_4k_pfn() if PFN doesn't fit inside PTE Madhusudanan Kandasamy
@ 2014-07-10 13:59 ` Brian W Hart
  0 siblings, 0 replies; 2+ messages in thread
From: Brian W Hart @ 2014-07-10 13:59 UTC (permalink / raw)
  To: linuxppc-dev, linuxppc-dev

On Thu, Jul 10, 2014 at 02:12:19PM +0530, Madhusudanan Kandasamy wrote:
> V2 : Rewritten to avoid helper function as suggested by Stephen Rothwell.
> remap_4k_pfn() silently truncates upper bits of input 4K PFN if
> it cannot be contained in PTE. This leads invalid memory mapping
> and could result in a system crash when the memory is accessed.
> This patch fails remap_4k_pfn() and returns -EINVAL if the input
> 4K PFN cannot be contained in PTE.
> 
> Signed-off-by: Madhusudanan Kandasamy <kmadhu@linux.vnet.ibm.com>
> ---
>  arch/powerpc/include/asm/pte-hash64-64k.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/include/asm/pte-hash64-64k.h b/arch/powerpc/include/asm/pte-hash64-64k.h
> index d836d94..b5178e4 100644
> --- a/arch/powerpc/include/asm/pte-hash64-64k.h
> +++ b/arch/powerpc/include/asm/pte-hash64-64k.h
> @@ -75,7 +75,8 @@
>  	(((pte) & _PAGE_COMBO)? MMU_PAGE_4K: MMU_PAGE_64K)
> 
>  #define remap_4k_pfn(vma, addr, pfn, prot)				\
> -	remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE,		\
> +	WARN_ON((pfn >= (1UL << (64 - PTE_RPN_SHIFT)))) ? -EINVAL :	\
> +		remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE,	\
>  			__pgprot(pgprot_val((prot)) | _PAGE_4K_PFN))
> 
>  #endif	/* __ASSEMBLY__ */
> -- 
> 2.0.1

Chatted with Madhu.  He'll send a new version that adds some
parentheses to protect 'pfn' inside the macro and the entire macro
against use cases like:

    !remap_4k_pfn(...)

brian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-07-10 13:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-10  8:42 [PATCH V2] powerpc: Fail remap_4k_pfn() if PFN doesn't fit inside PTE Madhusudanan Kandasamy
2014-07-10 13:59 ` Brian W Hart

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.