All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: Florian Fainelli <f.fainelli@gmail.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Arnd Bergmann <arnd@arndb.de>, Stefan Wahren <wahrenst@gmx.net>,
	Kees Cook <keescook@chromium.org>,
	linux-arm-kernel@lists.infradead.org,
	Catalin Marinas <catalin.marinas@arm.com>
Subject: Re: [PATCH v3 4/4] ARM: Implement PAN for LPAE by TTBR0 page table walks disablement
Date: Wed, 15 May 2024 17:18:11 +0100	[thread overview]
Message-ID: <ZkTgQ8EZG3E7o4lR@shell.armlinux.org.uk> (raw)
In-Reply-To: <CAMj1kXEPUKx-6QqfpjvgrL-YFbaz=akh=gEG0QakFJUDo-1C0w@mail.gmail.com>

On Wed, May 15, 2024 at 05:41:45PM +0200, Ard Biesheuvel wrote:
> This definitely looks like some pathological compiler behavior:
> 
> The faulting instruction in question is in busybox
> 
>    15f450:       eef11a10        vmrs    r1, fpscr
> 
> which [as expected] triggers an UNDEF exception as FP is disabled
> after a context switch.
> 
> The get_user() call in do_undefinstr() [arch/arm/kernel/traps.c:482]
> 
>     if (get_user(instr, (u32 __user *)pc))
> 
> gets compiled to the below, where the thing to note is that the
> out-of-line version of uaccess_save_and_enable() returns the old ttbcr
> value in R0. This value gets recorded in R3, but it also gets happily
> passed on to __get_user_4(), which expects the user address in R0, not
> the old value of TTBCR.
> 
> │    0xc040a5e4 <do_undefinstr+228>  bl      0xc0409fe4
> <uaccess_save_and_enable>
> │    0xc040a5e8 <do_undefinstr+232>  mov     r3, r0
> │  > 0xc040a5ec <do_undefinstr+236>  bl      0xc10443a8 <__get_user_4>
> │    0xc040a5f0 <do_undefinstr+240>  mcr     15, 0, r3, cr2, cr0, {2}
> │    0xc040a5f4 <do_undefinstr+244>  isb     sy
> 
> With __always_inline, this part is emitted as
> 
>  5fc:   ee124f50        mrc     15, 0, r4, cr2, cr0, {2}
>  600:   e0033004        and     r3, r3, r4
>  604:   ee023f50        mcr     15, 0, r3, cr2, cr0, {2}
>  608:   f57ff06f        isb     sy
>  60c:   ebfffffe        bl      0 <__get_user_4>
>                         60c: R_ARM_CALL __get_user_4
>  610:   ee024f50        mcr     15, 0, r4, cr2, cr0, {2}
>  614:   f57ff06f        isb     sy
> 
> and so R0 is preserved, and the issue does not happen.
> 
> Not sure how to reduce this to a reproducer that can be used to report
> the issue to the GCC folks, but it is most definitely a compiler
> problem, as far as I can tell.

Well this has come up before...

commit 851140ab0d083c78e5723a8b1cbd258f567a7aff
Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Date:   Wed Oct 2 11:28:02 2019 +0100

    ARM: 8908/1: add __always_inline to functions called from __get_user_check()

I assume it's a wontfix on the GCC side.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

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

  reply	other threads:[~2024-05-15 16:18 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-12 12:52 [PATCH v3 0/4] PAN for ARM32 using LPAE Linus Walleij
2024-03-12 12:52 ` [PATCH v3 1/4] ARM: Add TTBCR_* definitions to pgtable-3level-hwdef.h Linus Walleij
2024-03-12 12:52 ` [PATCH v3 2/4] ARM: Move asm statements accessing TTBCR into C functions Linus Walleij
2024-03-12 12:52 ` [PATCH v3 3/4] ARM: Reduce the number of #ifdef CONFIG_CPU_SW_DOMAIN_PAN Linus Walleij
2024-03-12 12:52 ` [PATCH v3 4/4] ARM: Implement PAN for LPAE by TTBR0 page table walks disablement Linus Walleij
2024-05-07 13:10   ` Geert Uytterhoeven
2024-05-13 19:23     ` Linus Walleij
2024-05-13 19:58       ` Geert Uytterhoeven
2024-05-13 20:29         ` Linus Walleij
2024-05-14  3:56           ` Florian Fainelli
2024-05-14  8:14             ` Russell King (Oracle)
2024-05-14 11:22               ` Geert Uytterhoeven
2024-05-14 11:33                 ` Russell King (Oracle)
2024-05-14 12:32                   ` Geert Uytterhoeven
2024-05-14 12:38                     ` Russell King (Oracle)
2024-05-14 15:03                       ` Catalin Marinas
2024-05-14  6:41           ` Geert Uytterhoeven
2024-05-14  7:46             ` Linus Walleij
2024-05-14  7:59               ` Ard Biesheuvel
2024-05-14  8:04                 ` Geert Uytterhoeven
2024-05-14  8:25                   ` Ard Biesheuvel
2024-05-14  9:22                     ` Russell King (Oracle)
2024-05-14 11:40                       ` Linus Walleij
2024-05-14 11:28                     ` Geert Uytterhoeven
2024-05-14 16:06                       ` Geert Uytterhoeven
2024-05-14 16:54                         ` Florian Fainelli
2024-05-14 17:03                           ` Russell King (Oracle)
2024-05-14 18:26                             ` Florian Fainelli
2024-05-14 20:33                               ` Linus Walleij
2024-05-14 20:34                                 ` Florian Fainelli
2024-05-15  8:36                                   ` Ard Biesheuvel
2024-05-15  8:45                                     ` Geert Uytterhoeven
2024-05-15  8:49                                       ` Ard Biesheuvel
2024-05-15  9:21                                         ` Geert Uytterhoeven
2024-05-15  9:39                                           ` Ard Biesheuvel
2024-05-15 11:58                                           ` Linus Walleij
2024-05-15 14:05                                             ` Geert Uytterhoeven
2024-05-15  8:48                                     ` Russell King (Oracle)
2024-05-15  8:53                                       ` Ard Biesheuvel
2024-05-15 12:27                                         ` Russell King (Oracle)
2024-05-15 15:41                                           ` Ard Biesheuvel
2024-05-15 16:18                                             ` Russell King (Oracle) [this message]
2024-05-15 16:36                                               ` Ard Biesheuvel
2024-05-15 21:51                                                 ` Arnd Bergmann
2024-05-15  8:10                               ` Geert Uytterhoeven
2024-05-14  7:37           ` Linus Walleij
2024-05-14 14:39             ` Catalin Marinas
2024-03-12 17:45 ` [PATCH v3 0/4] PAN for ARM32 using LPAE Florian Fainelli
2024-03-13  8:13   ` Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZkTgQ8EZG3E7o4lR@shell.armlinux.org.uk \
    --to=linux@armlinux.org.uk \
    --cc=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=catalin.marinas@arm.com \
    --cc=f.fainelli@gmail.com \
    --cc=geert@linux-m68k.org \
    --cc=keescook@chromium.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=wahrenst@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.