Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1664263 > unrolled thread

[PATCH] nfc: nci: fix potential NULL pointer dereference

Started by"Gustavo A. R. Silva" <garsilva@embeddedor.com>
First post2017-06-13 00:10 +0200
Last post2017-06-15 19:30 +0200
Articles 6 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] nfc: nci: fix potential NULL pointer dereference "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-06-13 00:10 +0200
    Re: nfc: nci: fix potential NULL pointer dereference Guenter Roeck <linux@roeck-us.net> - 2017-06-13 00:30 +0200
      Re: nfc: nci: fix potential NULL pointer dereference "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-06-13 01:00 +0200
        Re: nfc: nci: fix potential NULL pointer dereference Guenter Roeck <linux@roeck-us.net> - 2017-06-13 02:40 +0200
          [PATCH] nfc: nci: remove unnecessary null check "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-06-13 18:40 +0200
            Re: [PATCH] nfc: nci: remove unnecessary null check Guenter Roeck <linux@roeck-us.net> - 2017-06-15 19:30 +0200

#1664263 — [PATCH] nfc: nci: fix potential NULL pointer dereference

From"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Date2017-06-13 00:10 +0200
Subject[PATCH] nfc: nci: fix potential NULL pointer dereference
Message-ID<tRFH3-800-15@gated-at.bofh.it>
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

[toc] | [next] | [standalone]


#1664276 — Re: nfc: nci: fix potential NULL pointer dereference

FromGuenter Roeck <linux@roeck-us.net>
Date2017-06-13 00:30 +0200
SubjectRe: nfc: nci: fix potential NULL pointer dereference
Message-ID<tRG0p-86G-9@gated-at.bofh.it>
In reply to#1664263
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;
>  		}
>  	}
>  

[toc] | [prev] | [next] | [standalone]


#1664288 — Re: nfc: nci: fix potential NULL pointer dereference

From"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Date2017-06-13 01:00 +0200
SubjectRe: nfc: nci: fix potential NULL pointer dereference
Message-ID<tRGts-8hX-15@gated-at.bofh.it>
In reply to#1664276
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
--
Gustavo A. R. Silva

[toc] | [prev] | [next] | [standalone]


#1664319 — Re: nfc: nci: fix potential NULL pointer dereference

FromGuenter Roeck <linux@roeck-us.net>
Date2017-06-13 02:40 +0200
SubjectRe: nfc: nci: fix potential NULL pointer dereference
Message-ID<tRI2e-Sj-9@gated-at.bofh.it>
In reply to#1664288
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
> 
> 
> 
> 
> 
> 
> 

[toc] | [prev] | [next] | [standalone]


#1665009 — [PATCH] nfc: nci: remove unnecessary null check

From"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Date2017-06-13 18:40 +0200
Subject[PATCH] nfc: nci: remove unnecessary null check
Message-ID<tRX1g-1PX-17@gated-at.bofh.it>
In reply to#1664319
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

[toc] | [prev] | [next] | [standalone]


#1666918 — Re: [PATCH] nfc: nci: remove unnecessary null check

FromGuenter Roeck <linux@roeck-us.net>
Date2017-06-15 19:30 +0200
SubjectRe: [PATCH] nfc: nci: remove unnecessary null check
Message-ID<tSGKK-5iA-5@gated-at.bofh.it>
In reply to#1665009
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
> 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web