All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] e1000: avoid null pointer dereference on invalid stat type
@ 2017-09-21 22:01 ` Colin King
  0 siblings, 0 replies; 8+ messages in thread
From: Colin King @ 2017-09-21 22:01 UTC (permalink / raw)
  To: Jeff Kirsher, intel-wired-lan, netdev; +Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently if the stat type is invalid then data[i] is being set
either by dereferencing a null pointer p, or it is reading from
an incorrect previous location if we had a valid stat type
previously.  Fix this by nullify pointer p if a stat type is
invalid and only setting data if p is not null.

Detected by CoverityScan, CID#113385 ("Explicit null dereferenced")

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/net/ethernet/intel/e1000/e1000_ethtool.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/intel/e1000/e1000_ethtool.c b/drivers/net/ethernet/intel/e1000/e1000_ethtool.c
index ec8aa4562cc9..2ef6f08b580b 100644
--- a/drivers/net/ethernet/intel/e1000/e1000_ethtool.c
+++ b/drivers/net/ethernet/intel/e1000/e1000_ethtool.c
@@ -1824,11 +1824,12 @@ static void e1000_get_ethtool_stats(struct net_device *netdev,
 {
 	struct e1000_adapter *adapter = netdev_priv(netdev);
 	int i;
-	char *p = NULL;
 	const struct e1000_stats *stat = e1000_gstrings_stats;
 
 	e1000_update_stats(adapter);
 	for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
+		char *p;
+
 		switch (stat->type) {
 		case NETDEV_STATS:
 			p = (char *)netdev + stat->stat_offset;
@@ -1837,12 +1838,13 @@ static void e1000_get_ethtool_stats(struct net_device *netdev,
 			p = (char *)adapter + stat->stat_offset;
 			break;
 		default:
+			p = NULL;
 			WARN_ONCE(1, "Invalid E1000 stat type: %u index %d\n",
 				  stat->type, i);
 			break;
 		}
 
-		if (stat->sizeof_stat = sizeof(u64))
+		if (p && stat->sizeof_stat = sizeof(u64))
 			data[i] = *(u64 *)p;
 		else
 			data[i] = *(u32 *)p;
-- 
2.14.1


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

* [PATCH] e1000: avoid null pointer dereference on invalid stat type
@ 2017-09-21 22:01 ` Colin King
  0 siblings, 0 replies; 8+ messages in thread
From: Colin King @ 2017-09-21 22:01 UTC (permalink / raw)
  To: Jeff Kirsher, intel-wired-lan, netdev; +Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently if the stat type is invalid then data[i] is being set
either by dereferencing a null pointer p, or it is reading from
an incorrect previous location if we had a valid stat type
previously.  Fix this by nullify pointer p if a stat type is
invalid and only setting data if p is not null.

Detected by CoverityScan, CID#113385 ("Explicit null dereferenced")

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/net/ethernet/intel/e1000/e1000_ethtool.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/intel/e1000/e1000_ethtool.c b/drivers/net/ethernet/intel/e1000/e1000_ethtool.c
index ec8aa4562cc9..2ef6f08b580b 100644
--- a/drivers/net/ethernet/intel/e1000/e1000_ethtool.c
+++ b/drivers/net/ethernet/intel/e1000/e1000_ethtool.c
@@ -1824,11 +1824,12 @@ static void e1000_get_ethtool_stats(struct net_device *netdev,
 {
 	struct e1000_adapter *adapter = netdev_priv(netdev);
 	int i;
-	char *p = NULL;
 	const struct e1000_stats *stat = e1000_gstrings_stats;
 
 	e1000_update_stats(adapter);
 	for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
+		char *p;
+
 		switch (stat->type) {
 		case NETDEV_STATS:
 			p = (char *)netdev + stat->stat_offset;
@@ -1837,12 +1838,13 @@ static void e1000_get_ethtool_stats(struct net_device *netdev,
 			p = (char *)adapter + stat->stat_offset;
 			break;
 		default:
+			p = NULL;
 			WARN_ONCE(1, "Invalid E1000 stat type: %u index %d\n",
 				  stat->type, i);
 			break;
 		}
 
-		if (stat->sizeof_stat == sizeof(u64))
+		if (p && stat->sizeof_stat == sizeof(u64))
 			data[i] = *(u64 *)p;
 		else
 			data[i] = *(u32 *)p;
-- 
2.14.1

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

* Re: [PATCH] e1000: avoid null pointer dereference on invalid stat type
  2017-09-21 22:01 ` Colin King
@ 2017-09-22 11:50   ` Dan Carpenter
  -1 siblings, 0 replies; 8+ messages in thread
From: Dan Carpenter @ 2017-09-22 11:50 UTC (permalink / raw)
  To: Colin King
  Cc: Jeff Kirsher, intel-wired-lan, netdev, kernel-janitors,
	linux-kernel

On Thu, Sep 21, 2017 at 11:01:58PM +0100, Colin King wrote:
> @@ -1837,12 +1838,13 @@ static void e1000_get_ethtool_stats(struct net_device *netdev,
>  			p = (char *)adapter + stat->stat_offset;
>  			break;
>  		default:
> +			p = NULL;
>  			WARN_ONCE(1, "Invalid E1000 stat type: %u index %d\n",
>  				  stat->type, i);
>  			break;
>  		}
>  
> -		if (stat->sizeof_stat = sizeof(u64))
> +		if (p && stat->sizeof_stat = sizeof(u64))
>  			data[i] = *(u64 *)p;
>  		else
>  			data[i] = *(u32 *)p;
                                   ^^^^^^^^

The else side will still crash.

regards,
dan carpenter


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

* Re: [PATCH] e1000: avoid null pointer dereference on invalid stat type
@ 2017-09-22 11:50   ` Dan Carpenter
  0 siblings, 0 replies; 8+ messages in thread
From: Dan Carpenter @ 2017-09-22 11:50 UTC (permalink / raw)
  To: Colin King
  Cc: Jeff Kirsher, intel-wired-lan, netdev, kernel-janitors,
	linux-kernel

On Thu, Sep 21, 2017 at 11:01:58PM +0100, Colin King wrote:
> @@ -1837,12 +1838,13 @@ static void e1000_get_ethtool_stats(struct net_device *netdev,
>  			p = (char *)adapter + stat->stat_offset;
>  			break;
>  		default:
> +			p = NULL;
>  			WARN_ONCE(1, "Invalid E1000 stat type: %u index %d\n",
>  				  stat->type, i);
>  			break;
>  		}
>  
> -		if (stat->sizeof_stat == sizeof(u64))
> +		if (p && stat->sizeof_stat == sizeof(u64))
>  			data[i] = *(u64 *)p;
>  		else
>  			data[i] = *(u32 *)p;
                                   ^^^^^^^^

The else side will still crash.

regards,
dan carpenter

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

* Re: [PATCH] e1000: avoid null pointer dereference on invalid stat type
  2017-09-22 11:50   ` Dan Carpenter
@ 2017-09-22 11:55     ` Colin Ian King
  -1 siblings, 0 replies; 8+ messages in thread
From: Colin Ian King @ 2017-09-22 11:55 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Jeff Kirsher, intel-wired-lan, netdev, kernel-janitors,
	linux-kernel

On 22/09/17 12:50, Dan Carpenter wrote:
> On Thu, Sep 21, 2017 at 11:01:58PM +0100, Colin King wrote:
>> @@ -1837,12 +1838,13 @@ static void e1000_get_ethtool_stats(struct net_device *netdev,
>>  			p = (char *)adapter + stat->stat_offset;
>>  			break;
>>  		default:
>> +			p = NULL;
>>  			WARN_ONCE(1, "Invalid E1000 stat type: %u index %d\n",
>>  				  stat->type, i);
>>  			break;
>>  		}
>>  
>> -		if (stat->sizeof_stat = sizeof(u64))
>> +		if (p && stat->sizeof_stat = sizeof(u64))
>>  			data[i] = *(u64 *)p;
>>  		else
>>  			data[i] = *(u32 *)p;
>                                    ^^^^^^^^
> 
> The else side will still crash.
> 
> regards,
> dan carpenter
> 
Thanks, stupid me. I'll fix that up.

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

* Re: [PATCH] e1000: avoid null pointer dereference on invalid stat type
@ 2017-09-22 11:55     ` Colin Ian King
  0 siblings, 0 replies; 8+ messages in thread
From: Colin Ian King @ 2017-09-22 11:55 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Jeff Kirsher, intel-wired-lan, netdev, kernel-janitors,
	linux-kernel

On 22/09/17 12:50, Dan Carpenter wrote:
> On Thu, Sep 21, 2017 at 11:01:58PM +0100, Colin King wrote:
>> @@ -1837,12 +1838,13 @@ static void e1000_get_ethtool_stats(struct net_device *netdev,
>>  			p = (char *)adapter + stat->stat_offset;
>>  			break;
>>  		default:
>> +			p = NULL;
>>  			WARN_ONCE(1, "Invalid E1000 stat type: %u index %d\n",
>>  				  stat->type, i);
>>  			break;
>>  		}
>>  
>> -		if (stat->sizeof_stat == sizeof(u64))
>> +		if (p && stat->sizeof_stat == sizeof(u64))
>>  			data[i] = *(u64 *)p;
>>  		else
>>  			data[i] = *(u32 *)p;
>                                    ^^^^^^^^
> 
> The else side will still crash.
> 
> regards,
> dan carpenter
> 
Thanks, stupid me. I'll fix that up.

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

* [PATCH] e1000: avoid null pointer dereference on invalid stat type
@ 2018-11-09 13:17 Loic
  2018-11-17 14:37 ` Sasha Levin
  0 siblings, 1 reply; 8+ messages in thread
From: Loic @ 2018-11-09 13:17 UTC (permalink / raw)
  To: stable; +Cc: colin.king, alexander.h.duyck, aaron.f.brown, jeffrey.t.kirsher

Hello,

Please picked up this patch for linux 4.4 and 4.9.
Compiled/tested without problem.

Thank.

[ Upstream commit 5983587c8c5ef00d6886477544ad67d495bc5479 ]

From: Colin Ian King <colin.king@canonical.com>
Date: Fri, 22 Sep 2017 18:13:48 +0100
Subject: [PATCH] e1000: avoid null pointer dereference on invalid stat type

Currently if the stat type is invalid then data[i] is being set
either by dereferencing a null pointer p, or it is reading from
an incorrect previous location if we had a valid stat type
previously.  Fix this by skipping over the read of p on an invalid
stat type.

Detected by CoverityScan, CID#113385 ("Explicit null dereferenced")

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Alexander Duyck <alexander.h.duyck@intel.com>
Tested-by: Aaron Brown <aaron.f.brown@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
---
 drivers/net/ethernet/intel/e1000/e1000_ethtool.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/intel/e1000/e1000_ethtool.c b/drivers/net/ethernet/intel/e1000/e1000_ethtool.c
index ec8aa4562cc90..3b3983a1ffbba 100644
--- a/drivers/net/ethernet/intel/e1000/e1000_ethtool.c
+++ b/drivers/net/ethernet/intel/e1000/e1000_ethtool.c
@@ -1824,11 +1824,12 @@ static void e1000_get_ethtool_stats(struct net_device *netdev,
 {
 	struct e1000_adapter *adapter = netdev_priv(netdev);
 	int i;
-	char *p = NULL;
 	const struct e1000_stats *stat = e1000_gstrings_stats;
 
 	e1000_update_stats(adapter);
-	for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
+	for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++, stat++) {
+		char *p;
+
 		switch (stat->type) {
 		case NETDEV_STATS:
 			p = (char *)netdev + stat->stat_offset;
@@ -1839,15 +1840,13 @@ static void e1000_get_ethtool_stats(struct net_device *netdev,
 		default:
 			WARN_ONCE(1, "Invalid E1000 stat type: %u index %d\n",
 				  stat->type, i);
-			break;
+			continue;
 		}
 
 		if (stat->sizeof_stat == sizeof(u64))
 			data[i] = *(u64 *)p;
 		else
 			data[i] = *(u32 *)p;
-
-		stat++;
 	}
 /* BUG_ON(i != E1000_STATS_LEN); */
 }

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

* Re: [PATCH] e1000: avoid null pointer dereference on invalid stat type
  2018-11-09 13:17 [PATCH] e1000: avoid null pointer dereference on invalid stat type Loic
@ 2018-11-17 14:37 ` Sasha Levin
  0 siblings, 0 replies; 8+ messages in thread
From: Sasha Levin @ 2018-11-17 14:37 UTC (permalink / raw)
  To: Loic
  Cc: stable, colin.king, alexander.h.duyck, aaron.f.brown,
	jeffrey.t.kirsher

On Fri, Nov 09, 2018 at 02:17:06PM +0100, Loic wrote:
>Hello,
>
>Please picked up this patch for linux 4.4 and 4.9.
>Compiled/tested without problem.
>
>Thank.
>
>[ Upstream commit 5983587c8c5ef00d6886477544ad67d495bc5479 ]
>
>From: Colin Ian King <colin.king@canonical.com>
>Date: Fri, 22 Sep 2017 18:13:48 +0100
>Subject: [PATCH] e1000: avoid null pointer dereference on invalid stat type
>
>Currently if the stat type is invalid then data[i] is being set
>either by dereferencing a null pointer p, or it is reading from
>an incorrect previous location if we had a valid stat type
>previously.  Fix this by skipping over the read of p on an invalid
>stat type.
>
>Detected by CoverityScan, CID#113385 ("Explicit null dereferenced")
>
>Signed-off-by: Colin Ian King <colin.king@canonical.com>
>Reviewed-by: Alexander Duyck <alexander.h.duyck@intel.com>
>Tested-by: Aaron Brown <aaron.f.brown@intel.com>
>Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>

Queued for 4.9 and 4.4, thank you.

--
Thanks,
Sasha

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

end of thread, other threads:[~2018-11-18  0:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-09 13:17 [PATCH] e1000: avoid null pointer dereference on invalid stat type Loic
2018-11-17 14:37 ` Sasha Levin
  -- strict thread matches above, loose matches on Subject: below --
2017-09-21 22:01 Colin King
2017-09-21 22:01 ` Colin King
2017-09-22 11:50 ` Dan Carpenter
2017-09-22 11:50   ` Dan Carpenter
2017-09-22 11:55   ` Colin Ian King
2017-09-22 11:55     ` Colin Ian King

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.