All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/1] s390x/s390-virtio-ccw: fix off-by-one in loadparm getter
@ 2020-07-30 13:01 Halil Pasic
  2020-07-30 13:09 ` Peter Maydell
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Halil Pasic @ 2020-07-30 13:01 UTC (permalink / raw)
  To: Cornelia Huck, qemu-s390x, qemu-devel
  Cc: Peter Maydell, Thomas Huth, Daniel P. Berrangé,
	David Hildenbrand, Halil Pasic, Christian Borntraeger,
	Richard Henderson

As pointed out by Peter, g_memdup(ms->loadparm, sizeof(ms->loadparm) + 1)
reads one past of the end of ms->loadparm, so g_memdup() can not be used
here.

Let's use g_strndup instead!

Fixes: d664548328 ("s390x/s390-virtio-ccw: fix loadparm property getter")
Fixes: Coverity CID 1431058
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Halil Pasic <pasic@linux.ibm.com>
---
 hw/s390x/s390-virtio-ccw.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index 403d30e13b..e72c61d2ea 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -701,12 +701,9 @@ bool hpage_1m_allowed(void)
 static char *machine_get_loadparm(Object *obj, Error **errp)
 {
     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
-    char *loadparm_str;
 
     /* make a NUL-terminated string */
-    loadparm_str = g_memdup(ms->loadparm, sizeof(ms->loadparm) + 1);
-    loadparm_str[sizeof(ms->loadparm)] = 0;
-    return loadparm_str;
+    return g_strndup((char *) ms->loadparm, sizeof(ms->loadparm));
 }
 
 static void machine_set_loadparm(Object *obj, const char *val, Error **errp)

base-commit: 5772f2b1fc5d00e7e04e01fa28e9081d6550440a
-- 
2.17.1



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

* Re: [PATCH v2 1/1] s390x/s390-virtio-ccw: fix off-by-one in loadparm getter
  2020-07-30 13:01 [PATCH v2 1/1] s390x/s390-virtio-ccw: fix off-by-one in loadparm getter Halil Pasic
@ 2020-07-30 13:09 ` Peter Maydell
  2020-07-30 13:10 ` David Hildenbrand
  2020-07-30 15:06 ` Cornelia Huck
  2 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2020-07-30 13:09 UTC (permalink / raw)
  To: Halil Pasic
  Cc: Thomas Huth, Daniel P. Berrangé,
	David Hildenbrand, Cornelia Huck, QEMU Developers,
	Christian Borntraeger, qemu-s390x, Richard Henderson

On Thu, 30 Jul 2020 at 14:02, Halil Pasic <pasic@linux.ibm.com> wrote:
>
> As pointed out by Peter, g_memdup(ms->loadparm, sizeof(ms->loadparm) + 1)
> reads one past of the end of ms->loadparm, so g_memdup() can not be used
> here.
>
> Let's use g_strndup instead!
>
> Fixes: d664548328 ("s390x/s390-virtio-ccw: fix loadparm property getter")
> Fixes: Coverity CID 1431058
> Reported-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Halil Pasic <pasic@linux.ibm.com>
> ---
>  hw/s390x/s390-virtio-ccw.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
> index 403d30e13b..e72c61d2ea 100644
> --- a/hw/s390x/s390-virtio-ccw.c
> +++ b/hw/s390x/s390-virtio-ccw.c
> @@ -701,12 +701,9 @@ bool hpage_1m_allowed(void)
>  static char *machine_get_loadparm(Object *obj, Error **errp)
>  {
>      S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
> -    char *loadparm_str;
>
>      /* make a NUL-terminated string */
> -    loadparm_str = g_memdup(ms->loadparm, sizeof(ms->loadparm) + 1);
> -    loadparm_str[sizeof(ms->loadparm)] = 0;
> -    return loadparm_str;
> +    return g_strndup((char *) ms->loadparm, sizeof(ms->loadparm));
>  }

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


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

* Re: [PATCH v2 1/1] s390x/s390-virtio-ccw: fix off-by-one in loadparm getter
  2020-07-30 13:01 [PATCH v2 1/1] s390x/s390-virtio-ccw: fix off-by-one in loadparm getter Halil Pasic
  2020-07-30 13:09 ` Peter Maydell
@ 2020-07-30 13:10 ` David Hildenbrand
  2020-07-30 15:06 ` Cornelia Huck
  2 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand @ 2020-07-30 13:10 UTC (permalink / raw)
  To: Halil Pasic, Cornelia Huck, qemu-s390x, qemu-devel
  Cc: Peter Maydell, Christian Borntraeger, Thomas Huth,
	Daniel P. Berrangé,
	Richard Henderson

On 30.07.20 15:01, Halil Pasic wrote:
> As pointed out by Peter, g_memdup(ms->loadparm, sizeof(ms->loadparm) + 1)
> reads one past of the end of ms->loadparm, so g_memdup() can not be used
> here.
> 
> Let's use g_strndup instead!
> 
> Fixes: d664548328 ("s390x/s390-virtio-ccw: fix loadparm property getter")
> Fixes: Coverity CID 1431058
> Reported-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Halil Pasic <pasic@linux.ibm.com>
> ---
>  hw/s390x/s390-virtio-ccw.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
> index 403d30e13b..e72c61d2ea 100644
> --- a/hw/s390x/s390-virtio-ccw.c
> +++ b/hw/s390x/s390-virtio-ccw.c
> @@ -701,12 +701,9 @@ bool hpage_1m_allowed(void)
>  static char *machine_get_loadparm(Object *obj, Error **errp)
>  {
>      S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
> -    char *loadparm_str;
>  
>      /* make a NUL-terminated string */
> -    loadparm_str = g_memdup(ms->loadparm, sizeof(ms->loadparm) + 1);
> -    loadparm_str[sizeof(ms->loadparm)] = 0;
> -    return loadparm_str;
> +    return g_strndup((char *) ms->loadparm, sizeof(ms->loadparm));
>  }
>  
>  static void machine_set_loadparm(Object *obj, const char *val, Error **errp)
> 
> base-commit: 5772f2b1fc5d00e7e04e01fa28e9081d6550440a
> 

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Thanks,

David / dhildenb



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

* Re: [PATCH v2 1/1] s390x/s390-virtio-ccw: fix off-by-one in loadparm getter
  2020-07-30 13:01 [PATCH v2 1/1] s390x/s390-virtio-ccw: fix off-by-one in loadparm getter Halil Pasic
  2020-07-30 13:09 ` Peter Maydell
  2020-07-30 13:10 ` David Hildenbrand
@ 2020-07-30 15:06 ` Cornelia Huck
  2 siblings, 0 replies; 4+ messages in thread
From: Cornelia Huck @ 2020-07-30 15:06 UTC (permalink / raw)
  To: Halil Pasic
  Cc: Peter Maydell, Thomas Huth, Daniel P. Berrangé,
	David Hildenbrand, qemu-devel, Christian Borntraeger, qemu-s390x,
	Richard Henderson

On Thu, 30 Jul 2020 15:01:56 +0200
Halil Pasic <pasic@linux.ibm.com> wrote:

> As pointed out by Peter, g_memdup(ms->loadparm, sizeof(ms->loadparm) + 1)
> reads one past of the end of ms->loadparm, so g_memdup() can not be used
> here.
> 
> Let's use g_strndup instead!
> 
> Fixes: d664548328 ("s390x/s390-virtio-ccw: fix loadparm property getter")
> Fixes: Coverity CID 1431058
> Reported-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Halil Pasic <pasic@linux.ibm.com>
> ---
>  hw/s390x/s390-virtio-ccw.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)

Thanks, queued to s390-fixes.



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

end of thread, other threads:[~2020-07-30 15:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-30 13:01 [PATCH v2 1/1] s390x/s390-virtio-ccw: fix off-by-one in loadparm getter Halil Pasic
2020-07-30 13:09 ` Peter Maydell
2020-07-30 13:10 ` David Hildenbrand
2020-07-30 15:06 ` Cornelia Huck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.