Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Gokul K" <gokul02k@gmail.com>, kvm@vger.kernel.org
Subject: Re: [PATCH 3/3] KVM: selftests: Free the stats id string when no stats are defined
Date: Tue, 01 Dec 2026 09:12:06 +0000	[thread overview]
Message-ID: <sashiko-outbox-242923@kernel.org> (raw)
In-Reply-To: <20261201090632.2482795-4-gokul02k@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] KVM: selftests: stats_fd leak in stats_test() when
  header.num_desc == 0
--

commit 38dd872f0f6bd2de7be54a91cb51a47a844eca82
Author: Gokul K <gokul02k@gmail.com>

KVM: selftests: Free the stats id string when no stats are defined

This commit frees the allocated id string in stats_test() before returning
early when header.num_desc is zero.

> diff --git a/tools/testing/selftests/kvm/kvm_binary_stats_test.c b/tools/testing/selftests/kvm/kvm_binary_stats_test.c
> index b7dbde9c08436..89ae011ffae9f 100644
> --- a/tools/testing/selftests/kvm/kvm_binary_stats_test.c
> +++ b/tools/testing/selftests/kvm/kvm_binary_stats_test.c
> @@ -53,6 +53,7 @@ static void stats_test(int stats_fd)
>  	/* Sanity check for other fields in header */
>  	if (header.num_desc == 0) {
>  		ksft_print_msg("No KVM stats defined!\n");
> +		free(id);
>  		return;
>  	}

[Severity: Low]
Does this early return still leak stats_fd?

main() passes newly opened or duplicated file descriptors directly to
stats_test(), such as stats_test(kvm_dup(vm_stats_fds)) and
stats_test(vm_get_stats_fd(vms[i])), and relies on the tail of stats_test()
to close them:

tools/testing/selftests/kvm/kvm_binary_stats_test.c:stats_test() {
    ...
	free(stats_data);
	free(stats_desc);
	free(id);

	close(stats_fd);
	TEST_ASSERT(fcntl(stats_fd, F_GETFD) == -1, "Stats fd not freed");
}

Placing a label right before free(id) at the end of stats_test() and jumping
to it here would free id and close stats_fd without touching the
uninitialized stats_data and stats_desc pointers.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201090632.2482795-1-gokul02k@gmail.com?part=3

      reply	other threads:[~2026-12-01  9:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  9:06 [PATCH 0/3] KVM: selftests: Fix three leaked resources Gokul K
2026-12-01  9:06 ` [PATCH 1/3] KVM: selftests: Close /dev/sev when an SEV VM is released Gokul K
2026-12-01  9:06 ` [PATCH 2/3] KVM: selftests: Close the SEV fd opened for each KVM_SEV_INIT2 ioctl Gokul K
2026-12-01  9:06 ` [PATCH 3/3] KVM: selftests: Free the stats id string when no stats are defined Gokul K
2026-12-01  9:12   ` 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=sashiko-outbox-242923@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=gokul02k@gmail.com \
    --cc=kvm@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox