DPDK patches and discussions
 help / color / mirror / Atom feed
From: Pallantla Poornima <pallantlax.poornima@intel.com>
To: dev@dpdk.org
Cc: reshma.pattan@intel.com, ferruh.yigit@intel.com,
	Pallantla Poornima <pallantlax.poornima@intel.com>,
	stable@dpdk.org
Subject: [dpdk-dev] [PATCH] kni: fix sprintf with snprintf
Date: Mon,  4 Feb 2019 07:02:38 +0000	[thread overview]
Message-ID: <1549263758-32677-1-git-send-email-pallantlax.poornima@intel.com> (raw)
In-Reply-To: <y>

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(-)

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	other threads:[~2019-02-04  7:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-04  7:02 Pallantla Poornima [this message]
2019-02-07 16:40 ` Ferruh Yigit
2019-02-07 18:01   ` Wiles, Keith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1549263758-32677-1-git-send-email-pallantlax.poornima@intel.com \
    --to=pallantlax.poornima@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=reshma.pattan@intel.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).