All of lore.kernel.org
 help / color / mirror / Atom feed
From: Quentin Monnet <qmo@kernel.org>
To: sashiko-reviews@lists.linux.dev, Alan Maguire <alan.maguire@oracle.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v2 bpf-next 2/3] bpftool: Update func representation to include function signature
Date: Fri, 25 Sep 2026 20:55:02 +0100	[thread overview]
Message-ID: <6fc6245b-5497-40dd-a032-53c323467d2f@kernel.org> (raw)
In-Reply-To: <20260925171703.5D9EB1F000FF@smtp.kernel.org>

2026-09-25 17:17 UTC+0000 ~ sashiko-bot@kernel.org
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] bpf: btf_locsec_append hides truncation marker due to null byte gap
> --
> 
> commit 6f503008243b4dfc886859b905f8a6fa7b657ef2
> Author: Alan Maguire <alan.maguire@oracle.com>
> 
> bpftool: Update func representation to include function signature
> 
> This commit augments the func= output for LOCSEC entries to include a mapping
> from function signature to where parameters are stored. It addresses a feature
> suggestion to dump LOC_PARAM, LOC_PROTO and LOCSEC more verbosely.
> 
>> diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
>> index e29c8a84e224c..ce4c4036c2796 100644
>> --- a/tools/bpf/bpftool/btf.c
>> +++ b/tools/bpf/bpftool/btf.c
> 
> [ ... ]
> 
>> +static bool btf_locsec_append(char *str, size_t sz, size_t *off,
>> +			      const char *suffix)
>> +{
>> +	size_t len;
>> +
>> +	if (!sz || *off >= sz)
>> +		return false;
>> +
>> +	len = strlen(suffix);
>> +	if (len < sz - *off) {
>> +		memcpy(str + *off, suffix, len + 1);
>> +		*off += len;
>> +		return true;
>> +	}
>> +
>> +	if (sz >= 4) {
>> +		memcpy(str + sz - 4, "...", 4);
>> +	} else if (sz > 1) {
> 
> [Severity: Medium]
> When a string exceeds the buffer size and we hit this fallback path in
> btf_locsec_append(), is there a risk that the truncation marker is hidden?
> 
> The truncation marker ... is unconditionally placed at the very end of the
> buffer (sz - 4). Because the function fails to copy the prefix of the string
> that would fit and does not write over the existing null terminator at *off,
> a gap of null bytes can separate the current end of the string from the
> truncation marker.
> 
> String reading functions like printf or JSON dumpers will terminate at the
> first null byte, which would completely hide the ... marker and discard the
> partial data.
> 
> This would be triggered when bpftool formats a BTF location string (for 
> example, a function signature with many parameters) that cumulatively exceeds
> 1024 characters.

Maybe copy whatever we can from the suffix first, overwrite the end with
the dots after? Something like:

        if (sz >= 4) {
                size_t space_left = sz - 1 - *off;

                if (space_left)
                        memcpy(str + *off, suffix, space_left);
                memcpy(str + sz - 4, "...", 4);
        }

  reply	other threads:[~2026-09-25 19:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-25 17:08 [PATCH v2 bpf-next 0/3] BTF inline functionality followups Alan Maguire
2026-09-25 17:08 ` [PATCH v2 bpf-next 1/3] bpf: Verify BTF_KIND_LOC_PARAM vlen, flags Alan Maguire
2026-09-25 20:35   ` Alexei Starovoitov
2026-09-25 17:08 ` [PATCH v2 bpf-next 2/3] bpftool: Update func representation to include function signature Alan Maguire
2026-09-25 17:17   ` sashiko-bot
2026-09-25 19:55     ` Quentin Monnet [this message]
2026-09-25 17:08 ` [PATCH v2 bpf-next 3/3] selftests/bpf: Fix up bpftool btf dump test for signatures Alan Maguire

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=6fc6245b-5497-40dd-a032-53c323467d2f@kernel.org \
    --to=qmo@kernel.org \
    --cc=alan.maguire@oracle.com \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.