fm10k: fix possible null pointer deref after kcalloc
Subsystems (2)
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.
---
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
@@ -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
@@ -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
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Singh
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.
---
PATCH 3/4 fm10k: fix fm10k_add_ethtool_stats to zero memory
In reply to Jacob KellerThe 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
@@ -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
Singh
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.
---
PATCH 4/4 fm10k: fix incorrect IPv6 extended header checksum
In reply to Jacob KellerFrom: 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
@@ -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
Keller
PATCH 1/4 fm10k: fix possible null pointer deref after kcalloc
In reply to Jacob KellerQuoted 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 intofm10k_write_reta. If this function is passed a table, use it. Otherwise,
generate the default table usingethtool_rxfh_indir_default, 4 at at time.
Quoted 4 lines
Fixes 0ea7fae44094 ("fm10k: use ethtool_rxfh_indir_default fordefault redirection table", 2016-02-16)
Signed-off-by Jacob Keller <[email protected]>---
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
Singh
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.
---