All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ARM: mm: make act_mm() respect THREAD_SIZE_ORDER
@ 2020-05-14 13:57 Linus Walleij
  2020-05-14 17:19 ` Ard Biesheuvel
  0 siblings, 1 reply; 2+ messages in thread
From: Linus Walleij @ 2020-05-14 13:57 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, #(4095 << THREAD_SIZE_ORDER) & ~63

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>
---
I'm sending this as a separate preparatory fix as it is
a nice fix in its own right. I am now testing KASan on
ARMv4 and ARMv5 and with some minimal busybox userspace
it is quite possible to run it on even really small
devices like the Gemini-based routers and NAS from
D-Link.
---
 arch/arm/mm/proc-macros.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mm/proc-macros.S b/arch/arm/mm/proc-macros.S
index 5461d589a1e2..ba100b2d0ac2 100644
--- a/arch/arm/mm/proc-macros.S
+++ b/arch/arm/mm/proc-macros.S
@@ -30,7 +30,7 @@
  * act_mm - get current->active_mm
  */
 	.macro	act_mm, rd
-	bic	\rd, sp, #8128
+	bic	\rd, sp, #(4095 << THREAD_SIZE_ORDER) & ~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] ARM: mm: make act_mm() respect THREAD_SIZE_ORDER
  2020-05-14 13:57 [PATCH] ARM: mm: make act_mm() respect THREAD_SIZE_ORDER Linus Walleij
@ 2020-05-14 17:19 ` Ard Biesheuvel
  0 siblings, 0 replies; 2+ messages in thread
From: Ard Biesheuvel @ 2020-05-14 17:19 UTC (permalink / raw)
  To: Linus Walleij; +Cc: Florian Fainelli, Russell King, Linux ARM

On Thu, 14 May 2020 at 15:59, Linus Walleij <linus.walleij@linaro.org> 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, #(4095 << THREAD_SIZE_ORDER) & ~63
>

Perhaps

(THREAD_SIZE - 1) & ~63

is a bit cleaner here?



> 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>
> ---
> I'm sending this as a separate preparatory fix as it is
> a nice fix in its own right. I am now testing KASan on
> ARMv4 and ARMv5 and with some minimal busybox userspace
> it is quite possible to run it on even really small
> devices like the Gemini-based routers and NAS from
> D-Link.
> ---
>  arch/arm/mm/proc-macros.S | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm/mm/proc-macros.S b/arch/arm/mm/proc-macros.S
> index 5461d589a1e2..ba100b2d0ac2 100644
> --- a/arch/arm/mm/proc-macros.S
> +++ b/arch/arm/mm/proc-macros.S
> @@ -30,7 +30,7 @@
>   * act_mm - get current->active_mm
>   */
>         .macro  act_mm, rd
> -       bic     \rd, sp, #8128
> +       bic     \rd, sp, #(4095 << THREAD_SIZE_ORDER) & ~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	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-14 17:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-14 13:57 [PATCH] ARM: mm: make act_mm() respect THREAD_SIZE_ORDER Linus Walleij
2020-05-14 17:19 ` Ard Biesheuvel

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.