From: sashiko-bot@kernel.org
To: "Michalis Niarchos" <michael.niarchos@gmail.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2 4/4] perf tools: Fix double frees and memory leaks in cmd_kvm()
Date: Mon, 03 Aug 2026 13:39:22 +0000 [thread overview]
Message-ID: <20260803133923.6C7DE1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260803-perf-kvm-fixes-v2-4-1b337189fffc@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The patch fixes memory leaks and double-free vulnerabilities in `__cmd_record`, `__cmd_report`, `__cmd_buildid_list`, and `__cmd_top` by removing `STRDUP_FAIL_EXIT` and the element-wise `free()` loop on `rec_argv`, but it misses applying the exact same fix to `kvm_events_record()` which suffers from the identical bug.
--
--- Patch [4]: [PATCH v2 4/4] perf tools: Fix double frees and memory leaks in cmd_kvm() ---
commit 0b9d8e748caa2edae90fe11689ed1a0bf618e63b
Author: Michalis Niarchos <michael.niarchos@gmail.com>
perf tools: Fix double frees and memory leaks in cmd_kvm()
This commit fixes double free and memory leak vulnerabilities in various
builtin KVM commands (like __cmd_record, __cmd_report, __cmd_buildid_list,
and __cmd_top). It achieves this by removing the use of STRDUP_FAIL_EXIT and
dropping the element-wise free loop on rec_argv.
> diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
> index 9504c83e20744..04cf9bd5b5959 100644
> --- a/tools/perf/builtin-kvm.c
> +++ b/tools/perf/builtin-kvm.c
> @@ -2018,8 +2018,6 @@ static int __cmd_record(const char *file_name, int argc, const char **argv)
> ret = cmd_record(i, rec_argv);
>
> EXIT:
> - for (i = 0; i < rec_argc; i++)
> - free((void *)rec_argv[i]);
> free(rec_argv);
> return ret;
> }
[Severity: High]
This is a pre-existing issue and was not introduced by this patch, but does
kvm_events_record() in tools/perf/builtin-kvm.c require this exact same fix?
The commit message notes that the fixed functions follow the same pattern
as kvm_events_record(). However, looking at kvm_events_record(), it appears
it still contains the flawed cleanup loop:
tools/perf/builtin-kvm.c:kvm_events_record() {
...
EXIT:
for (i = 0; i < rec_argc; i++)
free((void *)rec_argv[i]);
free(rec_argv);
return ret;
}
When a user runs 'perf kvm stat record', cmd_record() processes the arguments
by calling parse_options(). Since parse_options() shifts the array in-place
using memmove() to consume recognized arguments, iterating over the original
length of rec_argv (rec_argc) during cleanup encounters duplicated pointers at
the end of the array.
Will leaving this loop in kvm_events_record() lead to a double-free memory
corruption when those duplicate pointers are freed?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260803-perf-kvm-fixes-v2-0-1b337189fffc@gmail.com?part=4
prev parent reply other threads:[~2026-08-03 13:39 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-03 13:05 [PATCH v2 0/4] perf tools: Fix memory issues Michalis Niarchos via B4 Relay
2026-08-03 13:05 ` Michalis Niarchos
2026-08-03 13:05 ` [PATCH v2 1/4] perf tools: Fix memory leak in cmd_kvm() Michalis Niarchos via B4 Relay
2026-08-03 13:05 ` Michalis Niarchos
2026-08-03 13:19 ` sashiko-bot
2026-08-03 13:05 ` [PATCH v2 2/4] perf tools: Fix double free and memory leak in kvm_events_record() Michalis Niarchos via B4 Relay
2026-08-03 13:05 ` Michalis Niarchos
2026-08-03 13:37 ` sashiko-bot
2026-08-03 13:05 ` [PATCH v2 3/4] perf tools: Fix memory leak in cmd_kvm() Michalis Niarchos via B4 Relay
2026-08-03 13:05 ` Michalis Niarchos
2026-08-03 13:05 ` [PATCH v2 4/4] perf tools: Fix double frees and memory leaks " Michalis Niarchos via B4 Relay
2026-08-03 13:05 ` Michalis Niarchos
2026-08-03 13:39 ` sashiko-bot [this message]
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=20260803133923.6C7DE1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=michael.niarchos@gmail.com \
--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.