qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hw/xen: Check if len is 0 before memcpy()
@ 2025-01-08 11:31 Akihiko Odaki
  2025-01-08 11:42 ` Philippe Mathieu-Daudé
  2025-01-08 11:47 ` David Woodhouse
  0 siblings, 2 replies; 3+ messages in thread
From: Akihiko Odaki @ 2025-01-08 11:31 UTC (permalink / raw)
  To: David Woodhouse, Paul Durrant, Michael S. Tsirkin,
	Marcel Apfelbaum, Paolo Bonzini, Richard Henderson,
	Eduardo Habkost
  Cc: qemu-devel, devel, Akihiko Odaki

data->data can be NULL when len is 0. Strictly speaking, the behavior
of memcpy() in such a scenario is undefined so UBSan complaints.

Satisfy UBSan by checking if len is 0 before memcpy().

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
 hw/i386/kvm/xen_xenstore.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/hw/i386/kvm/xen_xenstore.c b/hw/i386/kvm/xen_xenstore.c
index 59691056670e..17802aa33d20 100644
--- a/hw/i386/kvm/xen_xenstore.c
+++ b/hw/i386/kvm/xen_xenstore.c
@@ -532,6 +532,10 @@ static void xs_read(XenXenstoreState *s, unsigned int req_id,
         return;
     }
 
+    if (!len) {
+        return;
+    }
+
     memcpy(&rsp_data[rsp->len], data->data, len);
     rsp->len += len;
 }

---
base-commit: 38d0939b86e2eef6f6a622c6f1f7befda0146595
change-id: 20241227-xen-fb5a15cc0ca7

Best regards,
-- 
Akihiko Odaki <akihiko.odaki@daynix.com>



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] hw/xen: Check if len is 0 before memcpy()
  2025-01-08 11:31 [PATCH] hw/xen: Check if len is 0 before memcpy() Akihiko Odaki
@ 2025-01-08 11:42 ` Philippe Mathieu-Daudé
  2025-01-08 11:47 ` David Woodhouse
  1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-08 11:42 UTC (permalink / raw)
  To: Akihiko Odaki, David Woodhouse, Paul Durrant, Michael S. Tsirkin,
	Marcel Apfelbaum, Paolo Bonzini, Richard Henderson,
	Eduardo Habkost
  Cc: qemu-devel, devel

On 8/1/25 12:31, Akihiko Odaki wrote:
> data->data can be NULL when len is 0. Strictly speaking, the behavior
> of memcpy() in such a scenario is undefined so UBSan complaints.
> 
> Satisfy UBSan by checking if len is 0 before memcpy().
> 
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
> ---
>   hw/i386/kvm/xen_xenstore.c | 4 ++++
>   1 file changed, 4 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] hw/xen: Check if len is 0 before memcpy()
  2025-01-08 11:31 [PATCH] hw/xen: Check if len is 0 before memcpy() Akihiko Odaki
  2025-01-08 11:42 ` Philippe Mathieu-Daudé
@ 2025-01-08 11:47 ` David Woodhouse
  1 sibling, 0 replies; 3+ messages in thread
From: David Woodhouse @ 2025-01-08 11:47 UTC (permalink / raw)
  To: Akihiko Odaki, Paul Durrant, Michael S. Tsirkin, Marcel Apfelbaum,
	Paolo Bonzini, Richard Henderson, Eduardo Habkost
  Cc: qemu-devel, devel

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

On Wed, 2025-01-08 at 20:31 +0900, Akihiko Odaki wrote:
> data->data can be NULL when len is 0. Strictly speaking, the behavior
> of memcpy() in such a scenario is undefined so UBSan complaints.
> 
> Satisfy UBSan by checking if len is 0 before memcpy().
> 
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>

Reviewed-by: David Woodhouse <dwmw@amazon.co.uk>

Thanks.

> ---
>  hw/i386/kvm/xen_xenstore.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/hw/i386/kvm/xen_xenstore.c b/hw/i386/kvm/xen_xenstore.c
> index 59691056670e..17802aa33d20 100644
> --- a/hw/i386/kvm/xen_xenstore.c
> +++ b/hw/i386/kvm/xen_xenstore.c
> @@ -532,6 +532,10 @@ static void xs_read(XenXenstoreState *s,
> unsigned int req_id,
>          return;
>      }
>  
> +    if (!len) {
> +        return;
> +    }
> +
>      memcpy(&rsp_data[rsp->len], data->data, len);
>      rsp->len += len;
>  }
> 
> ---
> base-commit: 38d0939b86e2eef6f6a622c6f1f7befda0146595
> change-id: 20241227-xen-fb5a15cc0ca7
> 
> Best regards,


[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5069 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-01-08 11:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-08 11:31 [PATCH] hw/xen: Check if len is 0 before memcpy() Akihiko Odaki
2025-01-08 11:42 ` Philippe Mathieu-Daudé
2025-01-08 11:47 ` David Woodhouse

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).