From: "Michael S. Tsirkin" <mst@redhat.com>
To: Julia Lawall <Julia.Lawall@inria.fr>
Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
keescook@chromium.org, kernel-janitors@vger.kernel.org,
linux-kernel@vger.kernel.org,
virtualization@lists.linux-foundation.org
Subject: Re: [PATCH 08/26] virtio-mem: use array_size
Date: Mon, 26 Jun 2023 06:59:09 -0400 [thread overview]
Message-ID: <20230626065202-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20230623211457.102544-9-Julia.Lawall@inria.fr>
On Fri, Jun 23, 2023 at 11:14:39PM +0200, Julia Lawall wrote:
> Use array_size to protect against multiplication overflows.
>
> The changes were done using the following Coccinelle semantic patch:
>
> // <smpl>
> @@
> expression E1, E2;
> constant C1, C2;
> identifier alloc = {vmalloc,vzalloc};
> @@
>
> (
> alloc(C1 * C2,...)
> |
> alloc(
> - (E1) * (E2)
> + array_size(E1, E2)
> ,...)
> )
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
>
> ---
> drivers/virtio/virtio_mem.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
can't hurt I guess.
Acked-by: Michael S. Tsirkin <mst@redhat.com>
> diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c
> index 835f6cc2fb66..a4dfe7aab288 100644
> --- a/drivers/virtio/virtio_mem.c
> +++ b/drivers/virtio/virtio_mem.c
> @@ -399,7 +399,7 @@ static int virtio_mem_bbm_bb_states_prepare_next_bb(struct virtio_mem *vm)
> if (vm->bbm.bb_states && old_pages == new_pages)
> return 0;
>
> - new_array = vzalloc(new_pages * PAGE_SIZE);
> + new_array = vzalloc(array_size(new_pages, PAGE_SIZE));
> if (!new_array)
> return -ENOMEM;
>
> @@ -465,7 +465,7 @@ static int virtio_mem_sbm_mb_states_prepare_next_mb(struct virtio_mem *vm)
> if (vm->sbm.mb_states && old_pages == new_pages)
> return 0;
>
> - new_array = vzalloc(new_pages * PAGE_SIZE);
> + new_array = vzalloc(array_size(new_pages, PAGE_SIZE));
> if (!new_array)
> return -ENOMEM;
>
> @@ -588,7 +588,7 @@ static int virtio_mem_sbm_sb_states_prepare_next_mb(struct virtio_mem *vm)
> if (vm->sbm.sb_states && old_pages == new_pages)
> return 0;
>
> - new_bitmap = vzalloc(new_pages * PAGE_SIZE);
> + new_bitmap = vzalloc(array_size(new_pages, PAGE_SIZE));
> if (!new_bitmap)
> return -ENOMEM;
>
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
prev parent reply other threads:[~2023-06-26 10:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230623211457.102544-1-Julia.Lawall@inria.fr>
[not found] ` <20230623211457.102544-9-Julia.Lawall@inria.fr>
2023-06-25 1:39 ` [PATCH 08/26] virtio-mem: use array_size Xuan Zhuo
2023-06-26 7:40 ` David Hildenbrand
2023-06-26 10:59 ` Michael S. Tsirkin [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=20230626065202-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=Julia.Lawall@inria.fr \
--cc=keescook@chromium.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=virtualization@lists.linux-foundation.org \
--cc=xuanzhuo@linux.alibaba.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).