From: Mark-PK Tsai <mark-pk.tsai@mediatek.com>
To: <rostedt@goodmis.org>
Cc: <catalin.marinas@arm.com>, <linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>,
<linux-mediatek@lists.infradead.org>, <mark-pk.tsai@mediatek.com>,
<matthias.bgg@gmail.com>, <mingo@redhat.com>, <will@kernel.org>,
<yj.chiang@mediatek.com>
Subject: Re: [PATCH] arm64: ftrace: don't dereference a probably invalid address
Date: Tue, 8 Jun 2021 02:14:03 +0800 [thread overview]
Message-ID: <20210607181403.4017-1-mark-pk.tsai@mediatek.com> (raw)
In-Reply-To: <20210607105217.772214e5@oasis.local.home>
> On Mon, 7 Jun 2021 22:15:22 +0800
> Mark-PK Tsai <mark-pk.tsai@mediatek.com> wrote:
>
> > And the crash is becuase kernel trying to read *rec->ip in print_ip_ins() if
> > ftrace_bug() get error code -EINVAL.
>
> Right, so the actual fix should be something like this:
>
> [ not tested, nor even compiled ]
>
> -- Steve
>
I just test this patch, and turns out it work well.
All my modification is only rename copy_from_kernel_nofault
into probe_kernel_read because the older kernel version
I use.
Then the kernel will show the error mesage instead of panic as following.
[ 0.000000] ftrace failed to modify
[ 0.000000] [<0000000000000020>] 0x20
[ 0.000000] actual: [FAULT](0000000000000020)
Should I resend this patch as v2?
Or you will upstream this fix?
>
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 2e8a3fde7104..72ef4dccbcc4 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -1967,12 +1967,18 @@ static int ftrace_hash_ipmodify_update(struct ftrace_ops *ops,
>
> static void print_ip_ins(const char *fmt, const unsigned char *p)
> {
> + char ins[MCOUNT_INSN_SIZE];
> int i;
>
> + if (copy_from_kernel_nofault(ins, p, MCOUNT_INSN_SIZE)) {
> + printk(KERN_CONT "%s[FAULT](%px)", fmt, p);
> + return;
> + }
> +
> printk(KERN_CONT "%s", fmt);
>
> for (i = 0; i < MCOUNT_INSN_SIZE; i++)
> - printk(KERN_CONT "%s%02x", i ? ":" : "", p[i]);
> + printk(KERN_CONT "%s%02x", i ? ":" : "", ins[i]);
> }
>
> enum ftrace_bug_type ftrace_bug_type;
next prev parent reply other threads:[~2021-06-07 18:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-07 3:23 Mark-PK Tsai
2021-06-07 13:55 ` Steven Rostedt
2021-06-07 14:15 ` Mark-PK Tsai
2021-06-07 14:36 ` Mark-PK Tsai
2021-06-07 14:52 ` Steven Rostedt
2021-06-07 18:14 ` Mark-PK Tsai [this message]
2021-06-07 18:50 ` Steven Rostedt
2021-06-08 0:52 ` Mark-PK Tsai
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=20210607181403.4017-1-mark-pk.tsai@mediatek.com \
--to=mark-pk.tsai@mediatek.com \
--cc=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=mingo@redhat.com \
--cc=rostedt@goodmis.org \
--cc=will@kernel.org \
--cc=yj.chiang@mediatek.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
all inboxes | Powered by JetHome®