[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAADnVQK=3xigzt-pCat5OF29xT_F7-5rXDOMG+_FLSS0jRoWsQ@mail.gmail.com>
Date: Fri, 29 Aug 2025 17:28:01 -0700
From: Alexei Starovoitov <alexei.starovoitov@...il.com>
To: Song Liu <song@...nel.org>
Cc: Arnaud Lecomte <contact@...aud-lcm.com>, Yonghong Song <yonghong.song@...ux.dev>,
Martin KaFai Lau <martin.lau@...ux.dev>, Andrii Nakryiko <andrii@...nel.org>,
Alexei Starovoitov <ast@...nel.org>, bpf <bpf@...r.kernel.org>,
Daniel Borkmann <daniel@...earbox.net>, Eduard <eddyz87@...il.com>, Hao Luo <haoluo@...gle.com>,
John Fastabend <john.fastabend@...il.com>, Jiri Olsa <jolsa@...nel.org>,
KP Singh <kpsingh@...nel.org>, LKML <linux-kernel@...r.kernel.org>,
Stanislav Fomichev <sdf@...ichev.me>, syzbot+c9b724fbb41cf2538b7b@...kaller.appspotmail.com,
syzkaller-bugs <syzkaller-bugs@...glegroups.com>
Subject: Re: [PATCH bpf-next v5 2/2] bpf: fix stackmap overflow check in __bpf_get_stackid()
On Fri, Aug 29, 2025 at 11:50 AM Song Liu <song@...nel.org> wrote:
>
> On Fri, Aug 29, 2025 at 10:29 AM Alexei Starovoitov
> <alexei.starovoitov@...il.com> wrote:
> [...]
> > >
> > > static long __bpf_get_stackid(struct bpf_map *map,
> > > - struct perf_callchain_entry *trace, u64 flags)
> > > + struct perf_callchain_entry *trace, u64 flags, u32 max_depth)
> > > {
> > > struct bpf_stack_map *smap = container_of(map, struct bpf_stack_map, map);
> > > struct stack_map_bucket *bucket, *new_bucket, *old_bucket;
> > > @@ -263,6 +263,8 @@ static long __bpf_get_stackid(struct bpf_map *map,
> > >
> > > trace_nr = trace->nr - skip;
> > > trace_len = trace_nr * sizeof(u64);
> > > + trace_nr = min(trace_nr, max_depth - skip);
> > > +
> >
> > The patch might have fixed this particular syzbot repro
> > with OOB in stackmap-with-buildid case,
> > but above two line looks wrong.
> > trace_len is computed before being capped by max_depth.
> > So non-buildid case below is using
> > memcpy(new_bucket->data, ips, trace_len);
> >
> > so OOB is still there?
>
> +1 for this observation.
>
> We are calling __bpf_get_stackid() from two functions: bpf_get_stackid
> and bpf_get_stackid_pe. The check against max_depth is only needed
> from bpf_get_stackid_pe, so it is better to just check here.
Good point.
> I have got the following on top of patch 1/2. This makes more sense to
> me.
>
> PS: The following also includes some clean up in __bpf_get_stack.
> I include those because it also uses stack_map_calculate_max_depth.
>
> Does this look better?
yeah. It's certainly cleaner to avoid adding extra arg to
__bpf_get_stackid()
Powered by blists - more mailing lists