devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of: overlay: validate offset from property fixups
@ 2018-05-17  4:19 frowand.list
  2018-05-17 16:56 ` Frank Rowand
  2018-05-23 16:44 ` Rob Herring
  0 siblings, 2 replies; 4+ messages in thread
From: frowand.list @ 2018-05-17  4:19 UTC (permalink / raw)
  To: Rob Herring, pantelis.antoniou, Pantelis Antoniou
  Cc: Dan Carpenter, devicetree, linux-kernel

From: Frank Rowand <frank.rowand@sony.com>

The smatch static checker marks the data in offset as untrusted,
leading it to warn:

  drivers/of/resolver.c:125 update_usages_of_a_phandle_reference()
  error: buffer underflow 'prop->value' 's32min-s32max'

Add check to verify that offset is within the property data.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Frank Rowand <frank.rowand@sony.com>
---
 drivers/of/resolver.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/of/resolver.c b/drivers/of/resolver.c
index 65d0b7adfcd4..7edfac6f1914 100644
--- a/drivers/of/resolver.c
+++ b/drivers/of/resolver.c
@@ -122,6 +122,11 @@ static int update_usages_of_a_phandle_reference(struct device_node *overlay,
 			goto err_fail;
 		}
 
+		if (offset < 0 || offset + sizeof(__be32) > prop->length) {
+			err = -EINVAL;
+			goto err_fail;
+		}
+
 		*(__be32 *)(prop->value + offset) = cpu_to_be32(phandle);
 	}
 
-- 
Frank Rowand <frank.rowand@sony.com>

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

* Re: [PATCH] of: overlay: validate offset from property fixups
  2018-05-17  4:19 [PATCH] of: overlay: validate offset from property fixups frowand.list
@ 2018-05-17 16:56 ` Frank Rowand
  2018-05-17 16:58   ` Frank Rowand
  2018-05-23 16:44 ` Rob Herring
  1 sibling, 1 reply; 4+ messages in thread
From: Frank Rowand @ 2018-05-17 16:56 UTC (permalink / raw)
  To: Rob Herring, pantelis.antoniou, Pantelis Antoniou
  Cc: Dan Carpenter, devicetree, linux-kernel

Hi Rob,

On 05/16/18 21:19, frowand.list@gmail.com wrote:
> From: Frank Rowand <frank.rowand@sony.com>
> 
> The smatch static checker marks the data in offset as untrusted,
> leading it to warn:
> 
>   drivers/of/resolver.c:125 update_usages_of_a_phandle_reference()
>   error: buffer underflow 'prop->value' 's32min-s32max'
> 
> Add check to verify that offset is within the property data.
> 
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Frank Rowand <frank.rowand@sony.com>
> ---
>  drivers/of/resolver.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/of/resolver.c b/drivers/of/resolver.c
> index 65d0b7adfcd4..7edfac6f1914 100644
> --- a/drivers/of/resolver.c
> +++ b/drivers/of/resolver.c
> @@ -122,6 +122,11 @@ static int update_usages_of_a_phandle_reference(struct device_node *overlay,
>  			goto err_fail;
>  		}
>  
> +		if (offset < 0 || offset + sizeof(__be32) > prop->length) {
> +			err = -EINVAL;
> +			goto err_fail;
> +		}
> +
>  		*(__be32 *)(prop->value + offset) = cpu_to_be32(phandle);
>  	}
>  
> 

I should have mentioned that this results in a new compile warning
for W=2 and W=3.  The new if statement results in:

drivers/of/resolver.c:125:45: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

There are other pre-existing warnings in the same file for comparing
an integer to prop->length.  The correct solution is probably to
change the type of the length field in struct property to be
unsigned.  I have added that task to my todo list.

-Frank

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

* Re: [PATCH] of: overlay: validate offset from property fixups
  2018-05-17 16:56 ` Frank Rowand
@ 2018-05-17 16:58   ` Frank Rowand
  0 siblings, 0 replies; 4+ messages in thread
From: Frank Rowand @ 2018-05-17 16:58 UTC (permalink / raw)
  To: Rob Herring, pantelis.antoniou, Pantelis Antoniou
  Cc: Dan Carpenter, devicetree, linux-kernel

On 05/17/18 09:56, Frank Rowand wrote:
> Hi Rob,
> 
> On 05/16/18 21:19, frowand.list@gmail.com wrote:
>> From: Frank Rowand <frank.rowand@sony.com>
>>
>> The smatch static checker marks the data in offset as untrusted,
>> leading it to warn:
>>
>>   drivers/of/resolver.c:125 update_usages_of_a_phandle_reference()
>>   error: buffer underflow 'prop->value' 's32min-s32max'
>>
>> Add check to verify that offset is within the property data.
>>
>> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
>> Signed-off-by: Frank Rowand <frank.rowand@sony.com>
>> ---
>>  drivers/of/resolver.c | 5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> diff --git a/drivers/of/resolver.c b/drivers/of/resolver.c
>> index 65d0b7adfcd4..7edfac6f1914 100644
>> --- a/drivers/of/resolver.c
>> +++ b/drivers/of/resolver.c
>> @@ -122,6 +122,11 @@ static int update_usages_of_a_phandle_reference(struct device_node *overlay,
>>  			goto err_fail;
>>  		}
>>  
>> +		if (offset < 0 || offset + sizeof(__be32) > prop->length) {
>> +			err = -EINVAL;
>> +			goto err_fail;
>> +		}
>> +
>>  		*(__be32 *)(prop->value + offset) = cpu_to_be32(phandle);
>>  	}
>>  
>>
> 
> I should have mentioned that this results in a new compile warning
> for W=2 and W=3.  The new if statement results in:
> 

W=2 warning is:

> drivers/of/resolver.c:125:45: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

W=3 warning is:

drivers/of/resolver.c:125:3: warning: conversion to 'unsigned int' from 'int' may change the sign of the result [-Wsign-conversion]

> 
> There are other pre-existing warnings in the same file for comparing
> an integer to prop->length.  The correct solution is probably to
> change the type of the length field in struct property to be
> unsigned.  I have added that task to my todo list.
> 
> -Frank
> 

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

* Re: [PATCH] of: overlay: validate offset from property fixups
  2018-05-17  4:19 [PATCH] of: overlay: validate offset from property fixups frowand.list
  2018-05-17 16:56 ` Frank Rowand
@ 2018-05-23 16:44 ` Rob Herring
  1 sibling, 0 replies; 4+ messages in thread
From: Rob Herring @ 2018-05-23 16:44 UTC (permalink / raw)
  To: frowand.list
  Cc: pantelis.antoniou, Pantelis Antoniou, Dan Carpenter, devicetree,
	linux-kernel

On Wed, May 16, 2018 at 09:19:51PM -0700, frowand.list@gmail.com wrote:
> From: Frank Rowand <frank.rowand@sony.com>
> 
> The smatch static checker marks the data in offset as untrusted,
> leading it to warn:
> 
>   drivers/of/resolver.c:125 update_usages_of_a_phandle_reference()
>   error: buffer underflow 'prop->value' 's32min-s32max'
> 
> Add check to verify that offset is within the property data.
> 
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Frank Rowand <frank.rowand@sony.com>
> ---
>  drivers/of/resolver.c | 5 +++++
>  1 file changed, 5 insertions(+)

Applied, thanks.

Rob

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

end of thread, other threads:[~2018-05-23 16:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-17  4:19 [PATCH] of: overlay: validate offset from property fixups frowand.list
2018-05-17 16:56 ` Frank Rowand
2018-05-17 16:58   ` Frank Rowand
2018-05-23 16:44 ` Rob Herring

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