From: sashiko-bot@kernel.org
To: "Namhyung Kim" <namhyung@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2 3/4] perf annotate-date: Allow out-of-size access for flex-array types
Date: Mon, 14 Sep 2026 07:00:48 +0000 [thread overview]
Message-ID: <20260914070049.635701F0089C@smtp.kernel.org> (raw)
In-Reply-To: <20260914064535.1671939-4-namhyung@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] check_variable and check_matching_type fail to pass the typedef-resolved 'sized_type' to 'check_type_offset', causing an unused variable warning and breaking flex-array detection for typedefs.
- [Medium] Uninitialized stack variable 'last_mb' is used in 'die_has_flex_array_recurse' if a structure contains children but no data members.
--
commit cd675d28ffa1b31e0fe343fa27c89e7794eb74ec
Author: Namhyung Kim <namhyung@kernel.org>
perf annotate-date: Allow out-of-size access for flex-array types
Structs that have a flex array will have accesses beyond its original
size as the array was declared as 0 sized. For now, it just allow any
offset bigger than the size. It could be refined later.
> diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-data.c
> index aff60a630fd05..e8aff6a916c0a 100644
> --- a/tools/perf/util/annotate-data.c
> +++ b/tools/perf/util/annotate-data.c
[ ... ]
> @@ -399,6 +407,7 @@ static struct annotated_data_type *dso__findnew_data_type(struct dso *dso,
> result->self.type_name = type_name;
> result->self.size = size;
> INIT_LIST_HEAD(&result->self.children);
> + result->flex_array = die_has_flex_array(type_die);
[Severity: Medium]
Will this call into die_has_flex_array_recurse() trigger an uninitialized
stack variable access for empty structures?
If the structure has child DIEs but none of them are DW_TAG_member, the
last_mb variable won't be assigned in the loop, leaving it uninitialized
when evaluated:
tools/perf/util/dwarf-aux.c:die_has_flex_array_recurse() {
Dwarf_Die die_mem, last_mb;
...
do {
if (dwarf_tag(&die_mem) != DW_TAG_member)
continue;
...
if (tag == DW_TAG_structure_type)
memcpy(&last_mb, &die_mem, sizeof(last_mb));
} while (dwarf_siblingof(&die_mem, &die_mem) == 0);
if (tag == DW_TAG_structure_type) {
if (is_flex_array_member(&last_mb))
return true;
...
Should last_mb be initialized, or should we track whether it was set before
calling is_flex_array_member()?
>
> if (symbol_conf.annotate_data_member)
> add_member_types(result, type_die);
[ ... ]
> @@ -554,15 +580,7 @@ static enum type_match_result check_variable(struct data_loc_info *dloc,
> else
> sized_type = *type_die;
>
> - /* Get the size of the actual type */
> - if (dwarf_aggregate_size(&sized_type, &size) < 0)
> - return PERF_TMR_NO_SIZE;
> -
> - /* Minimal sanity check */
> - if ((unsigned)offset >= size)
> - return PERF_TMR_BAD_OFFSET;
> -
> - return PERF_TMR_OK;
> + return check_type_offset(type_die, offset);
> }
[Severity: Medium]
Should this pass &sized_type instead of type_die?
Passing type_die ignores the typedef resolution performed earlier in this
function and leaves sized_type completely unused. Since check_type_offset()
now evaluates die_has_flex_array(type_die), this might break flex-array
detection for types hidden behind typedefs.
[ ... ]
> @@ -1190,12 +1202,7 @@ static enum type_match_result check_matching_type(struct type_state *state,
>
> dloc->type_offset = dloc->op->offset + state->regs[reg].offset;
>
> - /* Get the size of the actual type */
> - if (dwarf_aggregate_size(type_die, &size) < 0 ||
> - (unsigned)dloc->type_offset >= size)
> - return PERF_TMR_BAD_OFFSET;
> -
> - return PERF_TMR_OK;
> + return check_type_offset(type_die, dloc->type_offset);
> }
[Severity: Medium]
For pointer types here, should type_die also be stripped of typedefs before
checking the type offset?
Similar to the logic used for TSR_KIND_TYPE, flex-arrays might go undetected
if they are hidden behind unresolved typedefs.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260914064535.1671939-1-namhyung@kernel.org?part=3
next prev parent reply other threads:[~2026-09-14 7:00 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 6:45 [PATCH v2 0/4] perf annotate-data: Support flexible array types Namhyung Kim
2026-09-14 6:45 ` [PATCH v2 1/4] perf annotate-data: Convert type histogram to hashmap Namhyung Kim
2026-09-14 6:58 ` sashiko-bot
2026-09-14 12:22 ` Tengda Wu
2026-09-14 18:56 ` Arnaldo Carvalho de Melo
2026-09-14 19:22 ` Arnaldo Carvalho de Melo
2026-09-14 20:42 ` Namhyung Kim
2026-09-14 6:45 ` [PATCH v2 2/4] perf dwarf-aux: Add die_has_flex_array() helper Namhyung Kim
2026-09-14 6:53 ` sashiko-bot
2026-09-14 12:14 ` Tengda Wu
2026-09-14 20:28 ` Namhyung Kim
2026-09-14 23:40 ` Masami Hiramatsu
2026-09-15 5:54 ` Namhyung Kim
2026-09-16 13:56 ` Masami Hiramatsu
2026-09-14 6:45 ` [PATCH v2 3/4] perf annotate-date: Allow out-of-size access for flex-array types Namhyung Kim
2026-09-14 7:00 ` sashiko-bot [this message]
2026-09-14 20:32 ` Namhyung Kim
2026-09-14 12:19 ` Tengda Wu
2026-09-14 20:39 ` Namhyung Kim
2026-09-14 6:45 ` [PATCH v2 4/4] perf annotate-data: Adjust type offset for flex-array Namhyung Kim
2026-09-14 7:01 ` sashiko-bot
2026-09-14 20:38 ` Namhyung Kim
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=20260914070049.635701F0089C@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=namhyung@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.