[PATCH] virtio-net: use g_memdup2() instead of unsafe g_memdup()

Eugenio Pérez posted 1 patch 3 years, 10 months ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20220331182935.538101-1-eperezma@redhat.com
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Jason Wang <jasowang@redhat.com>
hw/net/virtio-net.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] virtio-net: use g_memdup2() instead of unsafe g_memdup()
Posted by Eugenio Pérez 3 years, 10 months ago
Fixing that literal checkpatch.pl because it will complain when we modify the file

Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
 hw/net/virtio-net.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 1067e72b39..e4748a7e6c 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -1443,7 +1443,8 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
         }

         iov_cnt = elem->out_num;
-        iov2 = iov = g_memdup(elem->out_sg, sizeof(struct iovec) * elem->out_num);
+        iov2 = iov = g_memdup2(elem->out_sg,
+                               sizeof(struct iovec) * elem->out_num);
         s = iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl));
         iov_discard_front(&iov, &iov_cnt, sizeof(ctrl));
         if (s != sizeof(ctrl)) {
--
2.27.0


Re: [PATCH] virtio-net: use g_memdup2() instead of unsafe g_memdup()
Posted by Jason Wang 3 years, 10 months ago
On Fri, Apr 1, 2022 at 2:29 AM Eugenio Pérez <eperezma@redhat.com> wrote:
>
> Fixing that literal checkpatch.pl because it will complain when we modify the file
>
> Signed-off-by: Eugenio Pérez <eperezma@redhat.com>

Acked-by: Jason Wang <jasowang@redhat.com>

> ---
>  hw/net/virtio-net.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> index 1067e72b39..e4748a7e6c 100644
> --- a/hw/net/virtio-net.c
> +++ b/hw/net/virtio-net.c
> @@ -1443,7 +1443,8 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
>          }
>
>          iov_cnt = elem->out_num;
> -        iov2 = iov = g_memdup(elem->out_sg, sizeof(struct iovec) * elem->out_num);
> +        iov2 = iov = g_memdup2(elem->out_sg,
> +                               sizeof(struct iovec) * elem->out_num);
>          s = iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl));
>          iov_discard_front(&iov, &iov_cnt, sizeof(ctrl));
>          if (s != sizeof(ctrl)) {
> --
> 2.27.0
>
Re: [PATCH] virtio-net: use g_memdup2() instead of unsafe g_memdup()
Posted by Philippe Mathieu-Daudé 3 years, 10 months ago
On 1/4/22 04:31, Jason Wang wrote:
> On Fri, Apr 1, 2022 at 2:29 AM Eugenio Pérez <eperezma@redhat.com> wrote:
>>
>> Fixing that literal checkpatch.pl because it will complain when we modify the file

See https://www.mail-archive.com/qemu-devel@nongnu.org/msg834178.html

>> Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> 
> Acked-by: Jason Wang <jasowang@redhat.com>
> 
>> ---
>>   hw/net/virtio-net.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
>> index 1067e72b39..e4748a7e6c 100644
>> --- a/hw/net/virtio-net.c
>> +++ b/hw/net/virtio-net.c
>> @@ -1443,7 +1443,8 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
>>           }
>>
>>           iov_cnt = elem->out_num;
>> -        iov2 = iov = g_memdup(elem->out_sg, sizeof(struct iovec) * elem->out_num);
>> +        iov2 = iov = g_memdup2(elem->out_sg,
>> +                               sizeof(struct iovec) * elem->out_num);
>>           s = iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl));
>>           iov_discard_front(&iov, &iov_cnt, sizeof(ctrl));
>>           if (s != sizeof(ctrl)) {
>> --
>> 2.27.0
>>
> 

Re: [PATCH] virtio-net: use g_memdup2() instead of unsafe g_memdup()
Posted by Eugenio Perez Martin 3 years, 10 months ago
On Fri, Apr 1, 2022 at 12:31 PM Philippe Mathieu-Daudé
<philippe.mathieu.daude@gmail.com> wrote:
>
> On 1/4/22 04:31, Jason Wang wrote:
> > On Fri, Apr 1, 2022 at 2:29 AM Eugenio Pérez <eperezma@redhat.com> wrote:
> >>
> >> Fixing that literal checkpatch.pl because it will complain when we modify the file
>
> See https://www.mail-archive.com/qemu-devel@nongnu.org/msg834178.html
>

Sorry I missed that series. It performs more replacements so regarding
virtio it's better to push yours.

Thanks!

> >> Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> >
> > Acked-by: Jason Wang <jasowang@redhat.com>
> >
> >> ---
> >>   hw/net/virtio-net.c | 3 ++-
> >>   1 file changed, 2 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> >> index 1067e72b39..e4748a7e6c 100644
> >> --- a/hw/net/virtio-net.c
> >> +++ b/hw/net/virtio-net.c
> >> @@ -1443,7 +1443,8 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
> >>           }
> >>
> >>           iov_cnt = elem->out_num;
> >> -        iov2 = iov = g_memdup(elem->out_sg, sizeof(struct iovec) * elem->out_num);
> >> +        iov2 = iov = g_memdup2(elem->out_sg,
> >> +                               sizeof(struct iovec) * elem->out_num);
> >>           s = iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl));
> >>           iov_discard_front(&iov, &iov_cnt, sizeof(ctrl));
> >>           if (s != sizeof(ctrl)) {
> >> --
> >> 2.27.0
> >>
> >
>