From: Kevin Brodsky <kevin.brodsky@arm.com>
To: Jeff Xu <jeffxu@chromium.org>
Cc: linux-arm-kernel@lists.infradead.org, akpm@linux-foundation.org,
anshuman.khandual@arm.com, aruna.ramakrishna@oracle.com,
broonie@kernel.org, catalin.marinas@arm.com,
dave.hansen@linux.intel.com, Dave.Martin@arm.com,
joey.gouly@arm.com, keith.lucas@oracle.com,
pierre.langlois@arm.com, shuah@kernel.org, sroettger@google.com,
tglx@linutronix.de, will@kernel.org, yury.khrustalev@arm.com,
linux-kselftest@vger.kernel.org, x86@kernel.org,
Kees Cook <keescook@chromium.org>,
Jorge Lucangeli Obes <jorgelo@chromium.org>,
Jann Horn <jannh@google.com>
Subject: Re: [PATCH v3 1/5] arm64: signal: Improve POR_EL0 handling to avoid uaccess failures
Date: Thu, 31 Oct 2024 09:45:28 +0100 [thread overview]
Message-ID: <cd0e114d-57eb-4c90-bb6f-9abf0cc8920f@arm.com> (raw)
In-Reply-To: <CABi2SkUTSuk_PS9==_czM=64FGWK_5DyUe5QELxiFHtPFsKaHw@mail.gmail.com>
On 30/10/2024 23:01, Jeff Xu wrote:
>> -static int restore_poe_context(struct user_ctxs *user)
>> +static int restore_poe_context(struct user_ctxs *user,
>> + struct user_access_state *ua_state)
>> {
>> u64 por_el0;
>> int err = 0;
>> @@ -282,7 +338,7 @@ static int restore_poe_context(struct user_ctxs *user)
>>
>> __get_user_error(por_el0, &(user->poe->por_el0), err);
>> if (!err)
>> - write_sysreg_s(por_el0, SYS_POR_EL0);
>> + ua_state->por_el0 = por_el0;
>>
>> return err;
>> }
>> @@ -850,7 +906,8 @@ static int parse_user_sigframe(struct user_ctxs *user,
>> }
>>
>> static int restore_sigframe(struct pt_regs *regs,
>> - struct rt_sigframe __user *sf)
>> + struct rt_sigframe __user *sf,
>> + struct user_access_state *ua_state)
>> {
>> sigset_t set;
>> int i, err;
>> @@ -899,7 +956,7 @@ static int restore_sigframe(struct pt_regs *regs,
>> err = restore_zt_context(&user);
>>
>> if (err == 0 && system_supports_poe() && user.poe)
>> - err = restore_poe_context(&user);
>> + err = restore_poe_context(&user, ua_state);
>>
>> return err;
>> }
>> @@ -908,6 +965,7 @@ SYSCALL_DEFINE0(rt_sigreturn)
>> {
>> struct pt_regs *regs = current_pt_regs();
>> struct rt_sigframe __user *frame;
>> + struct user_access_state ua_state;
>>
>> /* Always make any pending restarted system calls return -EINTR */
>> current->restart_block.fn = do_no_restart_syscall;
>> @@ -924,12 +982,14 @@ SYSCALL_DEFINE0(rt_sigreturn)
>> if (!access_ok(frame, sizeof (*frame)))
>> goto badframe;
>>
>> - if (restore_sigframe(regs, frame))
>> + if (restore_sigframe(regs, frame, &ua_state))
>> goto badframe;
>>
>> if (restore_altstack(&frame->uc.uc_stack))
>> goto badframe;
>>
> Do you need to move restore_altstack ahead of restore_sigframe?
This is not necessary because restore_sigframe() no longer writes to
POR_EL0. restore_poe_context() (above) now saves the original POR_EL0
value into ua_state, and it is restore_user_access_state() (called below
just before returning to userspace) that actually writes to POR_EL0,
after all uaccess is completed.
Having said that, I somehow missed the call to restore_altstack() when
writing the commit message, so these changes in sys_rt_sigreturn are in
fact necessary. Good catch! At least the patch itself should be doing
the right thing.
- Kevin
> similar as x86 change [1],
> the discussion for this happened in [2] [3]
>
> [1] https://lore.kernel.org/lkml/20240802061318.2140081-5-aruna.ramakrishna@oracle.com/
> [2] https://lore.kernel.org/lkml/20240425210540.3265342-1-jeffxu@chromium.org/
> [3] https://lore.kernel.org/lkml/d0162c76c25bc8e1c876aebe8e243ff2e6862359.camel@intel.com/
>
> Thanks
> -Jeff
>
>
>> + restore_user_access_state(&ua_state);
>> +
>> return regs->regs[0];
next prev parent reply other threads:[~2024-10-31 8:45 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-29 14:45 [PATCH v3 0/5] Improve arm64 pkeys handling in signal delivery Kevin Brodsky
2024-10-29 14:45 ` [PATCH v3 1/5] arm64: signal: Improve POR_EL0 handling to avoid uaccess failures Kevin Brodsky
2024-10-30 22:01 ` Jeff Xu
2024-10-31 8:45 ` Kevin Brodsky [this message]
2024-10-31 18:43 ` Jeff Xu
2024-10-31 9:33 ` Will Deacon
2024-10-31 10:23 ` Kevin Brodsky
2024-10-29 14:45 ` [PATCH v3 2/5] arm64: signal: Remove unnecessary check when saving POE state Kevin Brodsky
2024-10-29 14:45 ` [PATCH v3 3/5] arm64: signal: Remove unused macro Kevin Brodsky
2024-10-29 14:45 ` [PATCH v3 4/5] selftests/mm: Use generic pkey register manipulation Kevin Brodsky
2024-10-29 17:42 ` Dave Hansen
2024-10-29 14:45 ` [PATCH v3 5/5] selftests/mm: Enable pkey_sighandler_tests on arm64 Kevin Brodsky
2024-10-29 18:28 ` [PATCH v3 0/5] Improve arm64 pkeys handling in signal delivery Will Deacon
2024-10-30 21:59 ` Jeff Xu
2024-10-31 13:00 ` Kevin Brodsky
2024-10-31 16:52 ` Jeff Xu
2024-11-04 17:12 ` (subset) " Catalin Marinas
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=cd0e114d-57eb-4c90-bb6f-9abf0cc8920f@arm.com \
--to=kevin.brodsky@arm.com \
--cc=Dave.Martin@arm.com \
--cc=akpm@linux-foundation.org \
--cc=anshuman.khandual@arm.com \
--cc=aruna.ramakrishna@oracle.com \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=dave.hansen@linux.intel.com \
--cc=jannh@google.com \
--cc=jeffxu@chromium.org \
--cc=joey.gouly@arm.com \
--cc=jorgelo@chromium.org \
--cc=keescook@chromium.org \
--cc=keith.lucas@oracle.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=pierre.langlois@arm.com \
--cc=shuah@kernel.org \
--cc=sroettger@google.com \
--cc=tglx@linutronix.de \
--cc=will@kernel.org \
--cc=x86@kernel.org \
--cc=yury.khrustalev@arm.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