From: Jiri Olsa <olsajiri@gmail.com>
To: Jiri Olsa <olsajiri@gmail.com>
Cc: Yonghong Song <yonghong.song@linux.dev>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
bpf@vger.kernel.org, Martin KaFai Lau <kafai@fb.com>,
Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@chromium.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
Yafang Shao <laoar.shao@gmail.com>
Subject: Re: [PATCHv3 bpf-next 3/6] bpf: Add link_info support for uprobe multi link
Date: Thu, 23 Nov 2023 10:20:07 +0100 [thread overview]
Message-ID: <ZV8ZR0UD8A7tJiil@krava> (raw)
In-Reply-To: <ZV53jlOMcLu3dRVt@krava>
On Wed, Nov 22, 2023 at 10:50:06PM +0100, Jiri Olsa wrote:
> On Mon, Nov 20, 2023 at 10:04:16AM -0800, Yonghong Song wrote:
>
> SNIP
>
> > > +static int bpf_uprobe_multi_link_fill_link_info(const struct bpf_link *link,
> > > + struct bpf_link_info *info)
> > > +{
> > > + u64 __user *uref_ctr_offsets = u64_to_user_ptr(info->uprobe_multi.ref_ctr_offsets);
> > > + u64 __user *ucookies = u64_to_user_ptr(info->uprobe_multi.cookies);
> > > + u64 __user *uoffsets = u64_to_user_ptr(info->uprobe_multi.offsets);
> > > + u64 __user *upath = u64_to_user_ptr(info->uprobe_multi.path);
> > > + u32 upath_size = info->uprobe_multi.path_size;
> > > + struct bpf_uprobe_multi_link *umulti_link;
> > > + u32 ucount = info->uprobe_multi.count;
> > > + int err = 0, i;
> > > + long left;
> > > +
> > > + if (!upath ^ !upath_size)
> > > + return -EINVAL;
> > > +
> > > + if ((uoffsets || uref_ctr_offsets || ucookies) && !ucount)
> > > + return -EINVAL;
> > > +
> > > + umulti_link = container_of(link, struct bpf_uprobe_multi_link, link);
> > > + info->uprobe_multi.count = umulti_link->cnt;
> > > + info->uprobe_multi.flags = umulti_link->flags;
> > > + info->uprobe_multi.pid = umulti_link->task ?
> > > + task_pid_nr_ns(umulti_link->task, task_active_pid_ns(current)) : 0;
> > > +
> > > + if (upath) {
> > > + char *p, *buf;
> > > +
> > > + upath_size = min_t(u32, upath_size, PATH_MAX);
> > > +
> > > + buf = kmalloc(upath_size, GFP_KERNEL);
> > > + if (!buf)
> > > + return -ENOMEM;
> > > + p = d_path(&umulti_link->path, buf, upath_size);
> > > + if (IS_ERR(p)) {
> > > + kfree(buf);
> > > + return -ENOSPC;
> >
> > Should we just return PTR_ERR(p)? In d_path, it is possible that
> > -ENAMETOOLONG is returned. But path->dentry->d_op->d_dname() might
> > return a different error reason than -ENAMETOOLONG or -ENOSPC?
>
> true, will change
>
> >
> > > + }
> > > + upath_size = buf + upath_size - p;
> > > + left = copy_to_user(upath, p, upath_size);
> >
> > Here, the data copied to user may contain more than
> > actual path itself. I am okay with this since this
> > is not in critical path. But early buf allocation is using
> > kmalloc whose content could be arbitrary. Should we
> > use kzalloc for the above 'buf' allocation?
>
> good catch, will use kzalloc
hum, actually.. after checking d_path IIUC it copies into the end of buffer,
so I can't see this code copying more data to user buffer
jirka
next prev parent reply other threads:[~2023-11-23 9:20 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-20 14:56 [PATCHv3 bpf-next 0/6] bpf: Add link_info support for uprobe multi link Jiri Olsa
2023-11-20 14:56 ` [PATCHv3 bpf-next 1/6] libbpf: Add st_type argument to elf_resolve_syms_offsets function Jiri Olsa
2023-11-20 14:56 ` [PATCHv3 bpf-next 2/6] bpf: Store ref_ctr_offsets values in bpf_uprobe array Jiri Olsa
2023-11-20 14:56 ` [PATCHv3 bpf-next 3/6] bpf: Add link_info support for uprobe multi link Jiri Olsa
2023-11-20 18:04 ` Yonghong Song
2023-11-22 21:50 ` Jiri Olsa
2023-11-23 9:20 ` Jiri Olsa [this message]
2023-11-23 18:26 ` Yonghong Song
2023-11-21 18:41 ` Andrii Nakryiko
2023-11-22 13:48 ` Jiri Olsa
2023-11-20 14:56 ` [PATCHv3 bpf-next 4/6] selftests/bpf: Use bpf_link__destroy in fill_link_info tests Jiri Olsa
2023-11-20 18:06 ` Yonghong Song
2023-11-20 14:56 ` [PATCHv3 bpf-next 5/6] selftests/bpf: Add link_info test for uprobe_multi link Jiri Olsa
2023-11-20 18:22 ` Yonghong Song
2023-11-21 11:29 ` Jiri Olsa
2023-11-20 14:56 ` [PATCHv3 bpf-next 6/6] bpftool: Add support to display uprobe_multi links Jiri Olsa
2023-11-20 18:32 ` Yonghong Song
2023-11-21 11:35 ` Jiri Olsa
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=ZV8ZR0UD8A7tJiil@krava \
--to=olsajiri@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@chromium.org \
--cc=laoar.shao@gmail.com \
--cc=sdf@google.com \
--cc=songliubraving@fb.com \
--cc=yhs@fb.com \
--cc=yonghong.song@linux.dev \
/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