Skip to content

Commit cf8f68c

Browse files
authored
Merge pull request #21 from blooo-io/fix/address-ledger-audit-vuln
Fix: address Ledger's audit vulnerabilities
2 parents 50b42c2 + 6b22bc5 commit cf8f68c

File tree

13 files changed

+48
-13
lines changed

13 files changed

+48
-13
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ doc/latex
3838

3939
tests/snapshots-tmp
4040
tests/bitcoin
41+
42+
.DS_Store

.vscode/settings.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"C_Cpp.clang_format_path": "/usr/bin/clang-format",
66
"editor.formatOnSave": true,
77
"ledgerDevTools.appSettings": {
8-
"selectedUseCase": "release"
9-
}
8+
"selectedUseCase": "release",
9+
"selectedDevice": "Nano S Plus",
10+
"selectedVariant": "acre_testnet"
11+
},
12+
"makefile.configureOnOpen": false
1013
}

Makefile

+5-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ PATH_APP_LOAD_PARAMS = "44'/0'" "44'/1'" "48'/0'" "48'/1'" "49'/0'" "49'/1'" "84
4545
# Application version
4646
APPVERSION_M = 1
4747
APPVERSION_N = 1
48-
APPVERSION_P = 1
48+
APPVERSION_P = 2
4949
APPVERSION_SUFFIX = # if not empty, appended at the end. Do not add a dash.
5050

5151
ifeq ($(APPVERSION_SUFFIX),)
@@ -158,8 +158,6 @@ DEFINES += HAVE_BOLOS_APP_STACK_CANARY
158158

159159
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=300
160160

161-
# debugging helper functions and macros
162-
CFLAGS += -g -include debug-helpers/debug.h
163161

164162
# DEFINES += HAVE_PRINT_STACK_POINTER
165163

@@ -169,6 +167,10 @@ ifeq ($(DEBUG),10)
169167
DEFINES += HAVE_PRINTF HAVE_SEMIHOSTED_PRINTF PRINTF=semihosted_printf
170168
endif
171169

170+
ifeq ($(DEBUG),1)
171+
# debugging helper functions and macros
172+
CFLAGS += -include debug-helpers/debug.h -g
173+
endif
172174
# Needed to be able to include the definition of G_cx
173175
INCLUDES_PATH += $(BOLOS_SDK)/lib_cxng/src
174176

src/debug-helpers/debug.c

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <stdio.h>
22
#include <stdarg.h>
33
#include "printf.h"
4+
#include "debug.h"
45

56
#pragma GCC diagnostic ignored "-Wunused-function"
67

src/handler/lib/get_merkle_preimage.c

+14-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ int call_get_merkle_preimage(dispatcher_context_t *dispatcher_context,
6363
cx_sha256_init(&hash_context);
6464

6565
// update hash
66-
crypto_hash_update(&hash_context.header, data_ptr, partial_data_len);
66+
int ret = cx_hash_no_throw(&hash_context.header, 0, data_ptr, partial_data_len, NULL, 0);
67+
if (ret != 0) {
68+
PRINTF("Error updating hash\n");
69+
return -11;
70+
}
6771

6872
buffer_t out_buffer = buffer_create(out_ptr, out_ptr_len);
6973

@@ -98,10 +102,17 @@ int call_get_merkle_preimage(dispatcher_context_t *dispatcher_context,
98102
}
99103

100104
// update hash
101-
crypto_hash_update(
105+
ret = cx_hash_no_throw(
102106
&hash_context.header,
107+
0,
103108
dispatcher_context->read_buffer.ptr + dispatcher_context->read_buffer.offset,
104-
n_bytes);
109+
n_bytes,
110+
NULL,
111+
0);
112+
if (ret != 0) {
113+
PRINTF("Error updating hash\n");
114+
return -12;
115+
}
105116

106117
// write bytes to output
107118
buffer_write_bytes(&out_buffer, data_ptr, n_bytes);

src/handler/sign_erc4361_message.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,14 @@ void handler_sign_erc4361_message(dispatcher_context_t *dc, uint8_t protocol_ver
311311
}
312312
// # Format signature into standard bitcoin format
313313
int r_length = sig[3];
314-
int s_length = sig[4 + r_length + 1];
314+
if (r_length < 0 || r_length > 33) {
315+
SAFE_SEND_SW(dc, SW_BAD_STATE); // can never happen
316+
ui_post_processing_confirm_message(dc, false);
317+
return;
318+
}
315319

316-
if (r_length > 33 || s_length > 33) {
320+
int s_length = sig[4 + r_length + 1];
321+
if (s_length < 0 || s_length > 33) {
317322
SAFE_SEND_SW(dc, SW_BAD_STATE); // can never happen
318323
ui_post_processing_confirm_message(dc, false);
319324
return;

src/handler/withdraw.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,18 @@ static bool display_data_content_and_confirm(dispatcher_context_t* dc,
183183
snprintf(value_with_ticker, sizeof(value_with_ticker), "stBTC %s", value);
184184

185185
// Trim the value of trailing zeros in a char of size of value
186-
int i = sizeof(value_with_ticker) - 1;
186+
int value_with_ticker_len = sizeof(value_with_ticker) - 1;
187+
int i = value_with_ticker_len;
187188
while (value_with_ticker[i] == '0' || value_with_ticker[i] == '\0' ||
188189
value_with_ticker[i] == '.') {
190+
if (i == 0) {
191+
break;
192+
}
189193
i--;
190194
}
191-
value_with_ticker[i + 1] = '\0';
195+
if (i < value_with_ticker_len) {
196+
value_with_ticker[i + 1] = '\0';
197+
}
192198
// Get the second chunk that contains the data to display
193199
call_get_merkle_leaf_element(dc,
194200
data_merkle_root,
@@ -264,6 +270,10 @@ void add_leading_zeroes(uint8_t* dest_buffer,
264270
PRINTF("Error: Null buffer\n");
265271
return;
266272
}
273+
if (dest_size < src_size) {
274+
PRINTF("Error: Destination buffer is too small\n");
275+
return;
276+
}
267277
// Clear the destination buffer
268278
memset(dest_buffer, 0, dest_size);
269279

src/swap/handle_get_printable_amount.c

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <string.h>
22
#include <stdint.h>
3+
#include "debug-helpers/debug.h"
34

45
#include "handle_get_printable_amount.h"
56

src/ui/menu_nbgl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#define SETTING_INFO_NB 3
2525
static const char* const INFO_TYPES[SETTING_INFO_NB] = {"Version", "Developer", "Copyright"};
26-
static const char* const INFO_CONTENTS[SETTING_INFO_NB] = {APPVERSION, "Blooo", "(c) 2024 Blooo"};
26+
static const char* const INFO_CONTENTS[SETTING_INFO_NB] = {APPVERSION, "Acre", "(c) 2024 Acre"};
2727

2828
static const nbgl_contentInfoList_t infoList = {
2929
.nbInfos = SETTING_INFO_NB,
464 Bytes
Loading
28 Bytes
Loading
28 Bytes
Loading
385 Bytes
Loading

0 commit comments

Comments
 (0)