Skip to contentSkip to conversation

fm10k: fix possible null pointer deref after kcalloc

PATCH New Jacob Keller 2 participants 8 messages Apr 7, 2016 – May 31, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 fm10k: fix possible null pointer deref after kcalloc

When writing a new default redirection table, we needed to populate a new RSS table using ethtool_rxfh_indir_default. We populated this table into a region of memory allocated using kcalloc, but never checked this for NULL. Fix this by moving the default table generation into fm10k_write_reta. If this function is passed a table, use it. Otherwise, generate the default table using ethtool_rxfh_indir_default, 4 at at time.

Fixes 0ea7fae44094 ("fm10k: use ethtool_rxfh_indir_default for default redirection table", 2016-02-16)

---

Notes:
Testing-hints:
This is a very unlikely memory failure, but you should test changing the number of queues, and the RSS table and make sure it behaves as expected.

 drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c | 26 ++++++++++++++++++------
 drivers/net/ethernet/intel/fm10k/fm10k_main.c    | 14 ++-----------
 2 files changed, 22 insertions(+), 18 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c +20 -6
index 27991348b659..24700a8026ed 100644
@@ -970,15 +970,29 @@ u32 fm10k_get_reta_size(struct net_device __always_unused *netdev)
 
 void fm10k_write_reta(struct fm10k_intfc *interface, const u32 *indir)
 {
+	u16 rss_i = interface->ring_feature[RING_F_RSS].indices;
 	struct fm10k_hw *hw = &interface->hw;
-	int i;
+	u32 table[4];
+	int i, j;
 
 	/* record entries to reta table */
-	for (i = 0; i < FM10K_RETA_SIZE; i++, indir += 4) {
-		u32 reta = indir[0] |
-			   (indir[1] << 8) |
-			   (indir[2] << 16) |
-			   (indir[3] << 24);
+	for (i = 0; i < FM10K_RETA_SIZE; i++) {
+		u32 reta, n;
+
+		/* generate a new table if we weren't given one */
+		for (j = 0; j < 4; j++) {
+			if (indir)
+				n = indir[i + j];
+			else
+				n = ethtool_rxfh_indir_default(i + j, rss_i);
+
+			table[j] = n;
+		}
+
+		reta = table[0] |
+			(table[1] << 8) |
+			(table[2] << 16) |
+			(table[3] << 24);
 
 		if (interface->reta[i] == reta)
 			continue;
drivers/net/ethernet/intel/fm10k/fm10k_main.c +2 -12
index 58092e523bbe..aca3e4762da7 100644
@@ -1927,8 +1927,7 @@ static void fm10k_assign_rings(struct fm10k_intfc *interface)
 static void fm10k_init_reta(struct fm10k_intfc *interface)
 {
 	u16 i, rss_i = interface->ring_feature[RING_F_RSS].indices;
-	struct net_device *netdev = interface->netdev;
-	u32 reta, *indir;
+	u32 reta;
 
 	/* If the Rx flow indirection table has been configured manually, we
 	 * need to maintain it when possible.
@@ -1953,16 +1952,7 @@ static void fm10k_init_reta(struct fm10k_intfc *interface)
 	}
 
 repopulate_reta:
-	indir = kcalloc(fm10k_get_reta_size(netdev),
-			sizeof(indir[0]), GFP_KERNEL);
-
-	/* generate redirection table using the default kernel policy */
-	for (i = 0; i < fm10k_get_reta_size(netdev); i++)
-		indir[i] = ethtool_rxfh_indir_default(i, rss_i);
-
-	fm10k_write_reta(interface, indir);
-
-	kfree(indir);
+	fm10k_write_reta(interface, NULL);
 }
 
 /**
Signature · 1 line
2.8.1.102.ga49ec4a
#1 lore raw

PATCH 2/4 fm10k: consistently use Intel(R) for driver names

Update every header file and other locations to consistently use Intel(R) instead of just Intel. Also update copyright year of files which we modified.

---

Notes:
Testing-hints:
Ensure all the uses of driver summary are the same.

 drivers/net/ethernet/intel/fm10k/Makefile        | 4 ++--
 drivers/net/ethernet/intel/fm10k/fm10k.h         | 2 +-
 drivers/net/ethernet/intel/fm10k/fm10k_common.c  | 4 ++--
 drivers/net/ethernet/intel/fm10k/fm10k_common.h  | 4 ++--
 drivers/net/ethernet/intel/fm10k/fm10k_dcbnl.c   | 4 ++--
 drivers/net/ethernet/intel/fm10k/fm10k_debugfs.c | 4 ++--
 drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c | 2 +-
 drivers/net/ethernet/intel/fm10k/fm10k_iov.c     | 4 ++--
 drivers/net/ethernet/intel/fm10k/fm10k_main.c    | 4 ++--
 drivers/net/ethernet/intel/fm10k/fm10k_mbx.c     | 4 ++--
 drivers/net/ethernet/intel/fm10k/fm10k_mbx.h     | 4 ++--
 drivers/net/ethernet/intel/fm10k/fm10k_netdev.c  | 2 +-
 drivers/net/ethernet/intel/fm10k/fm10k_pci.c     | 2 +-
 drivers/net/ethernet/intel/fm10k/fm10k_pf.c      | 2 +-
 drivers/net/ethernet/intel/fm10k/fm10k_pf.h      | 2 +-
 drivers/net/ethernet/intel/fm10k/fm10k_tlv.c     | 2 +-
 drivers/net/ethernet/intel/fm10k/fm10k_tlv.h     | 4 ++--
 drivers/net/ethernet/intel/fm10k/fm10k_type.h    | 2 +-
 drivers/net/ethernet/intel/fm10k/fm10k_vf.c      | 2 +-
 drivers/net/ethernet/intel/fm10k/fm10k_vf.h      | 2 +-
 20 files changed, 30 insertions(+), 30 deletions(-)
drivers/net/ethernet/intel/fm10k/Makefile +2 -2
index 2aeaa39d9a25..cac645329cea 100644
@@ -1,6 +1,6 @@
 ################################################################################
 #
-# Intel Ethernet Switch Host Interface Driver
+# Intel(R) Ethernet Switch Host Interface Driver
 # Copyright(c) 2013 - 2016 Intel Corporation.
 #
 # This program is free software; you can redistribute it and/or modify it
@@ -22,7 +22,7 @@
 ################################################################################
 
 #
-# Makefile for the Intel(R) FM10000 Ethernet Switch Host Interface driver
+# Makefile for the Intel(R) Ethernet Switch Host Interface Driver
 #
 
 obj-$(CONFIG_FM10K) += fm10k.o
drivers/net/ethernet/intel/fm10k/fm10k.h +1 -1
index 5efae40698cc..fcf106e545c5 100644
@@ -1,4 +1,4 @@
-/* Intel Ethernet Switch Host Interface Driver
+/* Intel(R) Ethernet Switch Host Interface Driver
  * Copyright(c) 2013 - 2016 Intel Corporation.
  *
  * This program is free software; you can redistribute it and/or modify it
drivers/net/ethernet/intel/fm10k/fm10k_common.c +2 -2
index 6cfae6ac04ea..5bbf19cfe29b 100644
@@ -1,5 +1,5 @@
-/* Intel Ethernet Switch Host Interface Driver
- * Copyright(c) 2013 - 2014 Intel Corporation.
+/* Intel(R) Ethernet Switch Host Interface Driver
+ * Copyright(c) 2013 - 2016 Intel Corporation.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
drivers/net/ethernet/intel/fm10k/fm10k_common.h +2 -2
index 45e4e5b1f20a..50f71e997448 100644
@@ -1,5 +1,5 @@
-/* Intel Ethernet Switch Host Interface Driver
- * Copyright(c) 2013 - 2014 Intel Corporation.
+/* Intel(R) Ethernet Switch Host Interface Driver
+ * Copyright(c) 2013 - 2016 Intel Corporation.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
drivers/net/ethernet/intel/fm10k/fm10k_dcbnl.c +2 -2
index 2be4361839db..db4bd8bf9722 100644
@@ -1,5 +1,5 @@
-/* Intel Ethernet Switch Host Interface Driver
- * Copyright(c) 2013 - 2015 Intel Corporation.
+/* Intel(R) Ethernet Switch Host Interface Driver
+ * Copyright(c) 2013 - 2016 Intel Corporation.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
drivers/net/ethernet/intel/fm10k/fm10k_debugfs.c +2 -2
index 5d6137faf7d1..5116fd043630 100644
@@ -1,5 +1,5 @@
-/* Intel Ethernet Switch Host Interface Driver
- * Copyright(c) 2013 - 2015 Intel Corporation.
+/* Intel(R) Ethernet Switch Host Interface Driver
+ * Copyright(c) 2013 - 2016 Intel Corporation.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c +1 -1
index 24700a8026ed..b4870b8ad0bd 100644
@@ -1,4 +1,4 @@
-/* Intel Ethernet Switch Host Interface Driver
+/* Intel(R) Ethernet Switch Host Interface Driver
  * Copyright(c) 2013 - 2016 Intel Corporation.
  *
  * This program is free software; you can redistribute it and/or modify it
drivers/net/ethernet/intel/fm10k/fm10k_iov.c +2 -2
index bbf7c4bac303..47f0743ec03b 100644
@@ -1,5 +1,5 @@
-/* Intel Ethernet Switch Host Interface Driver
- * Copyright(c) 2013 - 2015 Intel Corporation.
+/* Intel(R) Ethernet Switch Host Interface Driver
+ * Copyright(c) 2013 - 2016 Intel Corporation.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
drivers/net/ethernet/intel/fm10k/fm10k_main.c +2 -2
index aca3e4762da7..b875f4243667 100644
@@ -1,4 +1,4 @@
-/* Intel Ethernet Switch Host Interface Driver
+/* Intel(R) Ethernet Switch Host Interface Driver
  * Copyright(c) 2013 - 2016 Intel Corporation.
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -34,7 +34,7 @@ const char fm10k_driver_version[] = DRV_VERSION;
 char fm10k_driver_name[] = "fm10k";
 static const char fm10k_driver_string[] = DRV_SUMMARY;
 static const char fm10k_copyright[] =
-	"Copyright (c) 2013 Intel Corporation.";
+	"Copyright (c) 2013 - 2016 Intel Corporation.";
 
 MODULE_AUTHOR("Intel Corporation, <[email protected]>");
 MODULE_DESCRIPTION(DRV_SUMMARY);
drivers/net/ethernet/intel/fm10k/fm10k_mbx.c +2 -2
index 98202c3d591c..c9dfa6564fcf 100644
@@ -1,5 +1,5 @@
-/* Intel Ethernet Switch Host Interface Driver
- * Copyright(c) 2013 - 2015 Intel Corporation.
+/* Intel(R) Ethernet Switch Host Interface Driver
+ * Copyright(c) 2013 - 2016 Intel Corporation.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
drivers/net/ethernet/intel/fm10k/fm10k_mbx.h +2 -2
index 245a0a3dc32e..b7dbc8a84c05 100644
@@ -1,5 +1,5 @@
-/* Intel Ethernet Switch Host Interface Driver
- * Copyright(c) 2013 - 2015 Intel Corporation.
+/* Intel(R) Ethernet Switch Host Interface Driver
+ * Copyright(c) 2013 - 2016 Intel Corporation.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
drivers/net/ethernet/intel/fm10k/fm10k_netdev.c +1 -1
index bf229d54c20c..2a08d3f5b6df 100644
@@ -1,4 +1,4 @@
-/* Intel Ethernet Switch Host Interface Driver
+/* Intel(R) Ethernet Switch Host Interface Driver
  * Copyright(c) 2013 - 2016 Intel Corporation.
  *
  * This program is free software; you can redistribute it and/or modify it
drivers/net/ethernet/intel/fm10k/fm10k_pci.c +1 -1
index 1d833782d917..404f47ae14b6 100644
@@ -1,4 +1,4 @@
-/* Intel Ethernet Switch Host Interface Driver
+/* Intel(R) Ethernet Switch Host Interface Driver
  * Copyright(c) 2013 - 2016 Intel Corporation.
  *
  * This program is free software; you can redistribute it and/or modify it
drivers/net/ethernet/intel/fm10k/fm10k_pf.c +1 -1
index 2105cb8d31cc..5b0ceec361e6 100644
@@ -1,4 +1,4 @@
-/* Intel Ethernet Switch Host Interface Driver
+/* Intel(R) Ethernet Switch Host Interface Driver
  * Copyright(c) 2013 - 2016 Intel Corporation.
  *
  * This program is free software; you can redistribute it and/or modify it
drivers/net/ethernet/intel/fm10k/fm10k_pf.h +1 -1
index d4a34657b861..3336d3c10760 100644
@@ -1,4 +1,4 @@
-/* Intel Ethernet Switch Host Interface Driver
+/* Intel(R) Ethernet Switch Host Interface Driver
  * Copyright(c) 2013 - 2016 Intel Corporation.
  *
  * This program is free software; you can redistribute it and/or modify it
drivers/net/ethernet/intel/fm10k/fm10k_tlv.c +1 -1
index 6b500a6378e0..f8e87bf086b9 100644
@@ -1,4 +1,4 @@
-/* Intel Ethernet Switch Host Interface Driver
+/* Intel(R) Ethernet Switch Host Interface Driver
  * Copyright(c) 2013 - 2016 Intel Corporation.
  *
  * This program is free software; you can redistribute it and/or modify it
drivers/net/ethernet/intel/fm10k/fm10k_tlv.h +2 -2
index e1845e0a17d8..a1f1027fe184 100644
@@ -1,5 +1,5 @@
-/* Intel Ethernet Switch Host Interface Driver
- * Copyright(c) 2013 - 2015 Intel Corporation.
+/* Intel(R) Ethernet Switch Host Interface Driver
+ * Copyright(c) 2013 - 2016 Intel Corporation.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
drivers/net/ethernet/intel/fm10k/fm10k_type.h +1 -1
index f3f37a49806e..b8bc06183720 100644
@@ -1,4 +1,4 @@
-/* Intel Ethernet Switch Host Interface Driver
+/* Intel(R) Ethernet Switch Host Interface Driver
  * Copyright(c) 2013 - 2016 Intel Corporation.
  *
  * This program is free software; you can redistribute it and/or modify it
drivers/net/ethernet/intel/fm10k/fm10k_vf.c +1 -1
index 0440706eeb82..3b06685ea63b 100644
@@ -1,4 +1,4 @@
-/* Intel Ethernet Switch Host Interface Driver
+/* Intel(R) Ethernet Switch Host Interface Driver
  * Copyright(c) 2013 - 2016 Intel Corporation.
  *
  * This program is free software; you can redistribute it and/or modify it
drivers/net/ethernet/intel/fm10k/fm10k_vf.h +1 -1
index f0932f944793..2662f33c0c71 100644
@@ -1,4 +1,4 @@
-/* Intel Ethernet Switch Host Interface Driver
+/* Intel(R) Ethernet Switch Host Interface Driver
  * Copyright(c) 2013 - 2016 Intel Corporation.
  *
  * This program is free software; you can redistribute it and/or modify it
Signature · 1 line
2.8.1.102.ga49ec4a
#2 lore raw

PATCH 2/4 fm10k: consistently use Intel(R) for driver names

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at lists.osuosl.org] On Behalf Of Jacob Keller
Sent: Thursday, April 7, 2016 8:21 AM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH v1 2/4] fm10k: consistently use Intel(R) for driver names

Update every header file and other locations to consistently use Intel(R) instead of just Intel. Also update copyright year of files which we modified.

---

#3 lore raw

PATCH 3/4 fm10k: fix fm10k_add_ethtool_stats to zero memory

In reply to Jacob Keller

The ethtool API does not guarantee zero'd memory, so we need to zero the stats we skip instead of just skipping them.

---

Notes:
Testing-hints:
Ensure that the queue stats don't show random memory values, but always zero if they are unused.

Unfortunately, somehow Dave Miller pulled an incorrect version of the original for this patch, so this is a follow-on fixup which brings back the bug fix.

 drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c +3 -2
index b4870b8ad0bd..9c0d87503977 100644
@@ -243,9 +243,10 @@ static void fm10k_add_ethtool_stats(u64 **data, void *pointer,
 	unsigned int i;
 	char *p;
 
-	/* simply skip forward if we were not given a valid pointer */
 	if (!pointer) {
-		*data += size;
+		/* memory is not zero allocated so we have to clear it */
+		for (i = 0; i < size; i++)
+			*((*data)++) = 0;
 		return;
 	}
 
Signature · 1 line
2.8.1.102.ga49ec4a
#4 lore raw

PATCH 3/4 fm10k: fix fm10k_add_ethtool_stats to zero memory

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at lists.osuosl.org] On Behalf Of Jacob Keller
Sent: Thursday, April 7, 2016 8:21 AM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH v1 3/4] fm10k: fix fm10k_add_ethtool_stats to zero memory

The ethtool API does not guarantee zero'd memory, so we need to zero the stats we skip instead of just skipping them.

---

#5 lore raw

PATCH 4/4 fm10k: fix incorrect IPv6 extended header checksum

In reply to Jacob Keller

From: Bruce Allan <[email protected]>

Check for and handle IPv6 extended headers so that tx checksum offload can be done. Also use skb_checksum_help for unexpected cases.

---

Notes:
Testing-hints:
Use the testing tool ipv6-exth program supplied by Mark Rustad to verify that ipv6 packets with extended headers get proper checksums. When using tcpdump, ensure that you only check receive traffic on the link partner, as tcpdump will report checksum errors for transmitted traffic if Tx checksum offloads are enabled.

 drivers/net/ethernet/intel/fm10k/fm10k_main.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_main.c +16 -9
index b875f4243667..0e166e9c90c8 100644
@@ -820,6 +820,8 @@ static void fm10k_tx_csum(struct fm10k_ring *tx_ring,
 		struct ipv6hdr *ipv6;
 		u8 *raw;
 	} network_hdr;
+	u8 *transport_hdr;
+	__be16 frag_off;
 	__be16 protocol;
 	u8 l4_hdr = 0;
 
@@ -837,9 +839,11 @@ static void fm10k_tx_csum(struct fm10k_ring *tx_ring,
 			goto no_csum;
 		}
 		network_hdr.raw = skb_inner_network_header(skb);
+		transport_hdr = skb_inner_transport_header(skb);
 	} else {
 		protocol = vlan_get_protocol(skb);
 		network_hdr.raw = skb_network_header(skb);
+		transport_hdr = skb_transport_header(skb);
 	}
 
 	switch (protocol) {
@@ -848,15 +852,17 @@ static void fm10k_tx_csum(struct fm10k_ring *tx_ring,
 		break;
 	case htons(ETH_P_IPV6):
 		l4_hdr = network_hdr.ipv6->nexthdr;
+		if (likely((transport_hdr - network_hdr.raw) ==
+			   sizeof(struct ipv6hdr)))
+			break;
+		ipv6_skip_exthdr(skb, network_hdr.raw - skb->data +
+				      sizeof(struct ipv6hdr),
+				 &l4_hdr, &frag_off);
+		if (unlikely(frag_off))
+			l4_hdr = NEXTHDR_FRAGMENT;
 		break;
 	default:
-		if (unlikely(net_ratelimit())) {
-			dev_warn(tx_ring->dev,
-				 "partial checksum but ip version=%x!\n",
-				 protocol);
-		}
-		tx_ring->tx_stats.csum_err++;
-		goto no_csum;
+		break;
 	}
 
 	switch (l4_hdr) {
@@ -869,9 +875,10 @@ static void fm10k_tx_csum(struct fm10k_ring *tx_ring,
 	default:
 		if (unlikely(net_ratelimit())) {
 			dev_warn(tx_ring->dev,
-				 "partial checksum but l4 proto=%x!\n",
-				 l4_hdr);
+				 "partial checksum, version=%d l4 proto=%x\n",
+				 protocol, l4_hdr);
 		}
+		skb_checksum_help(skb);
 		tx_ring->tx_stats.csum_err++;
 		goto no_csum;
 	}
Signature · 1 line
2.8.1.102.ga49ec4a
#6 lore raw

PATCH 1/4 fm10k: fix possible null pointer deref after kcalloc

In reply to Jacob Keller
Quoted 10 lines · Jacob Keller

When writing a new default redirection table, we needed to populate a new RSS table using ethtool_rxfh_indir_default. We populated this table into a region of memory allocated using kcalloc, but never checked
this for NULL. Fix this by moving the default table generation into fm10k_write_reta. If this function is passed a table, use it. Otherwise,
generate the default table using ethtool_rxfh_indir_default, 4 at at time.

Quoted 4 lines
Fixes 0ea7fae44094 ("fm10k: use ethtool_rxfh_indir_default for

default redirection table", 2016-02-16)

---

Jeff,

This patch has an issue I will be sending a reworked version, so please drop this from the queue and don't submit it to net-next yet.

Thanks Krishniel for finding the issue!

Thanks,
Jake

#7 lore raw

PATCH 1/4 fm10k: fix possible null pointer deref after kcalloc

In reply to Jacob Keller

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at lists.osuosl.org] On Behalf Of Jacob Keller
Sent: Thursday, April 7, 2016 8:21 AM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH v1 1/4] fm10k: fix possible null pointer deref after kcalloc

When writing a new default redirection table, we needed to populate a new RSS table using ethtool_rxfh_indir_default. We populated this table into a region of memory allocated using kcalloc, but never checked this for NULL. Fix this by moving the default table generation into fm10k_write_reta. If this function is passed a table, use it. Otherwise, generate the default table using ethtool_rxfh_indir_default, 4 at at time.

Fixes 0ea7fae44094 ("fm10k: use ethtool_rxfh_indir_default for default redirection table", 2016-02-16)

---