fm10k: use snprintf() instead of sprintf() to avoid buffer overflow
Subsystems (2)
--- drivers/net/ethernet/intel/fm10k/fm10k_debugfs.c | 6 +++--- drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_debugfs.c +3 -3
@@ -176,7 +176,7 @@ void fm10k_dbg_q_vector_init(struct fm10k_q_vector *q_vector)return ;/* Generate a folder for each q_vector */ -sprintf (name,"q_vector.%03d" , q_vector->v_idx); +snprintf (name,sizeof (name),"q_vector.%03d" , q_vector->v_idx); q_vector->dbg_q_vector =debugfs_create_dir (name, interface->dbg_intfc);if (!q_vector->dbg_q_vector)
@@ -186,7 +186,7 @@ void fm10k_dbg_q_vector_init(struct fm10k_q_vector *q_vector)for (i =0 ; i < q_vector->tx.count; i++) {struct fm10k_ring *ring = &q_vector->tx.ring[i]; -sprintf (name,"tx_ring.%03d" , ring->queue_index); +snprintf (name,sizeof (name),"tx_ring.%03d" , ring->queue_index); debugfs_create_file(name, 0600, q_vector->dbg_q_vector, ring,
@@ -197,7 +197,7 @@ void fm10k_dbg_q_vector_init(struct fm10k_q_vector *q_vector)for (i =0 ; i < q_vector->rx.count; i++) {struct fm10k_ring *ring = &q_vector->rx.ring[i]; -sprintf (name,"rx_ring.%03d" , ring->queue_index); +snprintf (name,sizeof (name),"rx_ring.%03d" , ring->queue_index); debugfs_create_file(name, 0600, q_vector->dbg_q_vector, ring,
drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c +4 -4
@@ -206,13 +206,13 @@ static void fm10k_get_stat_strings(struct net_device *dev, u8 *data) }for (i =0 ; i < interface->hw.mac.max_queues; i++) { -sprintf (p,"tx_queue_%u_packets" , i); +snprintf (p,ETH_GSTRING_LEN ,"tx_queue_%u_packets" , i); p +=ETH_GSTRING_LEN ; -sprintf (p,"tx_queue_%u_bytes" , i); +snprintf (p,ETH_GSTRING_LEN ,"tx_queue_%u_bytes" , i); p +=ETH_GSTRING_LEN ; -sprintf (p,"rx_queue_%u_packets" , i); +snprintf (p,ETH_GSTRING_LEN ,"rx_queue_%u_packets" , i); p +=ETH_GSTRING_LEN ; -sprintf (p,"rx_queue_%u_bytes" , i); +snprintf (p,ETH_GSTRING_LEN ,"rx_queue_%u_bytes" , i); p +=ETH_GSTRING_LEN ; } }
Signature · 1 line
2.5.0.280.g4aaba03
[Intel-wired-lan] [next-queue] fm10k: Correct MTU for jumbo frames
Based on hardware testing, the host interface can support up to 15368 bytes on the wire. Subtracting 8 for an internal switch tag and 14 for the L2 header shows that the MTU should not be allowed to be set above 15346 bytes.
--- drivers/net/ethernet/intel/fm10k/fm10k.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/fm10k/fm10k.h +1 -1
@@ -33,7 +33,7 @@#include "fm10k_pf.h" #include "fm10k_vf.h" -#define FM10K_MAX_JUMBO_FRAME_SIZE 15358/* Maximum supported size 15K */ +#define FM10K_MAX_JUMBO_FRAME_SIZE 15346/* Maximum supported size 15K */ #define MAX_QUEUES FM10K_MAX_QUEUES_PF
Signature · 1 line
2.5.0.280.g4aaba03
[Intel-wired-lan] [next-queue] fm10k: do not use enum as boolean
In reply to Jacob KellerCheck for actual value NETREG_UNINITIALIZED in case it ever changes from the current value of zero.
--- drivers/net/ethernet/intel/fm10k/fm10k_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/fm10k/fm10k_main.c +1 -1
@@ -1905,7 +1905,7 @@ static void fm10k_init_reta(struct fm10k_intfc *interface)u32 reta, base;/* If the netdev is initialized we have to maintain table if possible */ -if (interface->netdev->reg_state) { +if (interface->netdev->reg_state !=NETREG_UNINITIALIZED ) {for (i =FM10K_RETA_SIZE ; i--;) { reta = interface->reta[i]; if ((((reta << 24) >> 24) < rss_i) &&
Signature · 1 line
2.5.0.280.g4aaba03
Singh
Tested-by Krishneil Singh[Intel-wired-lan] [next-queue] fm10k: do not use enum as boolean
-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at lists.osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, August 24, 2015 5:02 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [next-queue] fm10k: do not use enum as boolean
Check for actual value NETREG_UNINITIALIZED in case it ever changes from the current value of zero.
---
[Intel-wired-lan] [next-queue] fm10k: do not assume VF always has 1 queue
In reply to Jacob KellerIt is possible that the PF has not yet assigned resources to the VF. Although rare, this could result in the VF attempting to read queues it does not own and result in FUM or THI faults in the PF. To prevent this, check queue 0 before we continue in init_hw_vf.
--- drivers/net/ethernet/intel/fm10k/fm10k_vf.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/fm10k/fm10k_vf.c +6 -1
@@ -103,7 +103,12 @@ static s32 fm10k_init_hw_vf(struct fm10k_hw *hw)s32 err;u16 i; -/* assume we always have at least 1 queue */ +/* verify we have at least 1 queue */ +if (!~FM10K_READ_REG (hw,FM10K_TXQCTL (0 )) || + !~FM10K_READ_REG (hw,FM10K_RXQCTL (0 ))) +return FM10K_ERR_NO_RESOURCES ; + +/* determine how many queues we have */ for (i =1 ; tqdloc0 && (i <FM10K_MAX_QUEUES_POOL ); i++) {/* verify the Descriptor cache offsets are increasing */ tqdloc = ~fm10k_read_reg (hw,FM10K_TQDLOC (i));
Signature · 1 line
2.5.0.280.g4aaba03
Quoted 6 lines · On Mon, 24 Aug 2015 17:01:58 -0700 Jacob Keller <[email protected]>…
Signed-off-by Bruce Allan <[email protected]>Signed-off-by Jacob Keller <[email protected]>--- drivers/net/ethernet/intel/fm10k/fm10k_debugfs.c | 6 +++--- drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-)
The changes look fine, but I've seen multiple comments to the list that there needs to be a body in the commit message.
Suggest:
Subject:
fm10k: use snprintf()
Body:
Avoid buffer overflow and follow best practices by using snprintf() instead of sprintf().
Keller
Quoted 4 lines · Jesse Brandeburg
The changes look fine, but I've seen multiple comments to the list that
there needs to be a body in the commit message.
Really? Even for fairly trivial changes such as this?
I can re-work it.
Regards,
Jake
Singh
Tested-by Krishneil Singh-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at lists.osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, August 24, 2015 5:02 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [next-queue] fm10k: use snprintf() instead of sprintf() to avoid buffer overflow
---