From: Ingo Molnar <mingo@kernel.org>
To: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>, "H . Peter Anvin" <hpa@zytor.com>,
x86@kernel.org, Ananth N Mavinakayanahalli <ananth@in.ibm.com>,
Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>,
"David S . Miller" <davem@davemloft.net>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH -tip 1/2] kprobes/x86: Don't forget to set memory back to RO on failure
Date: Thu, 10 Aug 2017 17:29:56 +0200 [thread overview]
Message-ID: <20170810152956.n3dhwjtv2nyxmrpr@gmail.com> (raw)
In-Reply-To: <150150832476.31981.15380750058308167313.stgit@devbox>
* Masami Hiramatsu <mhiramat@kernel.org> wrote:
> Do not forget to set kprobes insn buffer memory back
> to RO on failure path. Without this fix, if there is
> an unexpected error on copying instructions, kprobes
> insn buffer kept RW, which can allow unexpected modifying
> instruction buffer.
>
> Fixes: d0381c81c2f7 ("kprobes/x86: Set kprobes pages read-only")
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---
> arch/x86/kernel/kprobes/core.c | 4 +++-
> arch/x86/kernel/kprobes/opt.c | 1 +
> 2 files changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
> index f0153714ddac..b16b10114e20 100644
> --- a/arch/x86/kernel/kprobes/core.c
> +++ b/arch/x86/kernel/kprobes/core.c
> @@ -435,8 +435,10 @@ static int arch_copy_kprobe(struct kprobe *p)
>
> /* Copy an instruction with recovering if other optprobe modifies it.*/
> len = __copy_instruction(p->ainsn.insn, p->addr, &insn);
> - if (!len)
> + if (!len) {
> + set_memory_ro((unsigned long)p->ainsn.insn & PAGE_MASK, 1);
> return -EINVAL;
> + }
So variable usage in the arch_copy_kprobe() is really awful: 'p->ainsn.insn' is
repeated 6 times!
Please consolidate all that via a helper variable.
Also, regarding the merits of the patch: do we know that the page in question was
RO before? If it was RW we'll unexpectedly mark it RO here in the failure path ...
> index 69ea0bc1cfa3..853614560a4f 100644
> --- a/arch/x86/kernel/kprobes/opt.c
> +++ b/arch/x86/kernel/kprobes/opt.c
> @@ -368,6 +368,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op,
> ret = copy_optimized_instructions(buf + TMPL_END_IDX, op->kp.addr);
> if (ret < 0) {
> __arch_remove_optimized_kprobe(op, 0);
> + set_memory_ro((unsigned long)buf & PAGE_MASK, 1);
> return ret;
> }
> op->optinsn.size = ret;
Ditto.
Thanks,
Ingo
next prev parent reply other threads:[~2017-08-10 15:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-31 13:37 [PATCH -tip 0/2] kprobes/x86: RO text code bugfix and cleanup Masami Hiramatsu
2017-07-31 13:38 ` [PATCH -tip 1/2] kprobes/x86: Don't forget to set memory back to RO on failure Masami Hiramatsu
2017-08-10 15:29 ` Ingo Molnar [this message]
2017-08-11 23:09 ` Masami Hiramatsu
2017-07-31 13:39 ` [PATCH -tip 2/2] kprobes/x86: Remove addressof operators 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=20170810152956.n3dhwjtv2nyxmrpr@gmail.com \
--to=mingo@kernel.org \
--cc=ananth@in.ibm.com \
--cc=anil.s.keshavamurthy@intel.com \
--cc=davem@davemloft.net \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=x86@kernel.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