Skip to content

KVStore: Fix buffer overrun when device key size doesn't match #12875

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
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions features/device_key/TESTS/device_key/functionality/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void generate_derived_key_consistency_16_byte_key_long_consistency_test(char *ke
int ret = inner_store->reset();
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);

ret = DeviceKey::get_instance().generate_root_of_trust();
ret = DeviceKey::get_instance().generate_root_of_trust(DEVICE_KEY_16BYTE);
if (ret != DEVICEKEY_SUCCESS) {
ret = inject_dummy_rot_key();
}
Expand Down Expand Up @@ -170,7 +170,7 @@ void generate_derived_key_consistency_32_byte_key_long_consistency_test(char *ke
int ret = inner_store->reset();
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);

ret = DeviceKey::get_instance().generate_root_of_trust();
ret = DeviceKey::get_instance().generate_root_of_trust(DEVICE_KEY_32BYTE);
if (ret != DEVICEKEY_SUCCESS) {
ret = inject_dummy_rot_key();
}
Expand Down Expand Up @@ -326,7 +326,7 @@ void generate_derived_key_consistency_16_byte_key_test()
int ret = inner_store->reset();
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);

ret = DeviceKey::get_instance().generate_root_of_trust();
ret = DeviceKey::get_instance().generate_root_of_trust(DEVICE_KEY_16BYTE);
if (ret != DEVICEKEY_SUCCESS) {
ret = inject_dummy_rot_key();
}
Expand Down Expand Up @@ -366,7 +366,7 @@ void generate_derived_key_consistency_32_byte_key_test()
int ret = inner_store->reset();
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);

ret = DeviceKey::get_instance().generate_root_of_trust();
ret = DeviceKey::get_instance().generate_root_of_trust(DEVICE_KEY_32BYTE);
if (ret != DEVICEKEY_SUCCESS) {
ret = inject_dummy_rot_key();
}
Expand Down Expand Up @@ -406,7 +406,7 @@ void generate_derived_key_key_type_16_test()
int ret = inner_store->reset();
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);

ret = DeviceKey::get_instance().generate_root_of_trust();
ret = DeviceKey::get_instance().generate_root_of_trust(DEVICE_KEY_16BYTE);
if (ret != DEVICEKEY_SUCCESS) {
ret = inject_dummy_rot_key();
}
Expand Down Expand Up @@ -442,7 +442,7 @@ void generate_derived_key_key_type_32_test()
int ret = inner_store->reset();
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);

ret = DeviceKey::get_instance().generate_root_of_trust();
ret = DeviceKey::get_instance().generate_root_of_trust(DEVICE_KEY_32BYTE);
if (ret != DEVICEKEY_SUCCESS) {
ret = inject_dummy_rot_key();
}
Expand Down
3 changes: 3 additions & 0 deletions features/storage/kvstore/tdbstore/TDBStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,9 @@ int TDBStore::do_reserved_data_get(void *reserved_data, size_t reserved_data_buf
if (crc == trailer.crc) {
// Correct data, copy it and return to caller
if (reserved_data) {
if (reserved_data_buf_size < trailer.data_size) {
return MBED_ERROR_INVALID_SIZE;
}
memcpy(reserved_data, buf, trailer.data_size);
}
if (actual_data_size) {
Expand Down