linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc/nohash: fix pte_access_permitted()
@ 2018-08-21 13:03 Christophe Leroy
  2018-08-21 14:25 ` Aneesh Kumar K.V
  2018-08-23 14:18 ` Michael Ellerman
  0 siblings, 2 replies; 4+ messages in thread
From: Christophe Leroy @ 2018-08-21 13:03 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, aneesh.kumar
  Cc: linux-kernel, linuxppc-dev, stable

Commit 5769beaf180a8 ("powerpc/mm: Add proper pte access check helper
for other platforms") replaced generic pte_access_permitted() by an
arch specific one.

The generic one is defined as
(pte_present(pte) && (!(write) || pte_write(pte)))

The arch specific one is open coded checking that _PAGE_USER and
_PAGE_WRITE (_PAGE_RW) flags are set, but lacking to check that
_PAGE_RO and _PAGE_PRIVILEGED are unset, leading to a useless test
on targets like the 8xx which defines _PAGE_RW and _PAGE_USER as 0.

Commit 5fa5b16be5b31 ("powerpc/mm/hugetlb: Use pte_access_permitted
for hugetlb access check") replaced some tests performed with
pte helpers by a call to pte_access_permitted(), leading to the same
issue.

This patch rewrites powerpc/nohash pte_access_permitted()
using pte helpers.

Fixes: 5769beaf180a8 ("powerpc/mm: Add proper pte access check helper for other platforms")
Fixes: 5fa5b16be5b31 ("powerpc/mm/hugetlb: Use pte_access_permitted for hugetlb access check")
Cc: stable@vger.kernel.org # v4.15+
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
 arch/powerpc/include/asm/nohash/pgtable.h | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/nohash/pgtable.h b/arch/powerpc/include/asm/nohash/pgtable.h
index 2160be2e4339..b321c82b3624 100644
--- a/arch/powerpc/include/asm/nohash/pgtable.h
+++ b/arch/powerpc/include/asm/nohash/pgtable.h
@@ -51,17 +51,14 @@ static inline int pte_present(pte_t pte)
 #define pte_access_permitted pte_access_permitted
 static inline bool pte_access_permitted(pte_t pte, bool write)
 {
-	unsigned long pteval = pte_val(pte);
 	/*
 	 * A read-only access is controlled by _PAGE_USER bit.
 	 * We have _PAGE_READ set for WRITE and EXECUTE
 	 */
-	unsigned long need_pte_bits = _PAGE_PRESENT | _PAGE_USER;
-
-	if (write)
-		need_pte_bits |= _PAGE_WRITE;
+	if (!pte_present(pte) || !pte_user(pte) || !pte_read(pte))
+		return false;
 
-	if ((pteval & need_pte_bits) != need_pte_bits)
+	if (write && !pte_write(pte))
 		return false;
 
 	return true;
-- 
2.13.3


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

* Re: [PATCH] powerpc/nohash: fix pte_access_permitted()
  2018-08-21 13:03 [PATCH] powerpc/nohash: fix pte_access_permitted() Christophe Leroy
@ 2018-08-21 14:25 ` Aneesh Kumar K.V
  2018-08-21 14:47   ` Christophe LEROY
  2018-08-23 14:18 ` Michael Ellerman
  1 sibling, 1 reply; 4+ messages in thread
From: Aneesh Kumar K.V @ 2018-08-21 14:25 UTC (permalink / raw)
  To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras,
	Michael Ellerman, aneesh.kumar
  Cc: linuxppc-dev, linux-kernel, stable

Christophe Leroy <christophe.leroy@c-s.fr> writes:

> Commit 5769beaf180a8 ("powerpc/mm: Add proper pte access check helper
> for other platforms") replaced generic pte_access_permitted() by an
> arch specific one.
>
> The generic one is defined as
> (pte_present(pte) && (!(write) || pte_write(pte)))
>
> The arch specific one is open coded checking that _PAGE_USER and
> _PAGE_WRITE (_PAGE_RW) flags are set, but lacking to check that
> _PAGE_RO and _PAGE_PRIVILEGED are unset, leading to a useless test
> on targets like the 8xx which defines _PAGE_RW and _PAGE_USER as 0.
>
> Commit 5fa5b16be5b31 ("powerpc/mm/hugetlb: Use pte_access_permitted
> for hugetlb access check") replaced some tests performed with
> pte helpers by a call to pte_access_permitted(), leading to the same
> issue.
>
> This patch rewrites powerpc/nohash pte_access_permitted()
> using pte helpers.
>

Thanks for fixing this. I should have used the helper instead of
opencoding it on nohash platforms. This is another reason why I was also
suggesting we should avoid consolidating pte accessors across platforms
and user accessors instead of opencoding. 

https://lore.kernel.org/lkml/87lgcusc6z.fsf@linux.vnet.ibm.com/T/#u

Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>

> Fixes: 5769beaf180a8 ("powerpc/mm: Add proper pte access check helper for other platforms")
> Fixes: 5fa5b16be5b31 ("powerpc/mm/hugetlb: Use pte_access_permitted for hugetlb access check")
> Cc: stable@vger.kernel.org # v4.15+
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
> ---
>  arch/powerpc/include/asm/nohash/pgtable.h | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/nohash/pgtable.h b/arch/powerpc/include/asm/nohash/pgtable.h
> index 2160be2e4339..b321c82b3624 100644
> --- a/arch/powerpc/include/asm/nohash/pgtable.h
> +++ b/arch/powerpc/include/asm/nohash/pgtable.h
> @@ -51,17 +51,14 @@ static inline int pte_present(pte_t pte)
>  #define pte_access_permitted pte_access_permitted
>  static inline bool pte_access_permitted(pte_t pte, bool write)
>  {
> -	unsigned long pteval = pte_val(pte);
>  	/*
>  	 * A read-only access is controlled by _PAGE_USER bit.
>  	 * We have _PAGE_READ set for WRITE and EXECUTE
>  	 */
> -	unsigned long need_pte_bits = _PAGE_PRESENT | _PAGE_USER;
> -
> -	if (write)
> -		need_pte_bits |= _PAGE_WRITE;
> +	if (!pte_present(pte) || !pte_user(pte) || !pte_read(pte))
> +		return false;
>  
> -	if ((pteval & need_pte_bits) != need_pte_bits)
> +	if (write && !pte_write(pte))
>  		return false;
>  
>  	return true;
> -- 
> 2.13.3


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

* Re: [PATCH] powerpc/nohash: fix pte_access_permitted()
  2018-08-21 14:25 ` Aneesh Kumar K.V
@ 2018-08-21 14:47   ` Christophe LEROY
  0 siblings, 0 replies; 4+ messages in thread
From: Christophe LEROY @ 2018-08-21 14:47 UTC (permalink / raw)
  To: Aneesh Kumar K.V, Benjamin Herrenschmidt, Paul Mackerras,
	Michael Ellerman, aneesh.kumar
  Cc: linuxppc-dev, linux-kernel, stable



Le 21/08/2018 à 16:25, Aneesh Kumar K.V a écrit :
> Christophe Leroy <christophe.leroy@c-s.fr> writes:
> 
>> Commit 5769beaf180a8 ("powerpc/mm: Add proper pte access check helper
>> for other platforms") replaced generic pte_access_permitted() by an
>> arch specific one.
>>
>> The generic one is defined as
>> (pte_present(pte) && (!(write) || pte_write(pte)))
>>
>> The arch specific one is open coded checking that _PAGE_USER and
>> _PAGE_WRITE (_PAGE_RW) flags are set, but lacking to check that
>> _PAGE_RO and _PAGE_PRIVILEGED are unset, leading to a useless test
>> on targets like the 8xx which defines _PAGE_RW and _PAGE_USER as 0.
>>
>> Commit 5fa5b16be5b31 ("powerpc/mm/hugetlb: Use pte_access_permitted
>> for hugetlb access check") replaced some tests performed with
>> pte helpers by a call to pte_access_permitted(), leading to the same
>> issue.
>>
>> This patch rewrites powerpc/nohash pte_access_permitted()
>> using pte helpers.
>>
> 
> Thanks for fixing this. I should have used the helper instead of
> opencoding it on nohash platforms. This is another reason why I was also
> suggesting we should avoid consolidating pte accessors across platforms
> and user accessors instead of opencoding.

I fully agree. I have opened a topic for that at 
https://github.com/linuxppc/linux/issues/177

Christophe

> 
> https://lore.kernel.org/lkml/87lgcusc6z.fsf@linux.vnet.ibm.com/T/#u
> 
> Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
> 
>> Fixes: 5769beaf180a8 ("powerpc/mm: Add proper pte access check helper for other platforms")
>> Fixes: 5fa5b16be5b31 ("powerpc/mm/hugetlb: Use pte_access_permitted for hugetlb access check")
>> Cc: stable@vger.kernel.org # v4.15+
>> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
>> ---
>>   arch/powerpc/include/asm/nohash/pgtable.h | 9 +++------
>>   1 file changed, 3 insertions(+), 6 deletions(-)
>>
>> diff --git a/arch/powerpc/include/asm/nohash/pgtable.h b/arch/powerpc/include/asm/nohash/pgtable.h
>> index 2160be2e4339..b321c82b3624 100644
>> --- a/arch/powerpc/include/asm/nohash/pgtable.h
>> +++ b/arch/powerpc/include/asm/nohash/pgtable.h
>> @@ -51,17 +51,14 @@ static inline int pte_present(pte_t pte)
>>   #define pte_access_permitted pte_access_permitted
>>   static inline bool pte_access_permitted(pte_t pte, bool write)
>>   {
>> -	unsigned long pteval = pte_val(pte);
>>   	/*
>>   	 * A read-only access is controlled by _PAGE_USER bit.
>>   	 * We have _PAGE_READ set for WRITE and EXECUTE
>>   	 */
>> -	unsigned long need_pte_bits = _PAGE_PRESENT | _PAGE_USER;
>> -
>> -	if (write)
>> -		need_pte_bits |= _PAGE_WRITE;
>> +	if (!pte_present(pte) || !pte_user(pte) || !pte_read(pte))
>> +		return false;
>>   
>> -	if ((pteval & need_pte_bits) != need_pte_bits)
>> +	if (write && !pte_write(pte))
>>   		return false;
>>   
>>   	return true;
>> -- 
>> 2.13.3

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

* Re: powerpc/nohash: fix pte_access_permitted()
  2018-08-21 13:03 [PATCH] powerpc/nohash: fix pte_access_permitted() Christophe Leroy
  2018-08-21 14:25 ` Aneesh Kumar K.V
@ 2018-08-23 14:18 ` Michael Ellerman
  1 sibling, 0 replies; 4+ messages in thread
From: Michael Ellerman @ 2018-08-23 14:18 UTC (permalink / raw)
  To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras, aneesh.kumar
  Cc: linuxppc-dev, linux-kernel, stable

On Tue, 2018-08-21 at 13:03:23 UTC, Christophe Leroy wrote:
> Commit 5769beaf180a8 ("powerpc/mm: Add proper pte access check helper
> for other platforms") replaced generic pte_access_permitted() by an
> arch specific one.
> 
> The generic one is defined as
> (pte_present(pte) && (!(write) || pte_write(pte)))
> 
> The arch specific one is open coded checking that _PAGE_USER and
> _PAGE_WRITE (_PAGE_RW) flags are set, but lacking to check that
> _PAGE_RO and _PAGE_PRIVILEGED are unset, leading to a useless test
> on targets like the 8xx which defines _PAGE_RW and _PAGE_USER as 0.
> 
> Commit 5fa5b16be5b31 ("powerpc/mm/hugetlb: Use pte_access_permitted
> for hugetlb access check") replaced some tests performed with
> pte helpers by a call to pte_access_permitted(), leading to the same
> issue.
> 
> This patch rewrites powerpc/nohash pte_access_permitted()
> using pte helpers.
> 
> Fixes: 5769beaf180a8 ("powerpc/mm: Add proper pte access check helper for other platforms")
> Fixes: 5fa5b16be5b31 ("powerpc/mm/hugetlb: Use pte_access_permitted for hugetlb access check")
> Cc: stable@vger.kernel.org # v4.15+
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
> Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/810e9f86f36f59f1d6f6710220c49a

cheers

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

end of thread, other threads:[~2018-08-23 14:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-21 13:03 [PATCH] powerpc/nohash: fix pte_access_permitted() Christophe Leroy
2018-08-21 14:25 ` Aneesh Kumar K.V
2018-08-21 14:47   ` Christophe LEROY
2018-08-23 14:18 ` Michael Ellerman

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