All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] qom: code hardening - have bound checking while looping with integer value
@ 2020-09-21  9:33 Ani Sinha
  2020-10-12 14:38 ` Ani Sinha
  2020-10-15 16:52 ` Eduardo Habkost
  0 siblings, 2 replies; 8+ messages in thread
From: Ani Sinha @ 2020-09-21  9:33 UTC (permalink / raw)
  To: qemu-devel
  Cc: Ani Sinha, Paolo Bonzini, Daniel P. Berrangé, Eduardo Habkost

Object property insertion code iterates over an integer to get an unused
index that can be used as an unique name for an object property. This loop
increments the integer value indefinitely. Although very unlikely, this can
still cause an integer overflow.
In this change, we fix the above code by checking against INT16_MAX and making
sure that the interger index does not overflow beyond that value. If no
available index is found, the code would cause an assertion failure. This
assertion failure is necessary because the callers of the function do not check
the return value for NULL.

Signed-off-by: Ani Sinha <ani@anisinha.ca>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
---
 qom/object.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

changelog:
v1: initial version
v2: change INT_MAX to INT16_MAX in code
v3: make the same change in commit log. Sorry for missing it.

diff --git a/qom/object.c b/qom/object.c
index 387efb25eb..9962874598 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1166,11 +1166,11 @@ object_property_try_add(Object *obj, const char *name, const char *type,
 
     if (name_len >= 3 && !memcmp(name + name_len - 3, "[*]", 4)) {
         int i;
-        ObjectProperty *ret;
+        ObjectProperty *ret = NULL;
         char *name_no_array = g_strdup(name);
 
         name_no_array[name_len - 3] = '\0';
-        for (i = 0; ; ++i) {
+        for (i = 0; i < INT16_MAX; ++i) {
             char *full_name = g_strdup_printf("%s[%d]", name_no_array, i);
 
             ret = object_property_try_add(obj, full_name, type, get, set,
@@ -1181,6 +1181,7 @@ object_property_try_add(Object *obj, const char *name, const char *type,
             }
         }
         g_free(name_no_array);
+        assert(ret);
         return ret;
     }
 
-- 
2.17.1



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

* Re: [PATCH v3] qom: code hardening - have bound checking while looping with integer value
  2020-09-21  9:33 [PATCH v3] qom: code hardening - have bound checking while looping with integer value Ani Sinha
@ 2020-10-12 14:38 ` Ani Sinha
  2020-10-15 14:53   ` Ani Sinha
  2020-10-15 16:52 ` Eduardo Habkost
  1 sibling, 1 reply; 8+ messages in thread
From: Ani Sinha @ 2020-10-12 14:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Daniel P. Berrangé, Eduardo Habkost

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

Request to queue this patch for the next pull.

On Mon, Sep 21, 2020 at 15:03 Ani Sinha <ani@anisinha.ca> wrote:

> Object property insertion code iterates over an integer to get an unused
> index that can be used as an unique name for an object property. This loop
> increments the integer value indefinitely. Although very unlikely, this can
> still cause an integer overflow.
> In this change, we fix the above code by checking against INT16_MAX and
> making
> sure that the interger index does not overflow beyond that value. If no
> available index is found, the code would cause an assertion failure. This
> assertion failure is necessary because the callers of the function do not
> check
> the return value for NULL.
>
> Signed-off-by: Ani Sinha <ani@anisinha.ca>
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  qom/object.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> changelog:
> v1: initial version
> v2: change INT_MAX to INT16_MAX in code
> v3: make the same change in commit log. Sorry for missing it.
>
> diff --git a/qom/object.c b/qom/object.c
> index 387efb25eb..9962874598 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -1166,11 +1166,11 @@ object_property_try_add(Object *obj, const char
> *name, const char *type,
>
>      if (name_len >= 3 && !memcmp(name + name_len - 3, "[*]", 4)) {
>          int i;
> -        ObjectProperty *ret;
> +        ObjectProperty *ret = NULL;
>          char *name_no_array = g_strdup(name);
>
>          name_no_array[name_len - 3] = '\0';
> -        for (i = 0; ; ++i) {
> +        for (i = 0; i < INT16_MAX; ++i) {
>              char *full_name = g_strdup_printf("%s[%d]", name_no_array, i);
>
>              ret = object_property_try_add(obj, full_name, type, get, set,
> @@ -1181,6 +1181,7 @@ object_property_try_add(Object *obj, const char
> *name, const char *type,
>              }
>          }
>          g_free(name_no_array);
> +        assert(ret);
>          return ret;
>      }
>
> --
> 2.17.1
>
>

[-- Attachment #2: Type: text/html, Size: 2734 bytes --]

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

* Re: [PATCH v3] qom: code hardening - have bound checking while looping with integer value
  2020-10-12 14:38 ` Ani Sinha
@ 2020-10-15 14:53   ` Ani Sinha
  0 siblings, 0 replies; 8+ messages in thread
From: Ani Sinha @ 2020-10-15 14:53 UTC (permalink / raw)
  To: QEMU Developers; +Cc: Paolo Bonzini, Daniel P. Berrangé, Eduardo Habkost

Ping ...

On Mon, Oct 12, 2020 at 8:08 PM Ani Sinha <ani@anisinha.ca> wrote:
>
> Request to queue this patch for the next pull.
>
> On Mon, Sep 21, 2020 at 15:03 Ani Sinha <ani@anisinha.ca> wrote:
>>
>> Object property insertion code iterates over an integer to get an unused
>> index that can be used as an unique name for an object property. This loop
>> increments the integer value indefinitely. Although very unlikely, this can
>> still cause an integer overflow.
>> In this change, we fix the above code by checking against INT16_MAX and making
>> sure that the interger index does not overflow beyond that value. If no
>> available index is found, the code would cause an assertion failure. This
>> assertion failure is necessary because the callers of the function do not check
>> the return value for NULL.
>>
>> Signed-off-by: Ani Sinha <ani@anisinha.ca>
>> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
>> ---
>>  qom/object.c | 5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> changelog:
>> v1: initial version
>> v2: change INT_MAX to INT16_MAX in code
>> v3: make the same change in commit log. Sorry for missing it.
>>
>> diff --git a/qom/object.c b/qom/object.c
>> index 387efb25eb..9962874598 100644
>> --- a/qom/object.c
>> +++ b/qom/object.c
>> @@ -1166,11 +1166,11 @@ object_property_try_add(Object *obj, const char *name, const char *type,
>>
>>      if (name_len >= 3 && !memcmp(name + name_len - 3, "[*]", 4)) {
>>          int i;
>> -        ObjectProperty *ret;
>> +        ObjectProperty *ret = NULL;
>>          char *name_no_array = g_strdup(name);
>>
>>          name_no_array[name_len - 3] = '\0';
>> -        for (i = 0; ; ++i) {
>> +        for (i = 0; i < INT16_MAX; ++i) {
>>              char *full_name = g_strdup_printf("%s[%d]", name_no_array, i);
>>
>>              ret = object_property_try_add(obj, full_name, type, get, set,
>> @@ -1181,6 +1181,7 @@ object_property_try_add(Object *obj, const char *name, const char *type,
>>              }
>>          }
>>          g_free(name_no_array);
>> +        assert(ret);
>>          return ret;
>>      }
>>
>> --
>> 2.17.1
>>


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

* Re: [PATCH v3] qom: code hardening - have bound checking while looping with integer value
  2020-09-21  9:33 [PATCH v3] qom: code hardening - have bound checking while looping with integer value Ani Sinha
  2020-10-12 14:38 ` Ani Sinha
@ 2020-10-15 16:52 ` Eduardo Habkost
  2020-10-31 16:21   ` Ani Sinha
  1 sibling, 1 reply; 8+ messages in thread
From: Eduardo Habkost @ 2020-10-15 16:52 UTC (permalink / raw)
  To: Ani Sinha; +Cc: Paolo Bonzini, Daniel P. Berrangé, qemu-devel

On Mon, Sep 21, 2020 at 03:03:25PM +0530, Ani Sinha wrote:
> Object property insertion code iterates over an integer to get an unused
> index that can be used as an unique name for an object property. This loop
> increments the integer value indefinitely. Although very unlikely, this can
> still cause an integer overflow.
> In this change, we fix the above code by checking against INT16_MAX and making
> sure that the interger index does not overflow beyond that value. If no
> available index is found, the code would cause an assertion failure. This
> assertion failure is necessary because the callers of the function do not check
> the return value for NULL.
> 
> Signed-off-by: Ani Sinha <ani@anisinha.ca>
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Queued on machine-next, thanks!  My apologies for the delay.

-- 
Eduardo



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

* Re: [PATCH v3] qom: code hardening - have bound checking while looping with integer value
  2020-10-15 16:52 ` Eduardo Habkost
@ 2020-10-31 16:21   ` Ani Sinha
  2020-11-04 15:53     ` Ani Sinha
  2020-11-04 15:59     ` Eduardo Habkost
  0 siblings, 2 replies; 8+ messages in thread
From: Ani Sinha @ 2020-10-31 16:21 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: Paolo Bonzini, Daniel P. Berrangé, QEMU Developers

On Thu, Oct 15, 2020 at 10:22 PM Eduardo Habkost <ehabkost@redhat.com> wrote:
>
> On Mon, Sep 21, 2020 at 03:03:25PM +0530, Ani Sinha wrote:
> > Object property insertion code iterates over an integer to get an unused
> > index that can be used as an unique name for an object property. This loop
> > increments the integer value indefinitely. Although very unlikely, this can
> > still cause an integer overflow.
> > In this change, we fix the above code by checking against INT16_MAX and making
> > sure that the interger index does not overflow beyond that value. If no
> > available index is found, the code would cause an assertion failure. This
> > assertion failure is necessary because the callers of the function do not check
> > the return value for NULL.
> >
> > Signed-off-by: Ani Sinha <ani@anisinha.ca>
> > Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
>
> Queued on machine-next, thanks!  My apologies for the delay.

Any idea when this will be pulled?


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

* Re: [PATCH v3] qom: code hardening - have bound checking while looping with integer value
  2020-10-31 16:21   ` Ani Sinha
@ 2020-11-04 15:53     ` Ani Sinha
  2020-11-04 15:59     ` Eduardo Habkost
  1 sibling, 0 replies; 8+ messages in thread
From: Ani Sinha @ 2020-11-04 15:53 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: Paolo Bonzini, Daniel P. Berrangé, QEMU Developers

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

Ping ...

On Sat, Oct 31, 2020 at 9:51 PM Ani Sinha <ani@anisinha.ca> wrote:

> On Thu, Oct 15, 2020 at 10:22 PM Eduardo Habkost <ehabkost@redhat.com>
> wrote:
> >
> > On Mon, Sep 21, 2020 at 03:03:25PM +0530, Ani Sinha wrote:
> > > Object property insertion code iterates over an integer to get an
> unused
> > > index that can be used as an unique name for an object property. This
> loop
> > > increments the integer value indefinitely. Although very unlikely,
> this can
> > > still cause an integer overflow.
> > > In this change, we fix the above code by checking against INT16_MAX
> and making
> > > sure that the interger index does not overflow beyond that value. If no
> > > available index is found, the code would cause an assertion failure.
> This
> > > assertion failure is necessary because the callers of the function do
> not check
> > > the return value for NULL.
> > >
> > > Signed-off-by: Ani Sinha <ani@anisinha.ca>
> > > Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> >
> > Queued on machine-next, thanks!  My apologies for the delay.
>
> Any idea when this will be pulled?
>

[-- Attachment #2: Type: text/html, Size: 1749 bytes --]

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

* Re: [PATCH v3] qom: code hardening - have bound checking while looping with integer value
  2020-10-31 16:21   ` Ani Sinha
  2020-11-04 15:53     ` Ani Sinha
@ 2020-11-04 15:59     ` Eduardo Habkost
  2020-12-09  4:33       ` Ani Sinha
  1 sibling, 1 reply; 8+ messages in thread
From: Eduardo Habkost @ 2020-11-04 15:59 UTC (permalink / raw)
  To: Ani Sinha; +Cc: Paolo Bonzini, Daniel P. Berrangé, QEMU Developers

On Sat, Oct 31, 2020 at 09:51:38PM +0530, Ani Sinha wrote:
> On Thu, Oct 15, 2020 at 10:22 PM Eduardo Habkost <ehabkost@redhat.com> wrote:
> >
> > On Mon, Sep 21, 2020 at 03:03:25PM +0530, Ani Sinha wrote:
> > > Object property insertion code iterates over an integer to get an unused
> > > index that can be used as an unique name for an object property. This loop
> > > increments the integer value indefinitely. Although very unlikely, this can
> > > still cause an integer overflow.
> > > In this change, we fix the above code by checking against INT16_MAX and making
> > > sure that the interger index does not overflow beyond that value. If no
> > > available index is found, the code would cause an assertion failure. This
> > > assertion failure is necessary because the callers of the function do not check
> > > the return value for NULL.
> > >
> > > Signed-off-by: Ani Sinha <ani@anisinha.ca>
> > > Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> >
> > Queued on machine-next, thanks!  My apologies for the delay.
> 
> Any idea when this will be pulled?

I was planning to send a pull request before soft freeze,
(October 27) but this was the only patch in the queue at that
moment, so I decided to wait.

As we're beyond freeze now, the pull request will be sent
immediately after 5.2.0 is released.

-- 
Eduardo



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

* Re: [PATCH v3] qom: code hardening - have bound checking while looping with integer value
  2020-11-04 15:59     ` Eduardo Habkost
@ 2020-12-09  4:33       ` Ani Sinha
  0 siblings, 0 replies; 8+ messages in thread
From: Ani Sinha @ 2020-12-09  4:33 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: Paolo Bonzini, Daniel P. Berrangé, QEMU Developers

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

On Wed, Nov 4, 2020 at 21:29 Eduardo Habkost <ehabkost@redhat.com> wrote:

> On Sat, Oct 31, 2020 at 09:51:38PM +0530, Ani Sinha wrote:
> > On Thu, Oct 15, 2020 at 10:22 PM Eduardo Habkost <ehabkost@redhat.com>
> wrote:
> > >
> > > On Mon, Sep 21, 2020 at 03:03:25PM +0530, Ani Sinha wrote:
> > > > Object property insertion code iterates over an integer to get an
> unused
> > > > index that can be used as an unique name for an object property.
> This loop
> > > > increments the integer value indefinitely. Although very unlikely,
> this can
> > > > still cause an integer overflow.
> > > > In this change, we fix the above code by checking against INT16_MAX
> and making
> > > > sure that the interger index does not overflow beyond that value. If
> no
> > > > available index is found, the code would cause an assertion failure.
> This
> > > > assertion failure is necessary because the callers of the function
> do not check
> > > > the return value for NULL.
> > > >
> > > > Signed-off-by: Ani Sinha <ani@anisinha.ca>
> > > > Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> > >
> > > Queued on machine-next, thanks!  My apologies for the delay.
> >
> > Any idea when this will be pulled?
>
> I was planning to send a pull request before soft freeze,
> (October 27) but this was the only patch in the queue at that
> moment, so I decided to wait.
>
> As we're beyond freeze now, the pull request will be sent
> immediately after 5.2.0 is released.


Gentle reminder since 5.2.0 has now been released.


>
>

[-- Attachment #2: Type: text/html, Size: 2385 bytes --]

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

end of thread, other threads:[~2020-12-09  4:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-21  9:33 [PATCH v3] qom: code hardening - have bound checking while looping with integer value Ani Sinha
2020-10-12 14:38 ` Ani Sinha
2020-10-15 14:53   ` Ani Sinha
2020-10-15 16:52 ` Eduardo Habkost
2020-10-31 16:21   ` Ani Sinha
2020-11-04 15:53     ` Ani Sinha
2020-11-04 15:59     ` Eduardo Habkost
2020-12-09  4:33       ` Ani Sinha

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.