Message ID | 20230804105732.3768-2-laoar.shao@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | BPF |
Headers | show |
Series | bpf: Fix fill_link_info and add selftest | expand |
On Fri, Aug 04, 2023 at 10:57:31AM +0000, Yafang Shao wrote: > The patch 1b715e1b0ec5: "bpf: Support ->fill_link_info for > perf_event" from Jul 9, 2023, leads to the following Smatch static > checker warning: > > kernel/bpf/syscall.c:3416 bpf_perf_link_fill_kprobe() > error: uninitialized symbol 'type'. > > That can happens when uname is NULL. So fix it by verifying the uname > when we really need to fill it. > > Fixes: 1b715e1b0ec5 ("bpf: Support ->fill_link_info for perf_event") > Reported-by: Dan Carpenter <dan.carpenter@linaro.org> > Closes: https://lore.kernel.org/bpf/85697a7e-f897-4f74-8b43-82721bebc462@kili.mountain/ > Signed-off-by: Yafang Shao <laoar.shao@gmail.com> > Acked-by: Yonghong Song <yonghong.song@linux.dev> Acked-by: Jiri Olsa <jolsa@kernel.org> jirka > --- > kernel/bpf/syscall.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c > index 7f4e8c3..166390f 100644 > --- a/kernel/bpf/syscall.c > +++ b/kernel/bpf/syscall.c > @@ -3378,14 +3378,14 @@ static int bpf_perf_link_fill_common(const struct perf_event *event, > > if (!ulen ^ !uname) > return -EINVAL; > - if (!uname) > - return 0; > > err = bpf_get_perf_event_info(event, &prog_id, fd_type, &buf, > probe_offset, probe_addr); > if (err) > return err; > > + if (!uname) > + return 0; > if (buf) { > len = strlen(buf); > err = bpf_copy_to_user(uname, buf, ulen, len); > -- > 1.8.3.1 >
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 7f4e8c3..166390f 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -3378,14 +3378,14 @@ static int bpf_perf_link_fill_common(const struct perf_event *event, if (!ulen ^ !uname) return -EINVAL; - if (!uname) - return 0; err = bpf_get_perf_event_info(event, &prog_id, fd_type, &buf, probe_offset, probe_addr); if (err) return err; + if (!uname) + return 0; if (buf) { len = strlen(buf); err = bpf_copy_to_user(uname, buf, ulen, len);