mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Jones <ajones@ventanamicro.com>
To: Mark Brown <broonie@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Shuah Khan <shuah@kernel.org>, Haibo Xu <haibo1.xu@intel.com>,
	Anup Patel <anup@brainfault.org>,
	kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: selftests: Initialise dynamically allocated configuration names
Date: Fri, 13 Oct 2023 08:30:04 +0200	[thread overview]
Message-ID: <20231013-0fb230037c78d2c397e691c7@orel> (raw)
In-Reply-To: <20231013-kvm-get-reg-list-str-init-v1-1-034f370ff8ab@kernel.org>

On Fri, Oct 13, 2023 at 12:19:30AM +0100, Mark Brown wrote:
> When we dynamically generate a name for a configuration in get-reg-list
> we use strcat() to append to a buffer allocated using malloc() but we
> never initialise that buffer. Since malloc() offers no guarantees
> regarding the contents of the memory it returns this can lead to us
> corrupting, and likely overflowing, the buffer:
> 
>   vregs: PASS
>   vregs+pmu: PASS
>   sve: PASS
>   sve+pmu: PASS
>   vregs+pauth_address+pauth_generic: PASS
>   X�vr+gspauth_addre+spauth_generi+pmu: PASS
> 
> Initialise the buffer to an empty string to avoid this.
> 
> Fixes: 17da79e009c37 ("KVM: arm64: selftests: Split get-reg-list test code")

Doh, this is an embarrassing bug. But the patch above just moves the buggy
code. I'm still guilty for the bug, but the fixes tag should be

Fixes: 2f9ace5d4557 ("KVM: arm64: selftests: get-reg-list: Introduce vcpu configs")

> Signed-off-by: Mark Brown <broonie@kernel.org>
> ---
>  tools/testing/selftests/kvm/get-reg-list.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tools/testing/selftests/kvm/get-reg-list.c b/tools/testing/selftests/kvm/get-reg-list.c
> index be7bf5224434..dd62a6976c0d 100644
> --- a/tools/testing/selftests/kvm/get-reg-list.c
> +++ b/tools/testing/selftests/kvm/get-reg-list.c
> @@ -67,6 +67,7 @@ static const char *config_name(struct vcpu_reg_list *c)
>  
>  	c->name = malloc(len);
>  
> +	c->name[0] = '\0';
>  	len = 0;
>  	for_each_sublist(c, s) {
>  		if (!strcmp(s->name, "base"))
> 
> ---
> base-commit: 6465e260f48790807eef06b583b38ca9789b6072
> change-id: 20231012-kvm-get-reg-list-str-init-76c8ed4e19d6
>

Other than the tag,

Reviewed-by: Andrew Jones <ajones@ventanamicro.com>

Thanks,
drew

      reply	other threads:[~2023-10-13  6:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-12 23:19 Mark Brown
2023-10-13  6:30 ` Andrew Jones [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=20231013-0fb230037c78d2c397e691c7@orel \
    --to=ajones@ventanamicro.com \
    --cc=anup@brainfault.org \
    --cc=broonie@kernel.org \
    --cc=haibo1.xu@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=shuah@kernel.org \
    /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®