-
Notifications
You must be signed in to change notification settings - Fork 147
Multiple fixes: buffer bound checks #721
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?
Changes from all commits
45749ed
68a1b01
0365eb7
3e07cbe
d3ff22e
1c6ee12
3153775
9194129
45eaf6f
ff20310
927b8c9
73a10e5
1b54481
83091e5
8b78a31
d1ab9eb
ab52d52
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 |
|---|---|---|
|
|
@@ -98,8 +98,9 @@ char *strcat(char *dest, const char *src) | |
| { | ||
| size_t i = 0; | ||
| size_t j = strlen(dest); | ||
| size_t src_len = strlen(src); | ||
|
|
||
| for (i = 0; i < strlen(src); i++) { | ||
| for (i = 0; i < src_len; i++) { | ||
| dest[j++] = src[i]; | ||
| } | ||
| dest[j] = '\0'; | ||
|
|
@@ -186,6 +187,10 @@ char *strncpy(char *dst, const char *src, size_t n) | |
| break; | ||
| } | ||
|
|
||
| while (++i < n) { | ||
| dst[i] = '\0'; | ||
| } | ||
|
Comment on lines
+190
to
+192
|
||
|
|
||
| return dst; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,6 +134,9 @@ static uint32_t get_decrypted_blob_version(uint8_t *hdr) | |
| continue; | ||
| } | ||
|
|
||
| if (p + 4 + tlv_len > max_p) | ||
| break; | ||
|
Comment on lines
+137
to
+138
|
||
|
|
||
| if (tlv_type == HDR_VERSION && tlv_len == 4) { | ||
| uint32_t ver = *((uint32_t*)(p + 4)); | ||
| return ver; | ||
|
Comment on lines
134
to
142
|
||
|
|
@@ -208,6 +211,12 @@ static int decrypt_header(const uint8_t *src, uint8_t *dst) | |
| return 0; | ||
| } | ||
|
|
||
| static void disk_crypto_clear(void) | ||
| { | ||
| ForceZero(disk_encrypt_key, sizeof(disk_encrypt_key)); | ||
| ForceZero(disk_encrypt_nonce, sizeof(disk_encrypt_nonce)); | ||
| } | ||
|
|
||
| #endif /* DISK_ENCRYPT */ | ||
|
|
||
| extern int wolfBoot_get_dts_size(void *dts_addr); | ||
|
|
@@ -254,11 +263,13 @@ void RAMFUNCTION wolfBoot_start(void) | |
| #ifdef DISK_ENCRYPT | ||
| /* Initialize encryption - this sets up the cipher with key from storage */ | ||
| if (wolfBoot_initialize_encryption() != 0) { | ||
| disk_crypto_clear(); | ||
| wolfBoot_printf("Error initializing encryption\r\n"); | ||
| wolfBoot_panic(); | ||
| } | ||
| /* Retrieve encryption key and nonce for disk decryption */ | ||
| if (wolfBoot_get_encrypt_key(disk_encrypt_key, disk_encrypt_nonce) != 0) { | ||
| disk_crypto_clear(); | ||
| wolfBoot_printf("Error getting encryption key\r\n"); | ||
| wolfBoot_panic(); | ||
| } | ||
|
|
@@ -267,10 +278,16 @@ void RAMFUNCTION wolfBoot_start(void) | |
|
|
||
| ret = disk_init(BOOT_DISK); | ||
| if (ret != 0) { | ||
| #ifdef DISK_ENCRYPT | ||
| disk_crypto_clear(); | ||
| #endif | ||
| wolfBoot_panic(); | ||
| } | ||
|
|
||
| if (disk_open(BOOT_DISK) < 0) { | ||
| #ifdef DISK_ENCRYPT | ||
| disk_crypto_clear(); | ||
| #endif | ||
| wolfBoot_printf("Error opening disk %d\r\n", BOOT_DISK); | ||
| wolfBoot_panic(); | ||
| } | ||
|
|
@@ -306,6 +323,9 @@ void RAMFUNCTION wolfBoot_start(void) | |
| } | ||
|
|
||
| if ((pB_ver == 0) && (pA_ver == 0)) { | ||
| #ifdef DISK_ENCRYPT | ||
| disk_crypto_clear(); | ||
| #endif | ||
| wolfBoot_printf("No valid OS image found in either partition %d or %d\r\n", | ||
| BOOT_PART_A, BOOT_PART_B); | ||
| wolfBoot_panic(); | ||
|
|
@@ -409,6 +429,7 @@ void RAMFUNCTION wolfBoot_start(void) | |
| wolfBoot_printf("Decrypting image..."); | ||
| BENCHMARK_START(); | ||
| if ((IMAGE_HEADER_SIZE % ENCRYPT_BLOCK_SIZE) != 0) { | ||
| disk_crypto_clear(); | ||
| wolfBoot_printf("Encrypted disk images require aligned header size\r\n"); | ||
| wolfBoot_panic(); | ||
| } | ||
|
|
@@ -456,6 +477,9 @@ void RAMFUNCTION wolfBoot_start(void) | |
| } while (failures < MAX_FAILURES); | ||
|
|
||
| if (failures) { | ||
| #ifdef DISK_ENCRYPT | ||
| disk_crypto_clear(); | ||
| #endif | ||
| wolfBoot_printf("Unable to find a valid partition!\r\n"); | ||
| wolfBoot_panic(); | ||
| } | ||
|
|
@@ -512,6 +536,9 @@ void RAMFUNCTION wolfBoot_start(void) | |
|
|
||
| #ifdef WOLFBOOT_HOOK_BOOT | ||
| wolfBoot_hook_boot(&os_image); | ||
| #endif | ||
| #ifdef DISK_ENCRYPT | ||
| disk_crypto_clear(); | ||
| #endif | ||
| do_boot((uint32_t*)load_address | ||
| #ifdef MMU | ||
|
|
||
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.
The format string uses
%dbut the arguments are cast tounsigned int. For correctness (and to avoid confusing negative output for large values), use%u(or a fixed-width format viaPRIu32with an appropriate cast).