Skip to content

Commit

Permalink
app/testpmd: fix stack overflow for EEPROM display
Browse files Browse the repository at this point in the history
[ upstream commit ff6db88 ]

When the size of EEPROM exceeds the default thread stack size(8MB),
e.g.: 10MB size, it will crash due to stack overflow.

Allocate the data of EPPROM information on the heap.

Fixes: 6b67721 ("app/testpmd: add EEPROM command")

Signed-off-by: Steve Yang <stevex.yang@intel.com>
Acked-by: Aman Singh <aman.deep.singh@intel.com>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
  • Loading branch information
Steve Yang authored and bluca committed Feb 17, 2022
1 parent aea2c5b commit 58767a9
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions app/test-pmd/config.c
Expand Up @@ -797,10 +797,15 @@ port_eeprom_display(portid_t port_id)
return;
}

char buf[len_eeprom];
einfo.offset = 0;
einfo.length = len_eeprom;
einfo.data = buf;
einfo.data = calloc(1, len_eeprom);
if (!einfo.data) {
fprintf(stderr,
"Allocation of port %u eeprom data failed\n",
port_id);
return;
}

ret = rte_eth_dev_get_eeprom(port_id, &einfo);
if (ret != 0) {
Expand All @@ -818,10 +823,12 @@ port_eeprom_display(portid_t port_id)
printf("Unable to get EEPROM: %d\n", ret);
break;
}
free(einfo.data);
return;
}
rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
printf("Finish -- Port: %d EEPROM length: %d bytes\n", port_id, len_eeprom);
free(einfo.data);
}

void
Expand Down Expand Up @@ -856,10 +863,15 @@ port_module_eeprom_display(portid_t port_id)
return;
}

char buf[minfo.eeprom_len];
einfo.offset = 0;
einfo.length = minfo.eeprom_len;
einfo.data = buf;
einfo.data = calloc(1, minfo.eeprom_len);
if (!einfo.data) {
fprintf(stderr,
"Allocation of port %u eeprom data failed\n",
port_id);
return;
}

ret = rte_eth_dev_get_module_eeprom(port_id, &einfo);
if (ret != 0) {
Expand All @@ -877,11 +889,13 @@ port_module_eeprom_display(portid_t port_id)
printf("Unable to get module EEPROM: %d\n", ret);
break;
}
free(einfo.data);
return;
}

rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
printf("Finish -- Port: %d MODULE EEPROM length: %d bytes\n", port_id, einfo.length);
free(einfo.data);
}

void
Expand Down

0 comments on commit 58767a9

Please sign in to comment.