From: Will Deacon <will@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>,
Linux ARM <linux-arm-kernel@lists.infradead.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Android Kernel Team <kernel-team@android.com>,
mark.rutland@arm.com
Subject: Re: [GIT PULL] arm64 fixes for -rc5
Date: Mon, 9 Aug 2021 11:52:38 +0100 [thread overview]
Message-ID: <20210809105238.GA5693@willie-the-truck> (raw)
In-Reply-To: <CAHk-=whNiAtCUqeCAcq+GKjmOXFfLCYA84TpeeL2085c+BdmQQ@mail.gmail.com>
Hi Linus,
[+Mark]
On Fri, Aug 06, 2021 at 11:40:33AM -0700, Linus Torvalds wrote:
> On Fri, Aug 6, 2021 at 6:53 AM Will Deacon <will@kernel.org> wrote:
> >
> > Please pull these arm64 fixes for -rc5. It's all pretty minor but the
> > main fix is sorting out how we deal with return values from 32-bit system
> > calls as audit expects error codes to be sign-extended to 64 bits
>
> I've pulled this, but that change looks _really_ odd.
Cheers, and yes it does. We're stuck in the middle of the architecture,
the compat ABI and internal kernel expectations. More below.
> First you seem to intentionally *zero-extend* the error value when you
> actually set it in pt_regs, and then you sign-extend them when reading
> them.
>
> So the rules seem entirely arbitrary: oen place says "upper 32 bits
> need to be clear" and another place says "upper 32 bits need to be
> sign-extended".
>
> Why this insanity? Why not make the rule be that the upper 32 bits are
> always just sign-extended?
There are a few things which collide here:
The architecture doesn't guarantee that the upper 32-bits of a 64-bit
general purpose register are preserved across an exception return to a
32-bit task. They _might_ be left intact, but it's up to the CPU whether
you get the value you wrote or all zeroes if you read those bits after
taking an exception back to 64-bit state. Consequently, we can't
expose 64-bit registers for 32-bit tasks via ptrace() as the
resulting behaviour is going to vary based on how the hardware feels.
Maybe we could sign-extend everything on exception entry, but that would
necessitate many more syscall wrappers for compat tasks than we currently
have so we could truncate pointer arguments back down to 32 bits.
Instead, we currently handle this by (a) treating the registers of a 32-bit
task as 32 bits (hence the zero extension when writing the value in
syscall_set_return_value()) and (b) explicitly clearing the upper bits of
x0 on exception entry from a 32-bit task in case we previously leaked a
negative syscall return value in there.
The problem then is that some in-kernel users (e.g. audit and some parts of
ptrace which abstract the syscall return value away from the register state)
_do_ want to see sign-extended syscall return arguments in order to match
against error codes (see is_syscall_success()). So we end up in a situation
where we need to sign-extend the return value for those, whilst leaving the
zero-extended version in the actual pt_regs structure.
It's ugly and subtle because the sky doesn't tend to fall in if you get
it wrong. As you can see, we're still fixing it.
Will
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2021-08-09 10:54 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-06 13:53 [GIT PULL] arm64 fixes for -rc5 Will Deacon
2021-08-06 18:40 ` Linus Torvalds
2021-08-09 10:52 ` Will Deacon [this message]
2021-08-06 18:48 ` pr-tracker-bot
-- strict thread matches above, loose matches on Subject: below --
2026-03-20 13:06 Will Deacon
2026-03-20 16:25 ` pr-tracker-bot
2025-03-01 21:21 Will Deacon
2025-03-01 21:48 ` pr-tracker-bot
2024-02-16 11:58 Will Deacon
2024-02-16 18:52 ` pr-tracker-bot
2023-10-06 7:56 Will Deacon
2023-10-06 15:15 ` pr-tracker-bot
2023-07-21 11:44 Will Deacon
2023-07-21 11:45 ` Will Deacon
2023-07-21 17:28 ` pr-tracker-bot
2022-09-11 11:37 Will Deacon
2022-09-11 19:36 ` pr-tracker-bot
2021-03-25 14:54 [GIT PULL] arm64: Fixes " Will Deacon
2021-03-25 19:13 ` pr-tracker-bot
2020-07-10 14:39 [GIT PULL] arm64 fixes " Will Deacon
2020-07-10 16:55 ` pr-tracker-bot
2020-03-06 15:12 Will Deacon
2020-03-06 20:55 ` pr-tracker-bot
2019-06-14 15:02 [GIT PULL] arm64: " Will Deacon
2019-06-14 16:20 ` pr-tracker-bot
2019-04-12 16:05 [GIT PULL] arm64 " Will Deacon
2019-04-13 17:40 ` pr-tracker-bot
2019-02-01 17:51 [GIT PULL] arm64: " Will Deacon
2019-02-02 1:00 ` pr-tracker-bot
2018-05-11 17:30 Will Deacon
2017-03-31 17:15 Will Deacon
2016-06-24 11:41 Will Deacon
2016-02-19 16:29 Will Deacon
2015-10-07 14:20 Will Deacon
2015-01-16 17:16 Will Deacon
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=20210809105238.GA5693@willie-the-truck \
--to=will@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=kernel-team@android.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=torvalds@linux-foundation.org \
/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