Skip to content

Commit d7241f6

Browse files
hvenevPaolo Abeni
authored andcommitted
be2net: Fix buffer overflow in be_get_module_eeprom
be_cmd_read_port_transceiver_data assumes that it is given a buffer that is at least PAGE_DATA_LEN long, or twice that if the module supports SFF 8472. However, this is not always the case. Fix this by passing the desired offset and length to be_cmd_read_port_transceiver_data so that we only copy the bytes once. Fixes: e36edd9 ("be2net: add ethtool "-m" option support") Signed-off-by: Hristo Venev <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent da791ba commit d7241f6

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

drivers/net/ethernet/emulex/benet/be_cmds.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,7 +2287,7 @@ int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
22872287

22882288
/* Uses sync mcc */
22892289
int be_cmd_read_port_transceiver_data(struct be_adapter *adapter,
2290-
u8 page_num, u8 *data)
2290+
u8 page_num, u32 off, u32 len, u8 *data)
22912291
{
22922292
struct be_dma_mem cmd;
22932293
struct be_mcc_wrb *wrb;
@@ -2321,10 +2321,10 @@ int be_cmd_read_port_transceiver_data(struct be_adapter *adapter,
23212321
req->port = cpu_to_le32(adapter->hba_port_num);
23222322
req->page_num = cpu_to_le32(page_num);
23232323
status = be_mcc_notify_wait(adapter);
2324-
if (!status) {
2324+
if (!status && len > 0) {
23252325
struct be_cmd_resp_port_type *resp = cmd.va;
23262326

2327-
memcpy(data, resp->page_data, PAGE_DATA_LEN);
2327+
memcpy(data, resp->page_data + off, len);
23282328
}
23292329
err:
23302330
mutex_unlock(&adapter->mcc_lock);
@@ -2415,7 +2415,7 @@ int be_cmd_query_cable_type(struct be_adapter *adapter)
24152415
int status;
24162416

24172417
status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
2418-
page_data);
2418+
0, PAGE_DATA_LEN, page_data);
24192419
if (!status) {
24202420
switch (adapter->phy.interface_type) {
24212421
case PHY_TYPE_QSFP:
@@ -2440,7 +2440,7 @@ int be_cmd_query_sfp_info(struct be_adapter *adapter)
24402440
int status;
24412441

24422442
status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
2443-
page_data);
2443+
0, PAGE_DATA_LEN, page_data);
24442444
if (!status) {
24452445
strlcpy(adapter->phy.vendor_name, page_data +
24462446
SFP_VENDOR_NAME_OFFSET, SFP_VENDOR_NAME_LEN - 1);

drivers/net/ethernet/emulex/benet/be_cmds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2427,7 +2427,7 @@ int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num, u8 beacon,
24272427
int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num,
24282428
u32 *state);
24292429
int be_cmd_read_port_transceiver_data(struct be_adapter *adapter,
2430-
u8 page_num, u8 *data);
2430+
u8 page_num, u32 off, u32 len, u8 *data);
24312431
int be_cmd_query_cable_type(struct be_adapter *adapter);
24322432
int be_cmd_query_sfp_info(struct be_adapter *adapter);
24332433
int lancer_cmd_read_object(struct be_adapter *adapter, struct be_dma_mem *cmd,

drivers/net/ethernet/emulex/benet/be_ethtool.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ static int be_get_module_info(struct net_device *netdev,
13441344
return -EOPNOTSUPP;
13451345

13461346
status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
1347-
page_data);
1347+
0, PAGE_DATA_LEN, page_data);
13481348
if (!status) {
13491349
if (!page_data[SFP_PLUS_SFF_8472_COMP]) {
13501350
modinfo->type = ETH_MODULE_SFF_8079;
@@ -1362,25 +1362,32 @@ static int be_get_module_eeprom(struct net_device *netdev,
13621362
{
13631363
struct be_adapter *adapter = netdev_priv(netdev);
13641364
int status;
1365+
u32 begin, end;
13651366

13661367
if (!check_privilege(adapter, MAX_PRIVILEGES))
13671368
return -EOPNOTSUPP;
13681369

1369-
status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
1370-
data);
1371-
if (status)
1372-
goto err;
1370+
begin = eeprom->offset;
1371+
end = eeprom->offset + eeprom->len;
1372+
1373+
if (begin < PAGE_DATA_LEN) {
1374+
status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0, begin,
1375+
min_t(u32, end, PAGE_DATA_LEN) - begin,
1376+
data);
1377+
if (status)
1378+
goto err;
1379+
1380+
data += PAGE_DATA_LEN - begin;
1381+
begin = PAGE_DATA_LEN;
1382+
}
13731383

1374-
if (eeprom->offset + eeprom->len > PAGE_DATA_LEN) {
1375-
status = be_cmd_read_port_transceiver_data(adapter,
1376-
TR_PAGE_A2,
1377-
data +
1378-
PAGE_DATA_LEN);
1384+
if (end > PAGE_DATA_LEN) {
1385+
status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A2,
1386+
begin - PAGE_DATA_LEN,
1387+
end - begin, data);
13791388
if (status)
13801389
goto err;
13811390
}
1382-
if (eeprom->offset)
1383-
memcpy(data, data + eeprom->offset, eeprom->len);
13841391
err:
13851392
return be_cmd_status(status);
13861393
}

0 commit comments

Comments
 (0)