8000 Move BearSSL from STACK_PROXY to a real, thunked 2nd stack by earlephilhower · Pull Request #5168 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

Move BearSSL from STACK_PROXY to a real, thunked 2nd stack #5168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
12e666e
Update to BearSSL 0.6+ release, add AES_CCM modes
earlephilhower Sep 25, 2018
167a11a
Merge branch 'master' into bssl0.6updt
earlephilhower Sep 25, 2018
f771d23
Merge branch 'master' into bssl0.6updt
d-a-v Sep 25, 2018
8fd3938
Enable the aes_ccm initialization in client/server
earlephilhower Sep 25, 2018
416660c
Initial attempt
earlephilhower Sep 25, 2018
ff9cbef
Working code with second stack thunking
earlephilhower Sep 26, 2018
edda69e
Remove #ifdefs in .S file, not needed.
earlephilhower Sep 26, 2018
3dfdfe9
Clean up thunks and remove separate stack flag
earlephilhower Sep 26, 2018
137ba8f
Fix PIO assembler errors
earlephilhower Sep 26, 2018
c34779b
Merge branch 'master' into thunks
earlephilhower Sep 26, 2018
40d17b5
Remove #ifdef code changes, ensure same code as PC
earlephilhower Sep 27, 2018
e908bc6
Merge branch 'thunks' of https://github.com/earlephilhower/Arduino in…
earlephilhower Sep 27, 2018
913b87e
Merge branch 'master' into thunks
earlephilhower Sep 27, 2018
d17fa23
Move to latest BearSSL w/EC progmem savings
earlephilhower Sep 27, 2018
37be1db
Merge with master
earlephilhower Sep 28, 2018
0ebf6e6
Merge branch 'master' of https://github.com/esp8266/Arduino into thunks
earlephilhower Sep 28, 2018
39b6d36
Merge branch 'master' into thunks
earlephilhower Sep 30, 2018
2f83ca9
Add br_thunk_* calls to do ref counting, painting
earlephilhower Sep 30, 2018
1789579
Merge branch 'master' into thunks
earlephilhower Oct 1, 2018
ec6ccdc
Add in postmortem stack dump hooks
earlephilhower Oct 1, 2018
bd4851a
Update stack dump to match decoder expectations
earlephilhower Oct 2, 2018
72362c7
Merge branch 'master' into thunks
earlephilhower Oct 2, 2018
5ee8015
Move thunk to code core for linkiage
earlephilhower Oct 2, 2018
5583696
Add 2nd stack dump utility routine
earlephilhower Oct 2, 2018
3e4de76
Merge branch 'master' into thunks
d-a-v Oct 8, 2018
e6bbf7f
Merge branch 'master' into thunks
earlephilhower Oct 27, 2018
a25f023
Refactor once more, update stack size, add stress
earlephilhower Oct 27, 2018
934f743
Merge branch 'master' into thunks
earlephilhower Oct 31, 2018
36d6fb2
Update to latest to-thunks branch
earlephilhower Oct 31, 2018
65962f4
Add BearSSL device test using stack stress
earlephilhower Oct 31, 2018
17f1548
Use bearssl/master branch, not /to-thunks branch
earlephilhower Oct 31, 2018
a499de2
Merge branch 'master' into thunks
earlephilhower Nov 12, 2018
717169b
Merge branch 'master' into thunks
devyte Nov 13, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add in postmortem stack dump hooks
When a crash occurs while in the second stack, dump the BSSL stack and
then also the stack that it was called from (either cont or sys).
  • Loading branch information
earlephilhower committed Oct 1, 2018
commit ec6ccdc507bc666c2fa982942202cdf08b070551
14 changes: 14 additions & 0 deletions cores/esp8266/core_esp8266_postmortem.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
#include "pgmspace.h"
#include "gdb_hooks.h"

// From BearSSLThunks.c
extern uint32_t br_thunk_get_stack_top();
extern uint32_t br_thunk_get_stack_bot();
extern uint32_t br_thunk_get_cont_sp();

extern void __real_system_restart_local();

// These will be pointers to PROGMEM const strings
Expand Down Expand Up @@ -147,6 +152,15 @@ void __wrap_system_restart_local() {
offset = 0x10;
}

if (sp > br_thunk_get_stack_bot() && sp <= br_thunk_get_stack_top()) {
// BearSSL we dump the BSSL second stack and then reset SP back to the main cont stack
ets_printf_P("\nctx: bearssl \n");
ets_printf_P("sp: %08x end: %08x offset: %04x\n", sp, br_thunk_get_stack_top(), offset);
print_stack(sp + offset, br_thunk_get_stack_top());
offset = 0; // No offset needed anymore, the exception info was stored in the bssl stack
sp = br_thunk_get_cont_sp();
}

if (sp > cont_stack_start && sp < cont_stack_end) {
ets_printf_P("\nctx: cont \n");
stack_end = cont_stack_end;
Expand Down
26 changes: 21 additions & 5 deletions libraries/ESP8266WiFi/src/BearSSLThunks.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@

static uint32_t *_stackPtr = NULL;
static uint32_t *_stackTop = NULL;
static uint32_t *_saveStack = NULL; /* Saved A1 while in BearSSL */
static uint32_t _refcnt = 0;

#define _stackSize (4500/4)
#define _stackSize (4600/4)
#define _stackPaint 0xdeadbeef

/* Add a reference, and allocate the stack if necessary */
8000 Expand All @@ -44,6 +45,7 @@ void br_thunk_add_ref()
for (int i=0; i < _stackSize; i++) {
_stackPtr[i] = _stackPaint;
}
_saveStack = NULL;
}
}

Expand All @@ -59,9 +61,27 @@ void br_thunk_del_ref()
free(_stackPtr);
_stackPtr = NULL;
_stackTop = NULL;
_saveStack = NULL;
}
}

/* Simple accessor functions used by postmortem */
uint32_t br_thunk_get_refcnt() {
return _refcnt;
}

uint32_t br_thunk_get_stack_top() {
return (uint32_t)_stackTop;
}

uint32_t br_thunk_get_stack_bot() {
return (uint32_t)_stackPtr;
}

uint32_t br_thunk_get_cont_sp() {
return (uint32_t)_saveStack;
}

/* Return the number of bytes ever used since the stack was created */
uint32_t br_thunk_get_max_usage()
{
Expand All @@ -79,10 +99,6 @@ uint32_t br_thunk_get_max_usage()
}

__asm("\n\
.data\n\
.align 4\n\
_saveStack: .word 0x00000000\n\
\n\
.text\n\
.literal_position\n\
\n\
Expand Down
5 changes: 5 additions & 0 deletions libraries/ESP8266WiFi/src/BearSSLThunks.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ extern "C" {

extern void br_thunk_add_ref();
extern void br_thunk_del_ref();

extern uint32_t br_thunk_get_refcnt();
extern uint32_t br_thunk_get_stack_top();
extern uint32_t br_thunk_get_stack_bot();
extern uint32_t br_thunk_get_cont_sp();
extern uint32_t br_thunk_get_max_usage();

extern unsigned char *thunk_br_ssl_engine_recvapp_buf( const br_ssl_engine_context *cc, size_t *len);
Expand Down
0