lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAADnVQJ8+xSJDnQeOQV=pT=oML37x=KygETGnA6AWJn=fEBFnw@mail.gmail.com>
Date: Sun, 31 Aug 2025 18:10:31 -0700
From: Alexei Starovoitov <alexei.starovoitov@...il.com>
To: "Lecomte, Arnaud" <contact@...aud-lcm.com>
Cc: Song Liu <song@...nel.org>, 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 Sat, Aug 30, 2025 at 10:13 AM Lecomte, Arnaud <contact@...aud-lcm.com> wrote:
>
>
> On 30/08/2025 02:28, Alexei Starovoitov wrote:
> > 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.
> Nice catch, thanks !
> >
> >> 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()
> >
> Are Song patches going to be applied then ?  Or should I raise a new
> revision
>   of the patch with Song's modifications with a Co-developped tag ?

Pls resubmit and retest with a tag.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ