netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nfc: nci: fix potential NULL pointer dereference
@ 2017-06-12 22:02 Gustavo A. R. Silva
  2017-06-12 22:21 ` Guenter Roeck
  0 siblings, 1 reply; 8+ messages in thread
From: Gustavo A. R. Silva @ 2017-06-12 22:02 UTC (permalink / raw)
  To: Samuel Ortiz, David S. Miller
  Cc: linux-wireless, netdev, linux-kernel, Gustavo A. R. Silva

NULL check at line 76: if (conn_info) {, implies that pointer conn_info
might be NULL, but this pointer is being previously dereferenced,
which might cause a NULL pointer dereference.

Add NULL check before dereferencing pointer conn_info in order to
avoid a potential NULL pointer dereference.

Addresses-Coverity-ID: 1362349
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
 net/nfc/nci/core.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
index 61fff42..d2198ce 100644
--- a/net/nfc/nci/core.c
+++ b/net/nfc/nci/core.c
@@ -70,14 +70,13 @@ int nci_get_conn_info_by_dest_type_params(struct nci_dev *ndev, u8 dest_type,
 	struct nci_conn_info *conn_info;
 
 	list_for_each_entry(conn_info, &ndev->conn_info_list, list) {
-		if (conn_info->dest_type == dest_type) {
+		if (conn_info && conn_info->dest_type == dest_type) {
 			if (!params)
 				return conn_info->conn_id;
-			if (conn_info) {
-				if (params->id == conn_info->dest_params->id &&
-				    params->protocol == conn_info->dest_params->protocol)
-					return conn_info->conn_id;
-			}
+
+			if (params->id == conn_info->dest_params->id &&
+			    params->protocol == conn_info->dest_params->protocol)
+				return conn_info->conn_id;
 		}
 	}
 
-- 
2.5.0

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

* Re: nfc: nci: fix potential NULL pointer dereference
  2017-06-12 22:02 [PATCH] nfc: nci: fix potential NULL pointer dereference Gustavo A. R. Silva
@ 2017-06-12 22:21 ` Guenter Roeck
  2017-06-12 22:28   ` Gustavo A. R. Silva
  0 siblings, 1 reply; 8+ messages in thread
From: Guenter Roeck @ 2017-06-12 22:21 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Samuel Ortiz, David S. Miller, linux-wireless, netdev,
	linux-kernel

On Mon, Jun 12, 2017 at 05:02:23PM -0500, Gustavo A. R. Silva wrote:
> NULL check at line 76: if (conn_info) {, implies that pointer conn_info
> might be NULL, but this pointer is being previously dereferenced,
> which might cause a NULL pointer dereference.
> 
> Add NULL check before dereferencing pointer conn_info in order to
> avoid a potential NULL pointer dereference.
> 
> Addresses-Coverity-ID: 1362349
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> ---
>  net/nfc/nci/core.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
> index 61fff42..d2198ce 100644
> --- a/net/nfc/nci/core.c
> +++ b/net/nfc/nci/core.c
> @@ -70,14 +70,13 @@ int nci_get_conn_info_by_dest_type_params(struct nci_dev *ndev, u8 dest_type,
>  	struct nci_conn_info *conn_info;
>  
>  	list_for_each_entry(conn_info, &ndev->conn_info_list, list) {

conn_info is set in list_for_each_entry() using container_of(),
which is never NULL. Plus, it is dereferenced there as well.
The check is unnecessary.

Guenter

> -		if (conn_info->dest_type == dest_type) {
> +		if (conn_info && conn_info->dest_type == dest_type) {
>  			if (!params)
>  				return conn_info->conn_id;
> -			if (conn_info) {
> -				if (params->id == conn_info->dest_params->id &&
> -				    params->protocol == conn_info->dest_params->protocol)
> -					return conn_info->conn_id;
> -			}
> +
> +			if (params->id == conn_info->dest_params->id &&
> +			    params->protocol == conn_info->dest_params->protocol)
> +				return conn_info->conn_id;
>  		}
>  	}
>  

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

* Re: nfc: nci: fix potential NULL pointer dereference
  2017-06-12 22:21 ` Guenter Roeck
@ 2017-06-12 22:28   ` Gustavo A. R. Silva
  2017-06-13  0:31     ` Guenter Roeck
  0 siblings, 1 reply; 8+ messages in thread
From: Gustavo A. R. Silva @ 2017-06-12 22:28 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Samuel Ortiz, David S. Miller, linux-wireless, netdev,
	linux-kernel

Hi Guenter,

Please, see my comments below

Quoting Guenter Roeck <linux@roeck-us.net>:

> On Mon, Jun 12, 2017 at 05:02:23PM -0500, Gustavo A. R. Silva wrote:
>> NULL check at line 76: if (conn_info) {, implies that pointer conn_info
>> might be NULL, but this pointer is being previously dereferenced,
>> which might cause a NULL pointer dereference.
>>
>> Add NULL check before dereferencing pointer conn_info in order to
>> avoid a potential NULL pointer dereference.
>>
>> Addresses-Coverity-ID: 1362349
>> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
>> ---
>>  net/nfc/nci/core.c | 11 +++++------
>>  1 file changed, 5 insertions(+), 6 deletions(-)
>>
>> diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
>> index 61fff42..d2198ce 100644
>> --- a/net/nfc/nci/core.c
>> +++ b/net/nfc/nci/core.c
>> @@ -70,14 +70,13 @@ int  
>> nci_get_conn_info_by_dest_type_params(struct nci_dev *ndev, u8  
>> dest_type,
>>  	struct nci_conn_info *conn_info;
>>
>>  	list_for_each_entry(conn_info, &ndev->conn_info_list, list) {
>
> conn_info is set in list_for_each_entry() using container_of(),
> which is never NULL. Plus, it is dereferenced there as well.
> The check is unnecessary.
>

Thanks for clarifying.

> Guenter
>
>> -		if (conn_info->dest_type == dest_type) {
>> +		if (conn_info && conn_info->dest_type == dest_type) {
>>  			if (!params)
>>  				return conn_info->conn_id;
>> -			if (conn_info) {

So, this NULL check could be removed as it seems it is not useful at all ?

>> -				if (params->id == conn_info->dest_params->id &&
>> -				    params->protocol == conn_info->dest_params->protocol)
>> -					return conn_info->conn_id;
>> -			}
>> +
>> +			if (params->id == conn_info->dest_params->id &&
>> +			    params->protocol == conn_info->dest_params->protocol)
>> +				return conn_info->conn_id;
>>  		}
>>  	}
>>

Thank you

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

* Re: nfc: nci: fix potential NULL pointer dereference
  2017-06-12 22:28   ` Gustavo A. R. Silva
@ 2017-06-13  0:31     ` Guenter Roeck
  2017-06-13 16:37       ` [PATCH] nfc: nci: remove unnecessary null check Gustavo A. R. Silva
  0 siblings, 1 reply; 8+ messages in thread
From: Guenter Roeck @ 2017-06-13  0:31 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Samuel Ortiz, David S. Miller, linux-wireless, netdev,
	linux-kernel

On 06/12/2017 03:28 PM, Gustavo A. R. Silva wrote:
> Hi Guenter,
> 
> Please, see my comments below
> 
> Quoting Guenter Roeck <linux@roeck-us.net>:
> 
>> On Mon, Jun 12, 2017 at 05:02:23PM -0500, Gustavo A. R. Silva wrote:
>>> NULL check at line 76: if (conn_info) {, implies that pointer conn_info
>>> might be NULL, but this pointer is being previously dereferenced,
>>> which might cause a NULL pointer dereference.
>>>
>>> Add NULL check before dereferencing pointer conn_info in order to
>>> avoid a potential NULL pointer dereference.
>>>
>>> Addresses-Coverity-ID: 1362349
>>> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
>>> ---
>>>  net/nfc/nci/core.c | 11 +++++------
>>>  1 file changed, 5 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
>>> index 61fff42..d2198ce 100644
>>> --- a/net/nfc/nci/core.c
>>> +++ b/net/nfc/nci/core.c
>>> @@ -70,14 +70,13 @@ int nci_get_conn_info_by_dest_type_params(struct nci_dev *ndev, u8 dest_type,
>>>      struct nci_conn_info *conn_info;
>>>
>>>      list_for_each_entry(conn_info, &ndev->conn_info_list, list) {
>>
>> conn_info is set in list_for_each_entry() using container_of(),
>> which is never NULL. Plus, it is dereferenced there as well.
>> The check is unnecessary.
>>
> 
> Thanks for clarifying.
> 
>> Guenter
>>
>>> -        if (conn_info->dest_type == dest_type) {
>>> +        if (conn_info && conn_info->dest_type == dest_type) {
>>>              if (!params)
>>>                  return conn_info->conn_id;
>>> -            if (conn_info) {
> 
> So, this NULL check could be removed as it seems it is not useful at all ?
> 
Exactly.

>>> -                if (params->id == conn_info->dest_params->id &&
>>> -                    params->protocol == conn_info->dest_params->protocol)
>>> -                    return conn_info->conn_id;
>>> -            }
>>> +
>>> +            if (params->id == conn_info->dest_params->id &&
>>> +                params->protocol == conn_info->dest_params->protocol)
>>> +                return conn_info->conn_id;
>>>          }
>>>      }
>>>
> 
> Thank you
> -- 
> Gustavo A. R. Silva
> 
> 
> 
> 
> 
> 
> 

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

* [PATCH] nfc: nci: remove unnecessary null check
  2017-06-13  0:31     ` Guenter Roeck
@ 2017-06-13 16:37       ` Gustavo A. R. Silva
  2017-06-15 17:29         ` Guenter Roeck
  2017-06-22 22:35         ` Samuel Ortiz
  0 siblings, 2 replies; 8+ messages in thread
From: Gustavo A. R. Silva @ 2017-06-13 16:37 UTC (permalink / raw)
  To: Samuel Ortiz, David S. Miller
  Cc: linux-wireless, netdev, linux-kernel, Gustavo A. R. Silva,
	Guenter Roeck

Remove unnecessary NULL check for pointer conn_info.
conn_info is set in list_for_each_entry() using container_of(),
which is never NULL.

Addresses-Coverity-ID: 1362349
Cc: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
 net/nfc/nci/core.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
index 61fff42..c15cb88 100644
--- a/net/nfc/nci/core.c
+++ b/net/nfc/nci/core.c
@@ -73,11 +73,10 @@ int nci_get_conn_info_by_dest_type_params(struct nci_dev *ndev, u8 dest_type,
 		if (conn_info->dest_type == dest_type) {
 			if (!params)
 				return conn_info->conn_id;
-			if (conn_info) {
-				if (params->id == conn_info->dest_params->id &&
-				    params->protocol == conn_info->dest_params->protocol)
-					return conn_info->conn_id;
-			}
+
+			if (params->id == conn_info->dest_params->id &&
+			    params->protocol == conn_info->dest_params->protocol)
+				return conn_info->conn_id;
 		}
 	}
 
-- 
2.5.0

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

* Re: [PATCH] nfc: nci: remove unnecessary null check
  2017-06-13 16:37       ` [PATCH] nfc: nci: remove unnecessary null check Gustavo A. R. Silva
@ 2017-06-15 17:29         ` Guenter Roeck
  2017-06-22 22:35         ` Samuel Ortiz
  1 sibling, 0 replies; 8+ messages in thread
From: Guenter Roeck @ 2017-06-15 17:29 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Samuel Ortiz, David S. Miller, linux-wireless, netdev,
	linux-kernel

On Tue, Jun 13, 2017 at 11:37:18AM -0500, Gustavo A. R. Silva wrote:
> Remove unnecessary NULL check for pointer conn_info.
> conn_info is set in list_for_each_entry() using container_of(),
> which is never NULL.
> 
> Addresses-Coverity-ID: 1362349
> Cc: Guenter Roeck <linux@roeck-us.net>
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  net/nfc/nci/core.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
> index 61fff42..c15cb88 100644
> --- a/net/nfc/nci/core.c
> +++ b/net/nfc/nci/core.c
> @@ -73,11 +73,10 @@ int nci_get_conn_info_by_dest_type_params(struct nci_dev *ndev, u8 dest_type,
>  		if (conn_info->dest_type == dest_type) {
>  			if (!params)
>  				return conn_info->conn_id;
> -			if (conn_info) {
> -				if (params->id == conn_info->dest_params->id &&
> -				    params->protocol == conn_info->dest_params->protocol)
> -					return conn_info->conn_id;
> -			}
> +
> +			if (params->id == conn_info->dest_params->id &&
> +			    params->protocol == conn_info->dest_params->protocol)
> +				return conn_info->conn_id;
>  		}
>  	}
>  
> -- 
> 2.5.0
> 

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

* Re: [PATCH] nfc: nci: remove unnecessary null check
  2017-06-13 16:37       ` [PATCH] nfc: nci: remove unnecessary null check Gustavo A. R. Silva
  2017-06-15 17:29         ` Guenter Roeck
@ 2017-06-22 22:35         ` Samuel Ortiz
  2017-06-23  1:25           ` Gustavo A. R. Silva
  1 sibling, 1 reply; 8+ messages in thread
From: Samuel Ortiz @ 2017-06-22 22:35 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: David S. Miller, linux-wireless-u79uwXL29TY76Z2rM5mHXA,
	netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Guenter Roeck

Hi Gustavo,

On Tue, Jun 13, 2017 at 11:37:18AM -0500, Gustavo A. R. Silva wrote:
> Remove unnecessary NULL check for pointer conn_info.
> conn_info is set in list_for_each_entry() using container_of(),
> which is never NULL.
> 
> Addresses-Coverity-ID: 1362349
> Cc: Guenter Roeck <linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
> Signed-off-by: Gustavo A. R. Silva <garsilva-L1vi/lXTdts+Va1GwOuvDg@public.gmane.org>
> ---
>  net/nfc/nci/core.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
Applied to nfc-next, thanks.

Cheers,
Samuel.

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

* Re: [PATCH] nfc: nci: remove unnecessary null check
  2017-06-22 22:35         ` Samuel Ortiz
@ 2017-06-23  1:25           ` Gustavo A. R. Silva
  0 siblings, 0 replies; 8+ messages in thread
From: Gustavo A. R. Silva @ 2017-06-23  1:25 UTC (permalink / raw)
  To: Samuel Ortiz
  Cc: David S. Miller, linux-wireless, netdev, linux-kernel,
	Guenter Roeck

Hi Samuel,

Quoting Samuel Ortiz <sameo@linux.intel.com>:

> Hi Gustavo,
>
> On Tue, Jun 13, 2017 at 11:37:18AM -0500, Gustavo A. R. Silva wrote:
>> Remove unnecessary NULL check for pointer conn_info.
>> conn_info is set in list_for_each_entry() using container_of(),
>> which is never NULL.
>>
>> Addresses-Coverity-ID: 1362349
>> Cc: Guenter Roeck <linux@roeck-us.net>
>> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
>> ---
>>  net/nfc/nci/core.c | 9 ++++-----
>>  1 file changed, 4 insertions(+), 5 deletions(-)
> Applied to nfc-next, thanks.
>

Absolutely, glad to help.

Thanks

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

end of thread, other threads:[~2017-06-23  1:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-12 22:02 [PATCH] nfc: nci: fix potential NULL pointer dereference Gustavo A. R. Silva
2017-06-12 22:21 ` Guenter Roeck
2017-06-12 22:28   ` Gustavo A. R. Silva
2017-06-13  0:31     ` Guenter Roeck
2017-06-13 16:37       ` [PATCH] nfc: nci: remove unnecessary null check Gustavo A. R. Silva
2017-06-15 17:29         ` Guenter Roeck
2017-06-22 22:35         ` Samuel Ortiz
2017-06-23  1:25           ` Gustavo A. R. Silva

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