From: Will Deacon <will@kernel.org>
To: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will.deacon@arm.com>, Dan Rue <dan.rue@linaro.org>,
Daniel Diaz <daniel.diaz@linaro.org>,
Anders Roxell <anders.roxell@linaro.org>,
Naresh Kamboju <naresh.kamboju@linaro.org>,
linux-kernel@vger.kernel.org, James Morse <james.morse@arm.com>,
Matt Hart <matthew.hart@linaro.org>,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v3 1/4] arm64: kprobes: Recover pstate.D in single-step exception handler
Date: Thu, 1 Aug 2019 13:16:22 +0100 [thread overview]
Message-ID: <20190801121622.vs57a6e2syklyr3z@willie-the-truck> (raw)
In-Reply-To: <156404255444.2020.3301023170351823334.stgit@devnote2>
On Thu, Jul 25, 2019 at 05:15:54PM +0900, Masami Hiramatsu wrote:
> kprobes manipulates the interrupted PSTATE for single step, and
> doesn't restore it. Thus, if we put a kprobe where the pstate.D
> (debug) masked, the mask will be cleared after the kprobe hits.
>
> Moreover, in the most complicated case, this can lead a kernel
> crash with below message when a nested kprobe hits.
>
> [ 152.118921] Unexpected kernel single-step exception at EL1
>
> When the 1st kprobe hits, do_debug_exception() will be called.
> At this point, debug exception (= pstate.D) must be masked (=1).
> But if another kprobes hits before single-step of the first kprobe
> (e.g. inside user pre_handler), it unmask the debug exception
> (pstate.D = 0) and return.
> Then, when the 1st kprobe setting up single-step, it saves current
> DAIF, mask DAIF, enable single-step, and restore DAIF.
> However, since "D" flag in DAIF is cleared by the 2nd kprobe, the
> single-step exception happens soon after restoring DAIF.
>
> This has been introduced by commit 7419333fa15e ("arm64: kprobe:
> Always clear pstate.D in breakpoint exception handler")
>
> To solve this issue, this stores all DAIF bits and restore it
> after single stepping.
>
> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> Fixes: commit 7419333fa15e ("arm64: kprobe: Always clear pstate.D in breakpoint exception handler")
> Reviewed-by: James Morse <james.morse@arm.com>
> Tested-by: James Morse <james.morse@arm.com>
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---
> Changes in v3:
> - Update patch description
> - move PSR_DAIF_MASK in daifflags.h
> Changes in v2:
> - Save and restore all DAIF flags.
> - Operate pstate directly and remove spsr_set_debug_flag().
> ---
> arch/arm64/include/asm/daifflags.h | 2 ++
> arch/arm64/kernel/probes/kprobes.c | 39 +++++-------------------------------
> 2 files changed, 7 insertions(+), 34 deletions(-)
I'm seeing an allmodconfig build failure with this:
arch/arm64/kernel/probes/kprobes.c: In function ‘kprobes_save_local_irqflag’:
arch/arm64/kernel/probes/kprobes.c:181:38: error: ‘DAIF_MASK’ undeclared (first use in this function); did you mean ‘BIT_MASK’?
kcb->saved_irqflag = regs->pstate & DAIF_MASK;
^~~~~~~~~
BIT_MASK
arch/arm64/kernel/probes/kprobes.c:181:38: note: each undeclared identifier is reported only once for each function it appears in
arch/arm64/kernel/probes/kprobes.c: In function ‘kprobes_restore_local_irqflag’:
arch/arm64/kernel/probes/kprobes.c:190:19: error: ‘DAIF_MASK’ undeclared (first use in this function); did you mean ‘BIT_MASK’?
regs->pstate &= ~DAIF_MASK;
^~~~~~~~~
BIT_MASK
make[2]: *** [scripts/Makefile.build:274: arch/arm64/kernel/probes/kprobes.o] Error 1
Will
next prev parent reply other threads:[~2019-08-01 12:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-25 8:15 [PATCH v3 0/4] arm64: kprobes: Fix some bugs in arm64 kprobes Masami Hiramatsu
2019-07-25 8:15 ` [PATCH v3 1/4] arm64: kprobes: Recover pstate.D in single-step exception handler Masami Hiramatsu
2019-08-01 12:16 ` Will Deacon [this message]
2019-08-01 14:08 ` Masami Hiramatsu
2019-08-01 14:25 ` [PATCH v4] " Masami Hiramatsu
2019-07-25 8:16 ` [PATCH v3 2/4] arm64: unwind: Prohibit probing on return_address() Masami Hiramatsu
2019-07-25 8:16 ` [PATCH v3 3/4] arm64: Make debug exception handlers visible from RCU Masami Hiramatsu
2019-07-31 17:26 ` Will Deacon
2019-08-01 5:32 ` Masami Hiramatsu
2019-08-01 7:37 ` Will Deacon
2019-08-01 14:36 ` [PATCH v4] " Masami Hiramatsu
2019-07-25 8:16 ` [PATCH v3 4/4] arm64: Remove unneeded rcu_read_lock from debug handlers Masami Hiramatsu
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=20190801121622.vs57a6e2syklyr3z@willie-the-truck \
--to=will@kernel.org \
--cc=anders.roxell@linaro.org \
--cc=catalin.marinas@arm.com \
--cc=dan.rue@linaro.org \
--cc=daniel.diaz@linaro.org \
--cc=james.morse@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matthew.hart@linaro.org \
--cc=mhiramat@kernel.org \
--cc=naresh.kamboju@linaro.org \
--cc=will.deacon@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;
as well as URLs for NNTP newsgroup(s).