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: sta...@dpdk.org

Signed-off-by: Pallantla Poornima <pallantlax.poorn...@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(-)

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); */
-- 
2.17.2

Reply via email to