From 58767a90f4b169d62b4e42086473bec562ed3ab7 Mon Sep 17 00:00:00 2001 From: Steve Yang Date: Thu, 20 Jan 2022 02:59:31 +0000 Subject: [PATCH] app/testpmd: fix stack overflow for EEPROM display [ upstream commit ff6db8829678396d2d10b3c29744d36149608982 ] 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: 6b67721dee2a ("app/testpmd: add EEPROM command") Signed-off-by: Steve Yang Acked-by: Aman Singh Tested-by: Ferruh Yigit --- app/test-pmd/config.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 8e37602f6b..abe2cc394c 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -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) { @@ -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 @@ -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) { @@ -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