bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Muchun Song <songmuchun@bytedance.com>
To: Qiang Wang <wangqiang.wq.frank@bytedance.com>
Cc: "Naveen N . Rao" <naveen.n.rao@linux.ibm.com>,
	Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>,
	David Miller <davem@davemloft.net>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	kpsingh@kernel.org, LKML <linux-kernel@vger.kernel.org>,
	Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
	Chengming Zhou <zhouchengming@bytedance.com>,
	Xiongchun duan <duanxiongchun@bytedance.com>
Subject: Re: [Phishing Risk] [PATCH] kprobe: fix kretprobe stack backtrace
Date: Fri, 25 Jun 2021 18:24:12 +0800	[thread overview]
Message-ID: <CAMZfGtWPi4CuVOtmUpy2N9J_mvp+5=gSAFvqV1nmvDKP+CAvQA@mail.gmail.com> (raw)
In-Reply-To: <20210625084748.18128-1-wangqiang.wq.frank@bytedance.com>

On Fri, Jun 25, 2021 at 4:49 PM Qiang Wang
<wangqiang.wq.frank@bytedance.com> wrote:
>
> We found that we couldn't get the correct kernel stack from
> kretprobe. For example:
>
> bpftrace -e 'kr:submit_bio {print(kstack)}'
> Attaching 1 probe...
>
>         kretprobe_trampoline+0
>
>         kretprobe_trampoline+0
>
> The problem is caused by the wrong instruction register which
> points to the address of kretprobe_trampoline in regs.
> So we set the real return address in instruction register.
> Finally, we tested and successfully fixed it.
>
> bpftrace -e 'kr:submit_bio {print(kstack)}'
> Attaching 1 probe...
>
>         ext4_mpage_readpages+475
>         read_pages+139
>         page_cache_ra_unbounded+417
>         filemap_get_pages+245
>         filemap_read+169
>         __kernel_read+327
>         bprm_execve+648
>         do_execveat_common.isra.39+409
>         __x64_sys_execve+50
>         do_syscall_64+54
>         entry_SYSCALL_64_after_hwframe+68
>
> Reported-by: Chengming Zhou <zhouchengming@bytedance.com>
> Signed-off-by: Qiang Wang <wangqiang.wq.frank@bytedance.com>

Seems like a bug. Maybe we should add a "Fixes" tag here.

> ---
>  kernel/kprobes.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 745f08fdd..1130381ca 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -1899,6 +1899,9 @@ unsigned long __kretprobe_trampoline_handler(struct pt_regs *regs,
>         current->kretprobe_instances.first = node->next;
>         node->next = NULL;
>
> +       /* Kretprobe handler expects address is the real return address */
> +       instruction_pointer_set(regs, (unsigned long)correct_ret_addr);
> +
>         /* Run them..  */
>         while (first) {
>                 ri = container_of(first, struct kretprobe_instance, llist);
> --
> 2.20.1
>

       reply	other threads:[~2021-06-25 10:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210625084748.18128-1-wangqiang.wq.frank@bytedance.com>
2021-06-25 10:24 ` Muchun Song [this message]
2021-06-28 13:34   ` [Phishing Risk] [PATCH] kprobe: fix kretprobe stack backtrace 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='CAMZfGtWPi4CuVOtmUpy2N9J_mvp+5=gSAFvqV1nmvDKP+CAvQA@mail.gmail.com' \
    --to=songmuchun@bytedance.com \
    --cc=andrii@kernel.org \
    --cc=anil.s.keshavamurthy@intel.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=duanxiongchun@bytedance.com \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=naveen.n.rao@linux.ibm.com \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=wangqiang.wq.frank@bytedance.com \
    --cc=yhs@fb.com \
    --cc=zhouchengming@bytedance.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).