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


Groups > linux.kernel > #1737077 > unrolled thread

[PATCH] e1000: avoid null pointer dereference on invalid stat type

Started byColin King <colin.king@canonical.com>
First post2017-09-22 00:10 +0200
Last post2017-09-22 14:00 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] e1000: avoid null pointer dereference on invalid stat type Colin King <colin.king@canonical.com> - 2017-09-22 00:10 +0200
    Re: [PATCH] e1000: avoid null pointer dereference on invalid stat  type Dan Carpenter <dan.carpenter@oracle.com> - 2017-09-22 14:00 +0200
      Re: [PATCH] e1000: avoid null pointer dereference on invalid stat  type Colin Ian King <colin.king@canonical.com> - 2017-09-22 14:00 +0200

#1737077 — [PATCH] e1000: avoid null pointer dereference on invalid stat type

FromColin King <colin.king@canonical.com>
Date2017-09-22 00:10 +0200
Subject[PATCH] e1000: avoid null pointer dereference on invalid stat type
Message-ID<ushPr-6zK-15@gated-at.bofh.it>
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

[toc] | [next] | [standalone]


#1737433 — Re: [PATCH] e1000: avoid null pointer dereference on invalid stat type

FromDan Carpenter <dan.carpenter@oracle.com>
Date2017-09-22 14:00 +0200
SubjectRe: [PATCH] e1000: avoid null pointer dereference on invalid stat type
Message-ID<usuMF-5Em-9@gated-at.bofh.it>
In reply to#1737077
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

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


#1737434 — Re: [PATCH] e1000: avoid null pointer dereference on invalid stat type

FromColin Ian King <colin.king@canonical.com>
Date2017-09-22 14:00 +0200
SubjectRe: [PATCH] e1000: avoid null pointer dereference on invalid stat type
Message-ID<usuMF-5Em-7@gated-at.bofh.it>
In reply to#1737433
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.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web