mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Lecomte, Arnaud" <contact@arnaud-lcm.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	Song Liu <song@kernel.org>
Cc: Yonghong Song <yonghong.song@linux.dev>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Andrii Nakryiko <andrii@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>, bpf <bpf@vger.kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Eduard <eddyz87@gmail.com>, Hao Luo <haoluo@google.com>,
	John Fastabend <john.fastabend@gmail.com>,
	Jiri Olsa <jolsa@kernel.org>, KP Singh <kpsingh@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>,
	syzbot+c9b724fbb41cf2538b7b@syzkaller.appspotmail.com,
	syzkaller-bugs <syzkaller-bugs@googlegroups.com>
Subject: Re: [PATCH bpf-next v5 2/2] bpf: fix stackmap overflow check in __bpf_get_stackid()
Date: Sat, 30 Aug 2025 19:13:50 +0200	[thread overview]
Message-ID: <c2d982c2-9593-4ac7-91d6-635b94f52d4e@arnaud-lcm.com> (raw)
In-Reply-To: <CAADnVQK=3xigzt-pCat5OF29xT_F7-5rXDOMG+_FLSS0jRoWsQ@mail.gmail.com>


On 30/08/2025 02:28, Alexei Starovoitov wrote:
> On Fri, Aug 29, 2025 at 11:50 AM Song Liu <song@kernel.org> wrote:
>> On Fri, Aug 29, 2025 at 10:29 AM Alexei Starovoitov
>> <alexei.starovoitov@gmail.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 ?
Thanks for your guidance in advance,
Arnaud


  reply	other threads:[~2025-08-30 17:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-26 21:22 [PATCH bpf-next v5 1/2] bpf: refactor max_depth computation in bpf_get_stack() Arnaud Lecomte
2025-08-26 21:23 ` [PATCH bpf-next v5 2/2] bpf: fix stackmap overflow check in __bpf_get_stackid() Arnaud Lecomte
2025-08-29 17:29   ` Alexei Starovoitov
2025-08-29 18:49     ` Song Liu
2025-08-30  0:28       ` Alexei Starovoitov
2025-08-30 17:13         ` Lecomte, Arnaud [this message]
2025-09-01  1:10           ` Alexei Starovoitov

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=c2d982c2-9593-4ac7-91d6-635b94f52d4e@arnaud-lcm.com \
    --to=contact@arnaud-lcm.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=syzbot+c9b724fbb41cf2538b7b@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.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

all inboxes | Powered by JetHome®