From: Will Deacon <will@kernel.org>
To: Vincent Whitchurch <vincent.whitchurch@axis.com>
Cc: catalin.marinas@arm.com, mark.rutland@arm.com, kernel@axis.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] arm64: uaccess: fix put_user() with TTBR0 PAN
Date: Fri, 19 Nov 2021 11:33:06 +0000 [thread overview]
Message-ID: <20211119113306.GA13292@willie-the-truck> (raw)
In-Reply-To: <20211118163417.21617-1-vincent.whitchurch@axis.com>
On Thu, Nov 18, 2021 at 05:34:17PM +0100, Vincent Whitchurch wrote:
> The value argument to put_user() must be evaluated before the TTBR0
> switch is done. Otherwise, if it is a function and the function sleeps,
> the reserved TTBR0 will be restored when the process is switched in
> again and the process will end up in an infinite loop of faults.
>
> This problem was seen with the put_user() in schedule_tail(). A similar
> fix was done for RISC-V in commit 285a76bb2cf51b0c74c634 ("riscv:
> evaluate put_user() arg before enabling user access").
>
> Fixes: f253d827f33cb5a5990 ("arm64: uaccess: refactor __{get,put}_user")
> Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
> ---
> arch/arm64/include/asm/uaccess.h | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
> index 6e2e0b7031ab..96b26fa9d3d0 100644
> --- a/arch/arm64/include/asm/uaccess.h
> +++ b/arch/arm64/include/asm/uaccess.h
> @@ -362,10 +362,11 @@ do { \
> #define __put_user_error(x, ptr, err) \
> do { \
> __typeof__(*(ptr)) __user *__p = (ptr); \
> + __typeof__(*(__p)) __val = (x); \
> might_fault(); \
> if (access_ok(__p, sizeof(*__p))) { \
> __p = uaccess_mask_ptr(__p); \
> - __raw_put_user((x), __p, (err)); \
> + __raw_put_user(__val, __p, (err)); \
> } else { \
> (err) = -EFAULT; \
> } \
Oh, nice spot! I hope you didn't lose too much time debugging if you
actually ran into this...
Although it seems a lot less likely to cause a problem, should we do
something similar for __get_user_error() and assign to (x) outside of
the uaccess-disabled section?
Will
next prev parent reply other threads:[~2021-11-19 11:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-18 16:34 [PATCH] arm64: uaccess: fix put_user() with TTBR0 PAN Vincent Whitchurch
2021-11-19 11:33 ` Will Deacon [this message]
2021-11-19 13:44 ` Mark Rutland
2021-11-19 13:04 ` Mark Rutland
2021-11-22 10:01 ` Mark Rutland
2021-11-22 10:09 ` Vincent Whitchurch
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=20211119113306.GA13292@willie-the-truck \
--to=will@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=kernel@axis.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=vincent.whitchurch@axis.com \
/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 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).