linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2] arm64: Allow vmalloc regions to be set with set_memory_*
@ 2016-01-12 23:22 Laura Abbott
  2016-01-12 23:54 ` Kees Cook
  2016-01-13 13:14 ` Mark Rutland
  0 siblings, 2 replies; 3+ messages in thread
From: Laura Abbott @ 2016-01-12 23:22 UTC (permalink / raw)
  To: linux-arm-kernel


The range of set_memory_* is currently restricted to the module address
range because of difficulties in breaking down larger block sizes.
vmalloc maps PAGE_SIZE pages so it is safe to use as well. Update the
function ranges and add a comment explaining why the range is restricted
the way it is.

Signed-off-by: Laura Abbott <labbott@fedoraproject.org>
---
v2: Old version was sent out with vmalloc warnings. Sorry for the noise.
---
 arch/arm64/mm/pageattr.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c
index 3571c73..88c8e54 100644
--- a/arch/arm64/mm/pageattr.c
+++ b/arch/arm64/mm/pageattr.c
@@ -36,6 +36,26 @@ static int change_page_range(pte_t *ptep, pgtable_t token, unsigned long addr,
 	return 0;
 }
 
+static bool validate_addr(unsigned long start, unsigned long end)
+{
+	/*
+	 * This check explicitly excludes most kernel memory. Most kernel
+	 * memory is mapped with a larger page size and breaking down the
+	 * larger page size without causing TLB conflicts is very difficult.
+	 *
+	 * If you need to call set_memory_* on a range, the recommendation is
+	 * to use vmalloc since that range is mapped with pages.
+	 */
+	if (start >= MODULES_VADDR && start < MODULES_END &&
+	    end >= MODULES_VADDR && end < MODULES_END)
+		return true;
+
+	if (is_vmalloc_addr((void *)start) && is_vmalloc_addr((void *)end))
+		return true;
+
+	return false;
+}
+
 static int change_memory_common(unsigned long addr, int numpages,
 				pgprot_t set_mask, pgprot_t clear_mask)
 {
@@ -51,10 +71,7 @@ static int change_memory_common(unsigned long addr, int numpages,
 		WARN_ON_ONCE(1);
 	}
 
-	if (start < MODULES_VADDR || start >= MODULES_END)
-		return -EINVAL;
-
-	if (end < MODULES_VADDR || end >= MODULES_END)
+	if (!validate_addr(start, end))
 		return -EINVAL;
 
 	data.set_mask = set_mask;
-- 
2.5.0

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

* [PATCHv2] arm64: Allow vmalloc regions to be set with set_memory_*
  2016-01-12 23:22 [PATCHv2] arm64: Allow vmalloc regions to be set with set_memory_* Laura Abbott
@ 2016-01-12 23:54 ` Kees Cook
  2016-01-13 13:14 ` Mark Rutland
  1 sibling, 0 replies; 3+ messages in thread
From: Kees Cook @ 2016-01-12 23:54 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Jan 12, 2016 at 3:22 PM, Laura Abbott <labbott@fedoraproject.org> wrote:
>
> The range of set_memory_* is currently restricted to the module address
> range because of difficulties in breaking down larger block sizes.
> vmalloc maps PAGE_SIZE pages so it is safe to use as well. Update the
> function ranges and add a comment explaining why the range is restricted
> the way it is.
>
> Signed-off-by: Laura Abbott <labbott@fedoraproject.org>

Acked-by: Kees Cook <keescook@chromium.org>

-Kees

> ---
> v2: Old version was sent out with vmalloc warnings. Sorry for the noise.
> ---
>  arch/arm64/mm/pageattr.c | 25 +++++++++++++++++++++----
>  1 file changed, 21 insertions(+), 4 deletions(-)
>
> diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c
> index 3571c73..88c8e54 100644
> --- a/arch/arm64/mm/pageattr.c
> +++ b/arch/arm64/mm/pageattr.c
> @@ -36,6 +36,26 @@ static int change_page_range(pte_t *ptep, pgtable_t token, unsigned long addr,
>         return 0;
>  }
>
> +static bool validate_addr(unsigned long start, unsigned long end)
> +{
> +       /*
> +        * This check explicitly excludes most kernel memory. Most kernel
> +        * memory is mapped with a larger page size and breaking down the
> +        * larger page size without causing TLB conflicts is very difficult.
> +        *
> +        * If you need to call set_memory_* on a range, the recommendation is
> +        * to use vmalloc since that range is mapped with pages.
> +        */
> +       if (start >= MODULES_VADDR && start < MODULES_END &&
> +           end >= MODULES_VADDR && end < MODULES_END)
> +               return true;
> +
> +       if (is_vmalloc_addr((void *)start) && is_vmalloc_addr((void *)end))
> +               return true;
> +
> +       return false;
> +}
> +
>  static int change_memory_common(unsigned long addr, int numpages,
>                                 pgprot_t set_mask, pgprot_t clear_mask)
>  {
> @@ -51,10 +71,7 @@ static int change_memory_common(unsigned long addr, int numpages,
>                 WARN_ON_ONCE(1);
>         }
>
> -       if (start < MODULES_VADDR || start >= MODULES_END)
> -               return -EINVAL;
> -
> -       if (end < MODULES_VADDR || end >= MODULES_END)
> +       if (!validate_addr(start, end))
>                 return -EINVAL;
>
>         data.set_mask = set_mask;
> --
> 2.5.0
>



-- 
Kees Cook
Chrome OS & Brillo Security

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

* [PATCHv2] arm64: Allow vmalloc regions to be set with set_memory_*
  2016-01-12 23:22 [PATCHv2] arm64: Allow vmalloc regions to be set with set_memory_* Laura Abbott
  2016-01-12 23:54 ` Kees Cook
@ 2016-01-13 13:14 ` Mark Rutland
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Rutland @ 2016-01-13 13:14 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Jan 12, 2016 at 03:22:35PM -0800, Laura Abbott wrote:
> 
> The range of set_memory_* is currently restricted to the module address
> range because of difficulties in breaking down larger block sizes.
> vmalloc maps PAGE_SIZE pages so it is safe to use as well. Update the
> function ranges and add a comment explaining why the range is restricted
> the way it is.
> 
> Signed-off-by: Laura Abbott <labbott@fedoraproject.org>
> ---
> v2: Old version was sent out with vmalloc warnings. Sorry for the noise.
> ---
>  arch/arm64/mm/pageattr.c | 25 +++++++++++++++++++++----
>  1 file changed, 21 insertions(+), 4 deletions(-)

Conceptually this looks fine.

Implementation comments below.

> 
> diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c
> index 3571c73..88c8e54 100644
> --- a/arch/arm64/mm/pageattr.c
> +++ b/arch/arm64/mm/pageattr.c
> @@ -36,6 +36,26 @@ static int change_page_range(pte_t *ptep, pgtable_t token, unsigned long addr,
>  	return 0;
>  }
>  
> +static bool validate_addr(unsigned long start, unsigned long end)
> +{
> +	/*
> +	 * This check explicitly excludes most kernel memory. Most kernel
> +	 * memory is mapped with a larger page size and breaking down the
> +	 * larger page size without causing TLB conflicts is very difficult.
> +	 *
> +	 * If you need to call set_memory_* on a range, the recommendation is
> +	 * to use vmalloc since that range is mapped with pages.
> +	 */
> +	if (start >= MODULES_VADDR && start < MODULES_END &&
> +	    end >= MODULES_VADDR && end < MODULES_END)
> +		return true;

I think we had an existing fencepost error that we carried across.

Say my module gets the very last page of the modules area. If I try to
change the permissions of that page, I'd call:

change_memory_common(MODULES_END - PAGE_SIZE, 1, foo, far);

We then calculate end as MODULES_END, sice we simply add one page.

Then we fail the check above, because end >= MODULES_END.

> +
> +	if (is_vmalloc_addr((void *)start) && is_vmalloc_addr((void *)end))
> +		return true;

Similarly here we would fail the check if this were the last page of the
vmalloc area, as addr == VMALLOC_END.

Other that that this looks good!

Thanks,
Mark.

> +
> +	return false;
> +}
> +
>  static int change_memory_common(unsigned long addr, int numpages,
>  				pgprot_t set_mask, pgprot_t clear_mask)
>  {
> @@ -51,10 +71,7 @@ static int change_memory_common(unsigned long addr, int numpages,
>  		WARN_ON_ONCE(1);
>  	}
>  
> -	if (start < MODULES_VADDR || start >= MODULES_END)
> -		return -EINVAL;
> -
> -	if (end < MODULES_VADDR || end >= MODULES_END)
> +	if (!validate_addr(start, end))
>  		return -EINVAL;
>  
>  	data.set_mask = set_mask;
> -- 
> 2.5.0
> 

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

end of thread, other threads:[~2016-01-13 13:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-12 23:22 [PATCHv2] arm64: Allow vmalloc regions to be set with set_memory_* Laura Abbott
2016-01-12 23:54 ` Kees Cook
2016-01-13 13:14 ` Mark Rutland

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