* [PATCH] powerpc: Fail remap_4k_pfn() if PFN doesn't fit inside PTE
@ 2014-07-09 16:08 Madhusudanan Kandasamy
2014-07-09 22:49 ` Stephen Rothwell
0 siblings, 1 reply; 3+ messages in thread
From: Madhusudanan Kandasamy @ 2014-07-09 16:08 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, linuxppc-dev; +Cc: linux-kernel
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.
Used a helper inline function in the failure case so that the
remap_4k_pfn() macro can still be used in expression contexts.
Signed-off-by: Madhusudanan Kandasamy <kmadhu@linux.vnet.ibm.com>
---
arch/powerpc/include/asm/pte-hash64-64k.h | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/include/asm/pte-hash64-64k.h b/arch/powerpc/include/asm/pte-hash64-64k.h
index d836d94..10af7f1 100644
--- a/arch/powerpc/include/asm/pte-hash64-64k.h
+++ b/arch/powerpc/include/asm/pte-hash64-64k.h
@@ -74,8 +74,15 @@
#define pte_pagesize_index(mm, addr, pte) \
(((pte) & _PAGE_COMBO)? MMU_PAGE_4K: MMU_PAGE_64K)
+static inline int bad_4k_pfn(void)
+{
+ WARN_ON(1);
+ return -EINVAL;
+}
+
#define remap_4k_pfn(vma, addr, pfn, prot) \
- remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE, \
- __pgprot(pgprot_val((prot)) | _PAGE_4K_PFN))
+ ((pfn >= (1UL << (64 - PTE_RPN_SHIFT))) ? bad_4k_pfn() : \
+ 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] 3+ messages in thread
* Re: [PATCH] powerpc: Fail remap_4k_pfn() if PFN doesn't fit inside PTE
2014-07-09 16:08 [PATCH] powerpc: Fail remap_4k_pfn() if PFN doesn't fit inside PTE Madhusudanan Kandasamy
@ 2014-07-09 22:49 ` Stephen Rothwell
2014-07-10 7:46 ` Madhusudanan Kandasamy
0 siblings, 1 reply; 3+ messages in thread
From: Stephen Rothwell @ 2014-07-09 22:49 UTC (permalink / raw)
To: Madhusudanan Kandasamy; +Cc: Paul Mackerras, linux-kernel, linuxppc-dev
[-- Attachment #1: Type: text/plain, Size: 1419 bytes --]
Hi Madhusudanan,
On Wed, 09 Jul 2014 21:38:31 +0530 Madhusudanan Kandasamy <kmadhu@linux.vnet.ibm.com> wrote:
>
> diff --git a/arch/powerpc/include/asm/pte-hash64-64k.h b/arch/powerpc/include/asm/pte-hash64-64k.h
> index d836d94..10af7f1 100644
> --- a/arch/powerpc/include/asm/pte-hash64-64k.h
> +++ b/arch/powerpc/include/asm/pte-hash64-64k.h
> @@ -74,8 +74,15 @@
> #define pte_pagesize_index(mm, addr, pte) \
> (((pte) & _PAGE_COMBO)? MMU_PAGE_4K: MMU_PAGE_64K)
>
> +static inline int bad_4k_pfn(void)
> +{
> + WARN_ON(1);
> + return -EINVAL;
> +}
> +
> #define remap_4k_pfn(vma, addr, pfn, prot) \
> - remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE, \
> - __pgprot(pgprot_val((prot)) | _PAGE_4K_PFN))
> + ((pfn >= (1UL << (64 - PTE_RPN_SHIFT))) ? bad_4k_pfn() : \
> + remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE, \
> + __pgprot(pgprot_val((prot)) | _PAGE_4K_PFN)))
>
> #endif /* __ASSEMBLY__ */
WARN_ON() returns the value it is passed, so no helper is needed:
#define remap_4k_pfn(vma, addr, pfn, prot) \
- remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE, \
- __pgprot(pgprot_val((prot)) | _PAGE_4K_PFN))
+ WARN_ON(((pfn >= (1UL << (64 - PTE_RPN_SHIFT)))) ? -EINVAL : \
+ remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE, \
+ __pgprot(pgprot_val((prot)) | _PAGE_4K_PFN)))
--
Cheers,
Stephen Rothwell sfr@canb.auug.org.au
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] powerpc: Fail remap_4k_pfn() if PFN doesn't fit inside PTE
2014-07-09 22:49 ` Stephen Rothwell
@ 2014-07-10 7:46 ` Madhusudanan Kandasamy
0 siblings, 0 replies; 3+ messages in thread
From: Madhusudanan Kandasamy @ 2014-07-10 7:46 UTC (permalink / raw)
To: Stephen Rothwell; +Cc: Paul Mackerras, linux-kernel, linuxppc-dev
Hi Stephen,
Thanks for the suggestion, I'll send a new patch.
On Thursday 10 July 2014 04:19 AM, Stephen Rothwell wrote:
> Hi Madhusudanan,
>
> On Wed, 09 Jul 2014 21:38:31 +0530 Madhusudanan Kandasamy <kmadhu@linux.vnet.ibm.com> wrote:
>>
>> diff --git a/arch/powerpc/include/asm/pte-hash64-64k.h b/arch/powerpc/include/asm/pte-hash64-64k.h
>> index d836d94..10af7f1 100644
>> --- a/arch/powerpc/include/asm/pte-hash64-64k.h
>> +++ b/arch/powerpc/include/asm/pte-hash64-64k.h
>> @@ -74,8 +74,15 @@
>> #define pte_pagesize_index(mm, addr, pte) \
>> (((pte) & _PAGE_COMBO)? MMU_PAGE_4K: MMU_PAGE_64K)
>>
>> +static inline int bad_4k_pfn(void)
>> +{
>> + WARN_ON(1);
>> + return -EINVAL;
>> +}
>> +
>> #define remap_4k_pfn(vma, addr, pfn, prot) \
>> - remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE, \
>> - __pgprot(pgprot_val((prot)) | _PAGE_4K_PFN))
>> + ((pfn >= (1UL << (64 - PTE_RPN_SHIFT))) ? bad_4k_pfn() : \
>> + remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE, \
>> + __pgprot(pgprot_val((prot)) | _PAGE_4K_PFN)))
>>
>> #endif /* __ASSEMBLY__ */
>
> WARN_ON() returns the value it is passed, so no helper is needed:
>
> #define remap_4k_pfn(vma, addr, pfn, prot) \
> - remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE, \
> - __pgprot(pgprot_val((prot)) | _PAGE_4K_PFN))
> + WARN_ON(((pfn >= (1UL << (64 - PTE_RPN_SHIFT)))) ? -EINVAL : \
> + remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE, \
> + __pgprot(pgprot_val((prot)) | _PAGE_4K_PFN)))
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-07-10 7:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-09 16:08 [PATCH] powerpc: Fail remap_4k_pfn() if PFN doesn't fit inside PTE Madhusudanan Kandasamy
2014-07-09 22:49 ` Stephen Rothwell
2014-07-10 7:46 ` Madhusudanan Kandasamy
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).