linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] ARM: mm: make act_mm() respect THREAD_SIZE
@ 2020-05-15 12:48 Linus Walleij
  2020-05-21 11:56 ` Russell King - ARM Linux admin
  0 siblings, 1 reply; 2+ messages in thread
From: Linus Walleij @ 2020-05-15 12:48 UTC (permalink / raw)
  To: Russell King
  Cc: Linus Walleij, Florian Fainelli, Ard Biesheuvel, linux-arm-kernel

Recent work with KASan exposed the folling hard-coded bitmask
in arch/arm/mm/proc-macros.S:

  bic     \rd, sp, #8128
  bic     \rd, \rd, #63

This forms the bitmask 0x1FFF that is coinciding with
(PAGE_SIZE << THREAD_SIZE_ORDER) - 1, this code was assuming
that THREAD_SIZE is always 8K (8192).

As KASan was increasing THREAD_SIZE_ORDER to 2, I ran into
this bug.

Fix it by this little oneline suggested by Ard:

  bic     \rd, sp, #(THREAD_SIZE - 1) & ~63

Where THREAD_SIZE is defined using THREAD_SIZE_ORDER.

We have to also include <linux/const.h> since the THREAD_SIZE
expands to use the _AC() macro.

Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Suggested-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v1->v2:
- Change from using THREAD_SIZE_ORDER with a hardcoded
  page size constant to just using THREAD_SIZE - 1
  for the mask.
---
 arch/arm/mm/proc-macros.S | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mm/proc-macros.S b/arch/arm/mm/proc-macros.S
index 5461d589a1e2..60ac7c5999a9 100644
--- a/arch/arm/mm/proc-macros.S
+++ b/arch/arm/mm/proc-macros.S
@@ -5,6 +5,7 @@
  *  VMA_VM_FLAGS
  *  VM_EXEC
  */
+#include <linux/const.h>
 #include <asm/asm-offsets.h>
 #include <asm/thread_info.h>
 
@@ -30,7 +31,7 @@
  * act_mm - get current->active_mm
  */
 	.macro	act_mm, rd
-	bic	\rd, sp, #8128
+	bic	\rd, sp, #(THREAD_SIZE - 1) & ~63
 	bic	\rd, \rd, #63
 	ldr	\rd, [\rd, #TI_TASK]
 	.if (TSK_ACTIVE_MM > IMM12_MASK)
-- 
2.25.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2] ARM: mm: make act_mm() respect THREAD_SIZE
  2020-05-15 12:48 [PATCH v2] ARM: mm: make act_mm() respect THREAD_SIZE Linus Walleij
@ 2020-05-21 11:56 ` Russell King - ARM Linux admin
  0 siblings, 0 replies; 2+ messages in thread
From: Russell King - ARM Linux admin @ 2020-05-21 11:56 UTC (permalink / raw)
  To: Linus Walleij; +Cc: Florian Fainelli, Ard Biesheuvel, linux-arm-kernel

On Fri, May 15, 2020 at 02:48:08PM +0200, Linus Walleij wrote:
> Recent work with KASan exposed the folling hard-coded bitmask
> in arch/arm/mm/proc-macros.S:
> 
>   bic     \rd, sp, #8128
>   bic     \rd, \rd, #63
> 
> This forms the bitmask 0x1FFF that is coinciding with
> (PAGE_SIZE << THREAD_SIZE_ORDER) - 1, this code was assuming
> that THREAD_SIZE is always 8K (8192).
> 
> As KASan was increasing THREAD_SIZE_ORDER to 2, I ran into
> this bug.
> 
> Fix it by this little oneline suggested by Ard:
> 
>   bic     \rd, sp, #(THREAD_SIZE - 1) & ~63
> 
> Where THREAD_SIZE is defined using THREAD_SIZE_ORDER.
> 
> We have to also include <linux/const.h> since the THREAD_SIZE
> expands to use the _AC() macro.
> 
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Suggested-by: Ard Biesheuvel <ardb@kernel.org>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> ChangeLog v1->v2:
> - Change from using THREAD_SIZE_ORDER with a hardcoded
>   page size constant to just using THREAD_SIZE - 1
>   for the mask.
> ---
>  arch/arm/mm/proc-macros.S | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/mm/proc-macros.S b/arch/arm/mm/proc-macros.S
> index 5461d589a1e2..60ac7c5999a9 100644
> --- a/arch/arm/mm/proc-macros.S
> +++ b/arch/arm/mm/proc-macros.S
> @@ -5,6 +5,7 @@
>   *  VMA_VM_FLAGS
>   *  VM_EXEC
>   */
> +#include <linux/const.h>
>  #include <asm/asm-offsets.h>
>  #include <asm/thread_info.h>
>  
> @@ -30,7 +31,7 @@
>   * act_mm - get current->active_mm
>   */
>  	.macro	act_mm, rd
> -	bic	\rd, sp, #8128
> +	bic	\rd, sp, #(THREAD_SIZE - 1) & ~63
>  	bic	\rd, \rd, #63

We have a get_thread_info macro in asm/assembler that performs the same
task.  Maybe this should be converted to use that, and maybe the macro
should be updated to use bic, since this seems to be acceptable for
Thumb and is one instruction shorter.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC for 0.8m (est. 1762m) line in suburbia: sync at 13.1Mbps down 424kbps up

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2020-05-21 11:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-15 12:48 [PATCH v2] ARM: mm: make act_mm() respect THREAD_SIZE Linus Walleij
2020-05-21 11:56 ` Russell King - ARM Linux admin

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