Understanding/Debugging Stack Smashing
Posted: Thu Aug 02, 2018 7:39 pm
I have configured with extensive stack smashing and gdbstub on panic. On startup, as I launch various tasks I get stack smashing panic on WiFi.begin:
If my understanding is correct, with "strong" stack smashing it places canaries at the end of each function's stack space and upon return checks to make sure the canary value is not overwritten, and the trace is showing that WiFiGenericClass::getMode() is somehow overwriting the bounds of its stack (which I find hard to believe). In any case, the stack for that function starts at 0x3ffc29a0 and moves downward. So I should be able to inspect the stack from the backtrace:
Ignoring the panic code, the method of interest is at address 0x400fadbf, which has a stack address starting at 0x3ffc29a0. Looking at stack around there:
And .... I'm stuck - now I don't know what to do with that. I would have thought that I would see the address of the instruction it's returning to, then some values, then the canary bytes but I'm stuck interpreting this.
Code: Select all
I (2742) wifi: Init dynamic tx buffer num: 32
I (2742) wifi: Init data frame dynamic rx buffer num: 64
I (2745) wifi: Init management frame dynamic rx buffer num: 64
I (2751) wifi: wifi driver task: 3ffc80f4, prio:23, stack:3584
I (2756) wifi: Init static rx buffer num: 5
I (2760) wifi: Init dynamic rx buffer num: 0
I (2764) wifi: wifi power manager task: 0x3ffcaf68 prio: 21 stack: 2560
Stack smashing protect failure!
abort() was called at PC 0x400d309c on core 0
0x400d309c: __stack_chk_fail at /dev/projA/Firmware/esp-idf/components/esp32/./stack_check.c:36
Backtrace: 0x4008a670:0x3ffc2940 0x4008a73b:0x3ffc2960 0x400d309c:0x3ffc2980 0x400fadbf:0x3ffc29a0 0x400fb096:0x3ffc29d0 0x400fb39d:0x3ffc29f0 0x400d6c35:0x3ffc2b10 0x400d7127:0x3ffc2b30
0x4008a670: invoke_abort at /dev/projA/Firmware/esp-idf/components/esp32/./panic.c:572
0x4008a73b: abort at /dev/projA/Firmware/esp-idf/components/esp32/./panic.c:572
0x400d309c: __stack_chk_fail at /dev/projA/Firmware/esp-idf/components/esp32/./stack_check.c:36
0x400fadbf: WiFiGenericClass::getMode() at /dev/projA/Firmware/solsense_esp32/components/arduino-esp32/libraries/WiFi/src//WiFiGeneric.cpp:517
0x400fb096: WiFiGenericClass::enableSTA(bool) at /dev/projA/Firmware/solsense_esp32/components/arduino-esp32/libraries/WiFi/src//WiFiGeneric.cpp:517
0x400fb39d: WiFiSTAClass::begin(char const*, char const*, int, unsigned char const*, bool) at /dev/projA/Firmware/solsense_esp32/components/arduino-esp32/libraries/WiFi/src//WiFiSTA.cpp:604
0x400d6c35: wifi_init() at /dev/projA/Firmware/solsense_esp32/main/./connection_manager.cpp:236
0x400d7127: connection_manager(void*) at /dev/projA/Firmware/solsense_esp32/main/./connection_manager.cpp:1128
Entering gdb stub now.
$T0b#e6GNU gdb (crosstool-NG crosstool-ng-1.22.0-80-g6c4433a) 7.10
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-build_apple-darwin16.3.0 --target=xtensa-esp32-elf".
Code: Select all
Backtrace: 0x4008a670:0x3ffc2940 0x4008a73b:0x3ffc2960 0x400d309c:0x3ffc2980 0x400fadbf:0x3ffc29a0 0x400fb096:0x3ffc29d0 0x400fb39d:0x3ffc29f0 0x400d6c35:0x3ffc2b10 0x400d7127:0x3ffc2b30
Code: Select all
(gdb) x/20x 0x3ffc2980
0x3ffc2980: 0x00000000 0x3ffc2360 0x3ffc2360 0x00000003
0x3ffc2990: 0x800fb3a0 0x3ffc29d0 0x3ffb4428 0x00000001
0x3ffc29a0: 0xa5a5a5a5 0xa5a5a5a5 0x00a5a5a5 0x2c000000
0x3ffc29b0: 0x3ffc2690 0x0000000c 0x00000000 0xff000000
0x3ffc29c0: 0x800d6c38 0x3ffc29f0 0x3ffb4428 0x3f4039cc