Skip to content
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

TDBStore: Must use work buffer with size of programming unit. #13731

Closed
wants to merge 1 commit into from

Conversation

SeppoTakalo
Copy link
Contributor

Summary of changes

In TDBStore::copy_record() we must prepare our content in
size of full programming unit. If we don't have big enough buffer
we end up writing garbage from our stack.

In most cases, this is prevent by usage of output buffer, but when
writing the record header, due the padding, we must write one full
programming unit.

Impact of changes

Migration actions required

Documentation


Pull request type

[X] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[X] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers


@ciarmcom ciarmcom added the release-type: patch Indentifies a PR as containing just a patch label Oct 7, 2020
@ciarmcom ciarmcom requested a review from a team October 7, 2020 10:00
@ciarmcom
Copy link
Member

ciarmcom commented Oct 7, 2020

@SeppoTakalo, thank you for your changes.
@ARMmbed/mbed-os-maintainers please review.

@0xc0170 0xc0170 requested a review from a team October 14, 2020 07:01
0xc0170
0xc0170 previously approved these changes Oct 14, 2020
@mergify mergify bot added needs: CI and removed needs: review labels Oct 14, 2020
evedon
evedon previously approved these changes Oct 14, 2020
@0xc0170
Copy link
Contributor

0xc0170 commented Oct 15, 2020

CI started

@mbed-ci
Copy link

mbed-ci commented Oct 15, 2020

Jenkins CI Test : ❌ FAILED

Build Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests
jenkins-ci/mbed-os-ci_build-ARM ✔️
jenkins-ci/mbed-os-ci_build-GCC_ARM ✔️

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 15, 2020

Unittests failed (TDBStore/moduletest.cpp), please review the logs

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 3, 2020

Unittests failed (TDBStore/moduletest.cpp), please review the logs

Please update the unittests or if not, someone else shall pick this up ?

In TDBStore::copy_record() we must prepare our content in
size of full programming unit. If we don't have big enough buffer
we end up writing garbage from our stack.

In most cases, this is prevent by usage of output buffer, but when
writing the record header, due the padding, we must write one full
programming unit.
@mergify mergify bot dismissed stale reviews from 0xc0170 and evedon November 9, 2020 09:25

Pull request has been modified.

@SeppoTakalo
Copy link
Contributor Author

PR updated. Found a bug in the PR, fixed it.

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 12, 2020

CI started

@mbed-ci
Copy link

mbed-ci commented Nov 12, 2020

Jenkins CI Test : ❌ FAILED

Build Number: 2 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_dynamic-memory-usage ✔️
jenkins-ci/mbed-os-ci_cloud-client-pytest
jenkins-ci/mbed-os-ci_cmake-example-test
jenkins-ci/mbed-os-ci_greentea-test

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 30, 2020

I restarted tests.

@ARMmbed/mbed-os-core would you be able to take over?

@mbed-ci
Copy link

mbed-ci commented Nov 30, 2020

Jenkins CI Test : ❌ FAILED

Build Number: 3 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_dynamic-memory-usage
jenkins-ci/mbed-os-ci_cmake-example-test ✔️
jenkins-ci/mbed-os-ci_greentea-test
jenkins-ci/mbed-os-ci_cloud-client-pytest ✔️

@evedon
Copy link
Contributor

evedon commented Dec 1, 2020

I restarted tests.

@ARMmbed/mbed-os-core would you be able to take over?

@LDong-Arm is taking over

Copy link
Contributor

@LDong-Arm LDong-Arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments are for our own record, I'll raise a separate PR

@@ -824,17 +823,19 @@ int TDBStore::copy_record(uint8_t from_area, uint32_t from_offset, uint32_t to_o
uint32_t &to_next_offset)
{
int ret;
record_header_t header;
record_header_t *header = (record_header_t *) _work_buf;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no guarantee _work_buf is large enough

@@ -1041,7 +1042,7 @@ int TDBStore::init()
}

_prog_size = _bd->get_program_size();
_work_buf = new uint8_t[work_buf_size];
_work_buf = new uint8_t[_prog_size];
Copy link
Contributor

@LDong-Arm LDong-Arm Dec 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, we read record_header_t (a 32-bit aligned struct of size 24 bytes) into _work_buff, but

  • here it's only 8-bit aligned
  • the program size can be less than that - some flashes can be programmed to 1-byte, in which case the buffer is insufficient

This could be why the Greentea test failed and hard faulted.

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 1, 2020

OK, I'll close this one now.

@0xc0170 0xc0170 closed this Dec 1, 2020
@mergify mergify bot removed needs: work release-type: patch Indentifies a PR as containing just a patch labels Dec 1, 2020
@@ -847,7 +848,7 @@ int TDBStore::copy_record(uint8_t from_area, uint32_t from_offset, uint32_t to_o
}

chunk_size = align_up(sizeof(record_header_t), _prog_size);
ret = write_area(1 - from_area, to_offset, chunk_size, &header);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I get that this is what the PR intended to fix

LDong-Arm added a commit to LDong-Arm/mbed-os that referenced this pull request Dec 2, 2020
Co-authored-by: Seppo Takalo <seppo.takalo@arm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants