Skip to contentSkip to conversation

bnx2x: ethtool dump fixes

PATCH In review Michal Schmidt 2 participants 4 messages Jul 1, 2013 – Jul 2, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover bnx2x: ethtool dump fixes

This fixes a couple of crashers in bnx2x's ethtool dump implementation.

Michal Schmidt (2):
bnx2x: remove zeroing of dump data buffer
bnx2x: fix dump flag handling

 drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c | 5 +++--
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c    | 2 ++
 2 files changed, 5 insertions(+), 2 deletions(-)
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH 1/2 bnx2x: remove zeroing of dump data buffer

There is no need to initialize the dump data with zeros. data is allocated with vzalloc, so it's already zero-filled.

More importantly, the memset is harmful, because dump->len (the length requested by userspace) can be bigger than the allocated buffer (whose size is determined by asking the driver's .get_dump_flag method).

---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c | 2 --
 1 file changed, 2 deletions(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c +0 -2
index ce1a916..61ccae5 100644
@@ -986,8 +986,6 @@ static int bnx2x_get_dump_data(struct net_device *dev,
 	struct bnx2x *bp = netdev_priv(dev);
 	struct dump_header dump_hdr = {0};
 
-	memset(p, 0, dump->len);
-
 	/* Disable parity attentions as long as following dump may
 	 * cause false alarms by reading never written registers. We
 	 * will re-enable parity attentions right after the dump.
Signature · 1 line
1.8.1.4
#2 lore raw

PATCH 2/2 bnx2x: fix dump flag handling

In reply to Michal Schmidt

bnx2x interprets the dump flag as an index of a register preset. It is important to validate the index to avoid out of bounds memory accesses.

---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c | 3 +++
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c    | 2 ++
 2 files changed, 5 insertions(+)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c +3 -0
index 61ccae5..10b52b0 100644
@@ -960,6 +960,9 @@ static int bnx2x_set_dump(struct net_device *dev, struct ethtool_dump *val)
 	struct bnx2x *bp = netdev_priv(dev);
 
 	/* Use the ethtool_dump "flag" field as the dump preset index */
+	if (val->flag < 1 || val->flag > DUMP_MAX_PRESETS)
+		return -EINVAL;
+
 	bp->dump_preset_idx = val->flag;
 	return 0;
 }
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c +2 -0
index b4c9dea..2a9927f 100644
@@ -11497,6 +11497,8 @@ static int bnx2x_init_bp(struct bnx2x *bp)
 		bp->min_msix_vec_cnt = 2;
 	BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
 
+	bp->dump_preset_idx = 1;
+
 	return rc;
 }
 
Signature · 1 line
1.8.1.4