From: Jiri Olsa <olsajiri@gmail.com>
To: Xu Kuohai <xukuohai@huaweicloud.com>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org,
Bruno Goncalves <bgoncalv@redhat.com>, Song Liu <song@kernel.org>
Subject: Re: [PATCH bpf-next] bpf: Fix NULL pointer dereference when registering bpf trampoline
Date: Thu, 28 Jul 2022 14:27:02 +0200 [thread overview]
Message-ID: <YuKAlk+p/ABzfUQ+@krava> (raw)
In-Reply-To: <20220728114048.3540461-1-xukuohai@huaweicloud.com>
On Thu, Jul 28, 2022 at 07:40:48AM -0400, Xu Kuohai wrote:
> From: Xu Kuohai <xukuohai@huawei.com>
SNIP
>
> It's caused by a NULL tr->fops passed to ftrace_set_filter_ip(). tr->fops
> is initialized to NULL and is assigned to an allocated memory address if
> CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS is enabled. Since there is no
> direct call on arm64 yet, the config can't be enabled.
>
> To fix it, call ftrace_set_filter_ip() only if tr->fops is not NULL.
>
> Fixes: 00963a2e75a8 ("bpf: Support bpf_trampoline on functions with IPMODIFY (e.g. livepatch)")
> Reported-by: Bruno Goncalves <bgoncalv@redhat.com>
> Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
> Tested-by: Bruno Goncalves <bgoncalv@redhat.com>
> Acked-by: Song Liu <songliubraving@fb.com>
> ---
> kernel/bpf/trampoline.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
> index 42e387a12694..0d5a9e0b9a7b 100644
> --- a/kernel/bpf/trampoline.c
> +++ b/kernel/bpf/trampoline.c
> @@ -255,8 +255,15 @@ static int register_fentry(struct bpf_trampoline *tr, void *new_addr)
> return -ENOENT;
>
> if (tr->func.ftrace_managed) {
> - ftrace_set_filter_ip(tr->fops, (unsigned long)ip, 0, 0);
> - ret = register_ftrace_direct_multi(tr->fops, (long)new_addr);
> + if (tr->fops)
> + ret = ftrace_set_filter_ip(tr->fops, (unsigned long)ip,
> + 0, 0);
> + else
> + ret = -ENOTSUPP;
> +
> + if (!ret)
> + ret = register_ftrace_direct_multi(tr->fops,
> + (long)new_addr);
> } else {
> ret = bpf_arch_text_poke(ip, BPF_MOD_CALL, NULL, new_addr);
> }
do we need to do the same also in unregister_fentry and modify_fentry ?
jirka
next prev parent reply other threads:[~2022-07-28 12:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-28 11:40 [PATCH bpf-next] bpf: Fix NULL pointer dereference when registering bpf trampoline Xu Kuohai
2022-07-28 12:27 ` Jiri Olsa [this message]
2022-07-28 12:56 ` Xu Kuohai
2022-07-28 13:25 ` Jiri Olsa
2022-07-29 21:56 ` Andrii Nakryiko
2022-07-29 22:00 ` patchwork-bot+netdevbpf
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=YuKAlk+p/ABzfUQ+@krava \
--to=olsajiri@gmail.com \
--cc=bgoncalv@redhat.com \
--cc=bpf@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=song@kernel.org \
--cc=xukuohai@huaweicloud.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.