[libvirt] [PATCH 1/5] virDomainNumaGetNodeDistance: Fix input arguments validation

Michal Privoznik posted 5 patches 7 years, 6 months ago
There is a newer version of this series
[libvirt] [PATCH 1/5] virDomainNumaGetNodeDistance: Fix input arguments validation
Posted by Michal Privoznik 7 years, 6 months ago
There's no point in checking if numa->mem_nodes[node].ndistances
is set if we check for numa->mem_nodes[node].distances. However,
it makes sense to check if the sibling node caller passed falls
within boundaries.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/conf/numa_conf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c
index 7bba4120b..5f0b3f9ed 100644
--- a/src/conf/numa_conf.c
+++ b/src/conf/numa_conf.c
@@ -1154,7 +1154,7 @@ virDomainNumaGetNodeDistance(virDomainNumaPtr numa,
      */
     if (!distances ||
         !distances[cellid].value ||
-        !numa->mem_nodes[node].ndistances)
+        node >= numa->nmem_nodes)
         return (node == cellid) ? LOCAL_DISTANCE : REMOTE_DISTANCE;
 
     return distances[cellid].value;
-- 
2.13.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/5] virDomainNumaGetNodeDistance: Fix input arguments validation
Posted by John Ferlan 7 years, 5 months ago

On 11/14/2017 09:47 AM, Michal Privoznik wrote:
> There's no point in checking if numa->mem_nodes[node].ndistances
> is set if we check for numa->mem_nodes[node].distances. However,
> it makes sense to check if the sibling node caller passed falls
> within boundaries.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/conf/numa_conf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c
> index 7bba4120b..5f0b3f9ed 100644
> --- a/src/conf/numa_conf.c
> +++ b/src/conf/numa_conf.c
> @@ -1154,7 +1154,7 @@ virDomainNumaGetNodeDistance(virDomainNumaPtr numa,
>       */
>      if (!distances ||
>          !distances[cellid].value ||
> -        !numa->mem_nodes[node].ndistances)
> +        node >= numa->nmem_nodes)

If @distances can only be set if "node < numa->nmem_nodes", then how
could "node >= numa->nmem_nodes" ever be true and @distances be non
NULL?  IOW: I see no need for the check... This former condition also
trips across my "favorite" condition check of "if !intValue"
substituting for "if intValue == 0" <sigh>.

BTW: I do think there is a memory leak @distances entries are not
VIR_FREE'd in virDomainNumaFree. I was looking for instances where
ndistances maybe have been forgotten to be set to 0 even though
distances was cleared.  I can send a patch or you can for that if you
want - IDC...  There's a couple of other cleanups I'd like to see w/r/t
using (!*ndistances) and how the @*distance are set to ldist/rdist
outside of the if condition that allocated, but those are type A type
things ;-)

John

>          return (node == cellid) ? LOCAL_DISTANCE : REMOTE_DISTANCE;
>  
>      return distances[cellid].value;
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/5] virDomainNumaGetNodeDistance: Fix input arguments validation
Posted by Michal Privoznik 7 years, 5 months ago
On 11/22/2017 12:22 AM, John Ferlan wrote:
> 
> 
> On 11/14/2017 09:47 AM, Michal Privoznik wrote:
>> There's no point in checking if numa->mem_nodes[node].ndistances
>> is set if we check for numa->mem_nodes[node].distances. However,
>> it makes sense to check if the sibling node caller passed falls
>> within boundaries.
>>
>> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>> ---
>>  src/conf/numa_conf.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c
>> index 7bba4120b..5f0b3f9ed 100644
>> --- a/src/conf/numa_conf.c
>> +++ b/src/conf/numa_conf.c
>> @@ -1154,7 +1154,7 @@ virDomainNumaGetNodeDistance(virDomainNumaPtr numa,
>>       */
>>      if (!distances ||
>>          !distances[cellid].value ||
>> -        !numa->mem_nodes[node].ndistances)
>> +        node >= numa->nmem_nodes)
> 
> If @distances can only be set if "node < numa->nmem_nodes", then how
> could "node >= numa->nmem_nodes" ever be true and @distances be non
> NULL?  IOW: I see no need for the check... This former condition also
> trips across my "favorite" condition check of "if !intValue"
> substituting for "if intValue == 0" <sigh>.

Ah right. This patch makes no sense. I don't even know what was I
thinking :-)

But now as I'm looking at the code, it might be worth to check if
@cellid < numa->nmem_nodes; We check @node but not @cellid.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/5] virDomainNumaGetNodeDistance: Fix input arguments validation
Posted by John Ferlan 7 years, 5 months ago

On 11/22/2017 04:45 AM, Michal Privoznik wrote:
> On 11/22/2017 12:22 AM, John Ferlan wrote:
>>
>>
>> On 11/14/2017 09:47 AM, Michal Privoznik wrote:
>>> There's no point in checking if numa->mem_nodes[node].ndistances
>>> is set if we check for numa->mem_nodes[node].distances. However,
>>> it makes sense to check if the sibling node caller passed falls
>>> within boundaries.
>>>
>>> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>>> ---
>>>  src/conf/numa_conf.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c
>>> index 7bba4120b..5f0b3f9ed 100644
>>> --- a/src/conf/numa_conf.c
>>> +++ b/src/conf/numa_conf.c
>>> @@ -1154,7 +1154,7 @@ virDomainNumaGetNodeDistance(virDomainNumaPtr numa,
>>>       */
>>>      if (!distances ||
>>>          !distances[cellid].value ||
>>> -        !numa->mem_nodes[node].ndistances)
>>> +        node >= numa->nmem_nodes)
>>
>> If @distances can only be set if "node < numa->nmem_nodes", then how
>> could "node >= numa->nmem_nodes" ever be true and @distances be non
>> NULL?  IOW: I see no need for the check... This former condition also
>> trips across my "favorite" condition check of "if !intValue"
>> substituting for "if intValue == 0" <sigh>.
> 
> Ah right. This patch makes no sense. I don't even know what was I
> thinking :-)
> 
> But now as I'm looking at the code, it might be worth to check if
> @cellid < numa->nmem_nodes; We check @node but not @cellid.

True, probably before we use it in distances too!  So flip/flop the
check and s/node/cellid/

John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list