kni: fix sprintf with snprintf

Message ID 1549263758-32677-1-git-send-email-pallantlax.poornima@intel.com
State Rejected
Delegated to: Thomas Monjalon
Headers show
Series
  • kni: fix sprintf with snprintf
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS
ci/checkpatch success coding style OK

Commit Message

Pallantla Poornima Feb. 4, 2019, 7:02 a.m.
sprintf function is not secure as it doesn't check the length of string.
More secure function snprintf is used.

Fixes: 3fc5ca2f63 ("kni: initial import")
Fixes: b9ee370557 ("kni: update kernel driver ethtool baseline")
Cc: stable@dpdk.org

Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com>
---
 kernel/linux/kni/ethtool/igb/igb_ethtool.c    | 41 +++++++++++--------
 kernel/linux/kni/ethtool/igb/igb_main.c       | 12 ++++--
 .../linux/kni/ethtool/ixgbe/ixgbe_ethtool.c   | 30 ++++++++------
 3 files changed, 50 insertions(+), 33 deletions(-)

Comments

Ferruh Yigit Feb. 7, 2019, 4:40 p.m. | #1
On 2/4/2019 7:02 AM, Pallantla Poornima wrote:
> sprintf function is not secure as it doesn't check the length of string.
> More secure function snprintf is used.
> 
> Fixes: 3fc5ca2f63 ("kni: initial import")
> Fixes: b9ee370557 ("kni: update kernel driver ethtool baseline")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com>
> ---
>  kernel/linux/kni/ethtool/igb/igb_ethtool.c    | 41 +++++++++++--------
>  kernel/linux/kni/ethtool/igb/igb_main.c       | 12 ++++--
>  .../linux/kni/ethtool/ixgbe/ixgbe_ethtool.c   | 30 ++++++++------

Overall updates looks good, but I am not sure if we need to update the kernel
drivers in KNI. At least *_ethtool.c ones shouldn't be called at all.

Any objection to skip these files from this patch?
Wiles, Keith Feb. 7, 2019, 6:01 p.m. | #2
> On Feb 7, 2019, at 10:40 AM, Ferruh Yigit <ferruh.yigit@intel.com> wrote:
> 
> On 2/4/2019 7:02 AM, Pallantla Poornima wrote:
>> sprintf function is not secure as it doesn't check the length of string.
>> More secure function snprintf is used.
>> 
>> Fixes: 3fc5ca2f63 ("kni: initial import")
>> Fixes: b9ee370557 ("kni: update kernel driver ethtool baseline")
>> Cc: stable@dpdk.org
>> 
>> Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com>
>> ---
>> kernel/linux/kni/ethtool/igb/igb_ethtool.c    | 41 +++++++++++--------
>> kernel/linux/kni/ethtool/igb/igb_main.c       | 12 ++++--
>> .../linux/kni/ethtool/ixgbe/ixgbe_ethtool.c   | 30 ++++++++------
> 
> Overall updates looks good, but I am not sure if we need to update the kernel
> drivers in KNI. At least *_ethtool.c ones shouldn't be called at all.
> 
> Any objection to skip these files from this patch?

yes, would skip the kernel modules.

Regards,
Keith

Patch

diff --git a/kernel/linux/kni/ethtool/igb/igb_ethtool.c b/kernel/linux/kni/ethtool/igb/igb_ethtool.c
index b6bddc025..d82ecec41 100644
--- a/kernel/linux/kni/ethtool/igb/igb_ethtool.c
+++ b/kernel/linux/kni/ethtool/igb/igb_ethtool.c
@@ -2115,39 +2115,48 @@  static void igb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
 			p += ETH_GSTRING_LEN;
 		}
 		for (i = 0; i < adapter->num_tx_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, "tx_queue_%u_restart", i);
+			snprintf(p, ETH_GSTRING_LEN, "tx_queue_%u_restart", i);
 			p += ETH_GSTRING_LEN;
 		}
 		for (i = 0; i < adapter->num_rx_queues; i++) {
-			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;
-			sprintf(p, "rx_queue_%u_drops", i);
+			snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_drops", i);
 			p += ETH_GSTRING_LEN;
-			sprintf(p, "rx_queue_%u_csum_err", i);
+			snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_csum_err", i);
 			p += ETH_GSTRING_LEN;
-			sprintf(p, "rx_queue_%u_alloc_failed", i);
+			snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_alloc_failed",
+					i);
 			p += ETH_GSTRING_LEN;
-			sprintf(p, "rx_queue_%u_ipv4_packets", i);
+			snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_ipv4_packets",
+					i);
 			p += ETH_GSTRING_LEN;
-			sprintf(p, "rx_queue_%u_ipv4e_packets", i);
+			snprintf(p, ETH_GSTRING_LEN,
+					"rx_queue_%u_ipv4e_packets", i);
 			p += ETH_GSTRING_LEN;
-			sprintf(p, "rx_queue_%u_ipv6_packets", i);
+			snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_ipv6_packets",
+					i);
 			p += ETH_GSTRING_LEN;
-			sprintf(p, "rx_queue_%u_ipv6e_packets", i);
+			snprintf(p, ETH_GSTRING_LEN,
+					"rx_queue_%u_ipv6e_packets", i);
 			p += ETH_GSTRING_LEN;
-			sprintf(p, "rx_queue_%u_tcp_packets", i);
+			snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_tcp_packets",
+					i);
 			p += ETH_GSTRING_LEN;
-			sprintf(p, "rx_queue_%u_udp_packets", i);
+			snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_udp_packets",
+					i);
 			p += ETH_GSTRING_LEN;
-			sprintf(p, "rx_queue_%u_sctp_packets", i);
+			snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_sctp_packets",
+					i);
 			p += ETH_GSTRING_LEN;
-			sprintf(p, "rx_queue_%u_nfs_packets", i);
+			snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_nfs_packets",
+					i);
 			p += ETH_GSTRING_LEN;
 		}
 /*		BUG_ON(p - data != IGB_STATS_LEN * ETH_GSTRING_LEN); */
diff --git a/kernel/linux/kni/ethtool/igb/igb_main.c b/kernel/linux/kni/ethtool/igb/igb_main.c
index 0b4faeae5..e6765b4dd 100644
--- a/kernel/linux/kni/ethtool/igb/igb_main.c
+++ b/kernel/linux/kni/ethtool/igb/igb_main.c
@@ -679,16 +679,20 @@  static int igb_request_msix(struct igb_adapter *adapter)
 		q_vector->itr_register = hw->hw_addr + E1000_EITR(vector);
 
 		if (q_vector->rx.ring && q_vector->tx.ring)
-			sprintf(q_vector->name, "%s-TxRx-%u", netdev->name,
+			snprintf(q_vector->name, sizeof(q_vector->name),
+					"%s-TxRx-%u", netdev->name,
 			        q_vector->rx.ring->queue_index);
 		else if (q_vector->tx.ring)
-			sprintf(q_vector->name, "%s-tx-%u", netdev->name,
+			snprintf(q_vector->name, sizeof(q_vector->name),
+					"%s-tx-%u", netdev->name,
 			        q_vector->tx.ring->queue_index);
 		else if (q_vector->rx.ring)
-			sprintf(q_vector->name, "%s-rx-%u", netdev->name,
+			snprintf(q_vector->name, sizeof(q_vector->name),
+					"%s-rx-%u", netdev->name,
 			        q_vector->rx.ring->queue_index);
 		else
-			sprintf(q_vector->name, "%s-unused", netdev->name);
+			snprintf(q_vector->name, sizeof(q_vector->name),
+					"%s-unused", netdev->name);
 
 		err = request_irq(adapter->msix_entries[vector].vector,
 		                  igb_msix_ring, 0, q_vector->name,
diff --git a/kernel/linux/kni/ethtool/ixgbe/ixgbe_ethtool.c b/kernel/linux/kni/ethtool/ixgbe/ixgbe_ethtool.c
index f2ded19e9..50e568ee2 100644
--- a/kernel/linux/kni/ethtool/ixgbe/ixgbe_ethtool.c
+++ b/kernel/linux/kni/ethtool/ixgbe/ixgbe_ethtool.c
@@ -1182,41 +1182,45 @@  static void ixgbe_get_strings(struct net_device *netdev, u32 stringset,
 			p += ETH_GSTRING_LEN;
 		}
 		for (i = 0; i < adapter->num_tx_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;
 		}
 		for (i = 0; i < adapter->num_rx_queues; i++) {
-			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;
 		}
 		if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
 			for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
-				sprintf(p, "tx_pb_%u_pxon", i);
+				snprintf(p, ETH_GSTRING_LEN, "tx_pb_%u_pxon",
+						i);
 				p += ETH_GSTRING_LEN;
-				sprintf(p, "tx_pb_%u_pxoff", i);
+				snprintf(p, ETH_GSTRING_LEN, "tx_pb_%u_pxoff",
+						i);
 				p += ETH_GSTRING_LEN;
 			}
 			for (i = 0; i < MAX_RX_PACKET_BUFFERS; i++) {
-				sprintf(p, "rx_pb_%u_pxon", i);
+				snprintf(p, ETH_GSTRING_LEN, "rx_pb_%u_pxon",
+						i);
 				p += ETH_GSTRING_LEN;
-				sprintf(p, "rx_pb_%u_pxoff", i);
+				snprintf(p, ETH_GSTRING_LEN, "rx_pb_%u_pxoff",
+						i);
 				p += ETH_GSTRING_LEN;
 			}
 		}
 		for (i = 0; i < adapter->num_vfs; i++) {
-			sprintf(p, "VF %d Rx Packets", i);
+			snprintf(p, ETH_GSTRING_LEN, "VF %d Rx Packets", i);
 			p += ETH_GSTRING_LEN;
-			sprintf(p, "VF %d Rx Bytes", i);
+			snprintf(p, ETH_GSTRING_LEN, "VF %d Rx Bytes", i);
 			p += ETH_GSTRING_LEN;
-			sprintf(p, "VF %d Tx Packets", i);
+			snprintf(p, ETH_GSTRING_LEN, "VF %d Tx Packets", i);
 			p += ETH_GSTRING_LEN;
-			sprintf(p, "VF %d Tx Bytes", i);
+			snprintf(p, ETH_GSTRING_LEN, "VF %d Tx Bytes", i);
 			p += ETH_GSTRING_LEN;
-			sprintf(p, "VF %d MC Packets", i);
+			snprintf(p, ETH_GSTRING_LEN, "VF %d MC Packets", i);
 			p += ETH_GSTRING_LEN;
 		}
 		/* BUG_ON(p - data != IXGBE_STATS_LEN * ETH_GSTRING_LEN); */