* [dpdk-dev] [PATCH] kni: fix sprintf with snprintf
@ 2019-02-04 7:02 Pallantla Poornima
2019-02-07 16:40 ` Ferruh Yigit
0 siblings, 1 reply; 3+ messages in thread
From: Pallantla Poornima @ 2019-02-04 7:02 UTC (permalink / raw)
To: dev; +Cc: reshma.pattan, ferruh.yigit, Pallantla Poornima, stable
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [dpdk-dev] [PATCH] kni: fix sprintf with snprintf
2019-02-04 7:02 [dpdk-dev] [PATCH] kni: fix sprintf with snprintf Pallantla Poornima
@ 2019-02-07 16:40 ` Ferruh Yigit
2019-02-07 18:01 ` Wiles, Keith
0 siblings, 1 reply; 3+ messages in thread
From: Ferruh Yigit @ 2019-02-07 16:40 UTC (permalink / raw)
To: Pallantla Poornima, dev; +Cc: reshma.pattan, stable
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?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [dpdk-dev] [PATCH] kni: fix sprintf with snprintf
2019-02-07 16:40 ` Ferruh Yigit
@ 2019-02-07 18:01 ` Wiles, Keith
0 siblings, 0 replies; 3+ messages in thread
From: Wiles, Keith @ 2019-02-07 18:01 UTC (permalink / raw)
To: Yigit, Ferruh; +Cc: Poornima, PallantlaX, dpdk-dev, Pattan, Reshma, stable
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-02-07 18:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-04 7:02 [dpdk-dev] [PATCH] kni: fix sprintf with snprintf Pallantla Poornima
2019-02-07 16:40 ` Ferruh Yigit
2019-02-07 18:01 ` Wiles, Keith
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).