Skip to content

Commit

Permalink
From 6e4c82467cdef208fb4c0404e920e7f090d4bb30 Mon Sep 17 00:00:00 2001
Browse files Browse the repository at this point in the history
From: Jia Yu <jyu@vmware.com>
Date: Sun, 19 Aug 2018 22:18:45 -0700
Subject: net/bonding: fix buffer corruption in packets

[ upstream commit 6b2a47d ]

When bond slave devices cannot transmit all packets in bufs array,
tx_burst callback shall merge the un-transmitted packets back to
bufs array. Recent merge logic introduced a bug which causes
invalid mbuf addresses being written to bufs array.
When caller frees the un-transmitted packets, due to invalid addresses,
application will crash.

The fix is avoid shifting mbufs, and directly write un-transmitted
packets back to bufs array.

Fixes: 0915078 ("net/bonding: burst mode hash calculation")

Signed-off-by: Jia Yu <jyu@vmware.com>
Acked-by: Chas Williams <chas3@att.com>
---
partial-jira-bug: CEM-4321
Pulled in patch from 18.08

Change-Id: I3e2135ada7f93d1d6dd4f8ae80aad820e3b2a486
  • Loading branch information
Jeya ganesh babu J committed Apr 2, 2019
1 parent a5ed7f0 commit 332dac0
Showing 1 changed file with 23 additions and 93 deletions.
116 changes: 23 additions & 93 deletions drivers/net/bonding/rte_eth_bond_pmd.c
Expand Up @@ -299,10 +299,10 @@ bond_ethdev_tx_burst_8023ad_fast_queue(void *queue, struct rte_mbuf **bufs,
/* Mapping array generated by hash function to map mbufs to slaves */
uint16_t bufs_slave_port_idxs[RTE_MAX_ETHPORTS] = { 0 };

uint16_t slave_tx_count, slave_tx_fail_count[RTE_MAX_ETHPORTS] = { 0 };
uint16_t slave_tx_count;
uint16_t total_tx_count = 0, total_tx_fail_count = 0;

uint16_t i, j;
uint16_t i;

if (unlikely(nb_bufs == 0))
return 0;
Expand Down Expand Up @@ -357,34 +357,12 @@ bond_ethdev_tx_burst_8023ad_fast_queue(void *queue, struct rte_mbuf **bufs,

/* If tx burst fails move packets to end of bufs */
if (unlikely(slave_tx_count < slave_nb_bufs[i])) {
slave_tx_fail_count[i] = slave_nb_bufs[i] -
int slave_tx_fail_count = slave_nb_bufs[i] -
slave_tx_count;
total_tx_fail_count += slave_tx_fail_count[i];

/*
* Shift bufs to beginning of array to allow reordering
* later
*/
for (j = 0; j < slave_tx_fail_count[i]; j++) {
slave_bufs[i][j] =
slave_bufs[i][(slave_tx_count - 1) + j];
}
}
}

/*
* If there are tx burst failures we move packets to end of bufs to
* preserve expected PMD behaviour of all failed transmitted being
* at the end of the input mbuf array
*/
if (unlikely(total_tx_fail_count > 0)) {
int bufs_idx = nb_bufs - total_tx_fail_count - 1;

for (i = 0; i < slave_count; i++) {
if (slave_tx_fail_count[i] > 0) {
for (j = 0; j < slave_tx_fail_count[i]; j++)
bufs[bufs_idx++] = slave_bufs[i][j];
}
total_tx_fail_count += slave_tx_fail_count;
memcpy(&bufs[nb_bufs - total_tx_fail_count],
&slave_bufs[i][slave_tx_count],
slave_tx_fail_count * sizeof(bufs[0]));
}
}

Expand Down Expand Up @@ -714,8 +692,8 @@ bond_ethdev_tx_burst_round_robin(void *queue, struct rte_mbuf **bufs,
tx_fail_total += tx_fail_slave;

memcpy(&bufs[nb_pkts - tx_fail_total],
&slave_bufs[i][num_tx_slave],
tx_fail_slave * sizeof(bufs[0]));
&slave_bufs[i][num_tx_slave],
tx_fail_slave * sizeof(bufs[0]));
}
num_tx_total += num_tx_slave;
}
Expand Down Expand Up @@ -1220,10 +1198,10 @@ bond_ethdev_tx_burst_balance(void *queue, struct rte_mbuf **bufs,
/* Mapping array generated by hash function to map mbufs to slaves */
uint16_t bufs_slave_port_idxs[nb_bufs];

uint16_t slave_tx_count, slave_tx_fail_count[RTE_MAX_ETHPORTS] = { 0 };
uint16_t slave_tx_count;
uint16_t total_tx_count = 0, total_tx_fail_count = 0;

uint16_t i, j;
uint16_t i;

if (unlikely(nb_bufs == 0))
return 0;
Expand Down Expand Up @@ -1264,34 +1242,12 @@ bond_ethdev_tx_burst_balance(void *queue, struct rte_mbuf **bufs,

/* If tx burst fails move packets to end of bufs */
if (unlikely(slave_tx_count < slave_nb_bufs[i])) {
slave_tx_fail_count[i] = slave_nb_bufs[i] -
int slave_tx_fail_count = slave_nb_bufs[i] -
slave_tx_count;
total_tx_fail_count += slave_tx_fail_count[i];

/*
* Shift bufs to beginning of array to allow reordering
* later
*/
for (j = 0; j < slave_tx_fail_count[i]; j++) {
slave_bufs[i][j] =
slave_bufs[i][(slave_tx_count - 1) + j];
}
}
}

/*
* If there are tx burst failures we move packets to end of bufs to
* preserve expected PMD behaviour of all failed transmitted being
* at the end of the input mbuf array
*/
if (unlikely(total_tx_fail_count > 0)) {
int bufs_idx = nb_bufs - total_tx_fail_count - 1;

for (i = 0; i < slave_count; i++) {
if (slave_tx_fail_count[i] > 0) {
for (j = 0; j < slave_tx_fail_count[i]; j++)
bufs[bufs_idx++] = slave_bufs[i][j];
}
total_tx_fail_count += slave_tx_fail_count;
memcpy(&bufs[nb_bufs - total_tx_fail_count],
&slave_bufs[i][slave_tx_count],
slave_tx_fail_count * sizeof(bufs[0]));
}
}

Expand All @@ -1318,10 +1274,10 @@ bond_ethdev_tx_burst_8023ad(void *queue, struct rte_mbuf **bufs,
/* Mapping array generated by hash function to map mbufs to slaves */
uint16_t bufs_slave_port_idxs[RTE_MAX_ETHPORTS] = { 0 };

uint16_t slave_tx_count, slave_tx_fail_count[RTE_MAX_ETHPORTS] = { 0 };
uint16_t slave_tx_count;
uint16_t total_tx_count = 0, total_tx_fail_count = 0;

uint16_t i, j;
uint16_t i;

if (unlikely(nb_bufs == 0))
return 0;
Expand Down Expand Up @@ -1379,39 +1335,13 @@ bond_ethdev_tx_burst_8023ad(void *queue, struct rte_mbuf **bufs,

/* If tx burst fails move packets to end of bufs */
if (unlikely(slave_tx_count < slave_nb_bufs[i])) {
slave_tx_fail_count[i] = slave_nb_bufs[i] -
int slave_tx_fail_count = slave_nb_bufs[i] -
slave_tx_count;
total_tx_fail_count += slave_tx_fail_count[i];

/*
* Shift bufs to beginning of array to allow
* reordering later
*/
for (j = 0; j < slave_tx_fail_count[i]; j++)
slave_bufs[i][j] =
slave_bufs[i]
[(slave_tx_count - 1)
+ j];
}
}
total_tx_fail_count += slave_tx_fail_count;

/*
* If there are tx burst failures we move packets to end of
* bufs to preserve expected PMD behaviour of all failed
* transmitted being at the end of the input mbuf array
*/
if (unlikely(total_tx_fail_count > 0)) {
int bufs_idx = nb_bufs - total_tx_fail_count - 1;

for (i = 0; i < slave_count; i++) {
if (slave_tx_fail_count[i] > 0) {
for (j = 0;
j < slave_tx_fail_count[i];
j++) {
bufs[bufs_idx++] =
slave_bufs[i][j];
}
}
memcpy(&bufs[nb_bufs - total_tx_fail_count],
&slave_bufs[i][slave_tx_count],
slave_tx_fail_count * sizeof(bufs[0]));
}
}
}
Expand Down

0 comments on commit 332dac0

Please sign in to comment.