-
Notifications
You must be signed in to change notification settings - Fork 29
Restore the stack canary #1273
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
base: master
Are you sure you want to change the base?
Restore the stack canary #1273
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,9 +48,6 @@ | |
| /* Private defines------------------------------------------------------------*/ | ||
|
|
||
| /* Private macros-------------------------------------------------------------*/ | ||
| #ifdef HAVE_BOLOS_APP_STACK_CANARY | ||
| #define APP_STACK_CANARY_MAGIC 0xDEAD0031 | ||
| #endif // HAVE_BOLOS_APP_STACK_CANARY | ||
|
Comment on lines
-51
to
-53
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll need to check if this causes issues with some applications still using legacy IO and the canary
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing should change for them. These are moved in |
||
|
|
||
|
iartemov-ledger marked this conversation as resolved.
|
||
| /* Private functions prototypes ----------------------------------------------*/ | ||
| #ifdef HAVE_NFC_READER | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,10 @@ | |
| #include "os_endorsement.h" | ||
| #include <string.h> | ||
|
|
||
| #ifdef HAVE_BOLOS_APP_STACK_CANARY | ||
| extern unsigned int app_stack_canary; | ||
| #endif // HAVE_BOLOS_APP_STACK_CANARY | ||
|
|
||
| unsigned int SVC_Call(unsigned int syscall_id, void *parameters); | ||
| unsigned int SVC_cx_call(unsigned int syscall_id, unsigned int *parameters); | ||
|
|
||
|
|
@@ -1865,6 +1869,10 @@ int os_io_seph_se_rx_event(unsigned char *buffer, | |
|
|
||
| __attribute((weak)) int os_io_init(os_io_init_t *init) | ||
| { | ||
| #ifdef HAVE_BOLOS_APP_STACK_CANARY | ||
| app_stack_canary = APP_STACK_CANARY_MAGIC; | ||
| #endif // HAVE_BOLOS_APP_STACK_CANARY | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to not modify the syscall APIs.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the syscalls APIs are the only place used for io for most apps (that is, after io revamp and defining (I chose
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Syscalls are not called directly by apps, there is SDK functions that can be used. Let's discuss to find a better solution. |
||
| unsigned int parameters[1]; | ||
| parameters[0] = (unsigned int) init; | ||
| return (int) SVC_Call(SYSCALL_os_io_init_ID, parameters); | ||
|
|
@@ -1889,6 +1897,13 @@ __attribute((weak)) int os_io_tx_cmd(unsigned char type, | |
| unsigned short length, | ||
| unsigned int *timeout_ms) | ||
| { | ||
| #ifdef HAVE_BOLOS_APP_STACK_CANARY | ||
| // if the canary is corrupted, reset the device | ||
| if (app_stack_canary != APP_STACK_CANARY_MAGIC) { | ||
| os_sched_exit(APP_STACK_CANARY_CORRUPTED_EXIT_VALUE); | ||
| } | ||
| #endif | ||
|
Comment on lines
+1900
to
+1905
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can factorize this snippet
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was worried about introducing an additional function because if we know the stack is already corrupted, we should use it as little as possible. |
||
|
|
||
| unsigned int parameters[4]; | ||
| parameters[0] = (unsigned int) type; | ||
| parameters[1] = (unsigned int) buffer; | ||
|
|
@@ -1902,6 +1917,13 @@ __attribute((weak)) int os_io_rx_evt(unsigned char *buffer, | |
| unsigned int *timeout_ms, | ||
| bool check_se_event) | ||
| { | ||
| #ifdef HAVE_BOLOS_APP_STACK_CANARY | ||
| // if the canary is corrupted, reset the device | ||
| if (app_stack_canary != APP_STACK_CANARY_MAGIC) { | ||
| os_sched_exit(APP_STACK_CANARY_CORRUPTED_EXIT_VALUE); | ||
| } | ||
| #endif | ||
|
|
||
| unsigned int parameters[4]; | ||
| parameters[0] = (unsigned int) buffer; | ||
| parameters[1] = (unsigned int) buffer_max_length; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the perfect world it should be automatically tested against an app with and without legacy IO stack.
But we do not seem to have an infrastructure for this.
Might be https://github.com/LedgerHQ/speculos/tree/master/tests/c, but also it does not seem to fit.