linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavoars@kernel.org>
To: Rustam Kovhaev <rkovhaev@gmail.com>
Cc: pbonzini@redhat.com, vkuznets@redhat.com, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] KVM: use struct_size() and flex_array_size() helpers in kvm_io_bus_unregister_dev()
Date: Fri, 18 Sep 2020 19:09:25 -0500	[thread overview]
Message-ID: <20200919000925.GA23967@embeddedor> (raw)
In-Reply-To: <20200918120500.954436-1-rkovhaev@gmail.com>

On Fri, Sep 18, 2020 at 05:05:00AM -0700, Rustam Kovhaev wrote:
> Make use of the struct_size() helper to avoid any potential type
> mistakes and protect against potential integer overflows
> Make use of the flex_array_size() helper to calculate the size of a
> flexible array member within an enclosing structure
> 
> Cc: stable@vger.kernel.org

I don't think this change applies for -stable.

> Suggested-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> Signed-off-by: Rustam Kovhaev <rkovhaev@gmail.com>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks!
--
Gustavo

> ---
>  virt/kvm/kvm_main.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index cf88233b819a..68edd25dcb11 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -4350,10 +4350,10 @@ void kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
>  	new_bus = kmalloc(struct_size(bus, range, bus->dev_count - 1),
>  			  GFP_KERNEL_ACCOUNT);
>  	if (new_bus) {
> -		memcpy(new_bus, bus, sizeof(*bus) + i * sizeof(struct kvm_io_range));
> +		memcpy(new_bus, bus, struct_size(bus, range, i));
>  		new_bus->dev_count--;
>  		memcpy(new_bus->range + i, bus->range + i + 1,
> -		       (new_bus->dev_count - i) * sizeof(struct kvm_io_range));
> +				flex_array_size(new_bus, range, new_bus->dev_count - i));
>  	} else {
>  		pr_err("kvm: failed to shrink bus, removing it completely\n");
>  		for (j = 0; j < bus->dev_count; j++) {
> -- 
> 2.28.0
> 

  reply	other threads:[~2020-09-19  0:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-18 12:05 [PATCH] KVM: use struct_size() and flex_array_size() helpers in kvm_io_bus_unregister_dev() Rustam Kovhaev
2020-09-19  0:09 ` Gustavo A. R. Silva [this message]
2020-09-22 12:43   ` Paolo Bonzini
2020-09-21 12:54 ` Sasha Levin
2020-09-30 17:58   ` Gustavo A. R. Silva

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=20200919000925.GA23967@embeddedor \
    --to=gustavoars@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkovhaev@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=vkuznets@redhat.com \
    /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;
as well as URLs for NNTP newsgroup(s).