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: pad program units when writing record_header_t; ensure work buffer is large enough #13996

Merged
merged 4 commits into from
Dec 9, 2020

Conversation

LDong-Arm
Copy link
Contributor

Summary of changes

(Continuation of #13731)

When copying a TDB record header, we program whole program unit(s) as the underlying BlockDevice requires. Previously, we directly passed the address of the variable record_header_t header as the input buffer, but if the program size is larger than sizeof(record_header_t) (24 bytes), data beyond the variable (on the stack) gets programmed into the BlockDevice as a result. To fix this, this PR copies the record header variable into the zero-padded work buffer first, then writes the work buffer to the storage.

Additionally, this PR ensures the work buffer is at least the program size (this check was missing previously) and also no less than 64 byte. Note: To accommodate the record_header_t the minimum size is 24, but 64 bytes is what we had before and a power of 2.

#13731 also has small improvements to the TDBStoreModuleTest, which we carry forward to this PR.

Please see individual commits, as several changes are involved.

Impact of changes

No impact in terms of public API or functionality.

Migration actions required

None.

Documentation

None.


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

@ARMmbed/mbed-os-core


LDong-Arm and others added 4 commits December 2, 2020 14:57
Previously, when writing a record header into a TDBStore, we
took the pointer to the record_header_t variable as the input,
but used a program-aligned chunk size which is larger.
As a result, garbage from the stack memory gets written.

This commit fixes that by buffering the record header.

Co-authored-by: Seppo Takalo <seppo.takalo@arm.com>
Previously, we always set the work buffer to 64 bytes, without
checking it was no less the actual program size. But we can't
simply switch to use the program size for the work buffer,
because if it's too small (e.g. 1 byte in some cases), we
will not be able to read the status header (24 bytes), and
small buffers means more underlying write operations and
lower efficiency.

This PR changes the work buffer size to be the program size,
or 64 bytes as an absolute minimum like before.
Co-authored-by: Seppo Takalo <seppo.takalo@arm.com>
@ciarmcom ciarmcom added the release-type: patch Indentifies a PR as containing just a patch label Dec 2, 2020
@ciarmcom
Copy link
Member

ciarmcom commented Dec 2, 2020

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

@ciarmcom ciarmcom requested review from a team December 2, 2020 16:00
@@ -847,7 +847,10 @@ 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);
// The record header takes up whole program units
memset(_work_buf, 0, chunk_size);
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought that a check thatchunk_size is not greater than _work_buf_size was missing but I see that this is done in TDBStore::init()

@mergify mergify bot added needs: CI and removed needs: review labels Dec 7, 2020
@LDong-Arm
Copy link
Contributor Author

Either this or #13908 need to be rebased, when one of them is merged

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 9, 2020

CI started

@mbed-ci
Copy link

mbed-ci commented Dec 9, 2020

Jenkins CI Test : ✔️ SUCCESS

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_cmake-example-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-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-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-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-test ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️
jenkins-ci/mbed-os-ci_cloud-client-pytest ✔️

@0xc0170 0xc0170 merged commit b25e047 into ARMmbed:master Dec 9, 2020
@mergify mergify bot removed the ready for merge label Dec 9, 2020
@mbedmain mbedmain added release-version: 6.6.0 Release-pending and removed release-type: patch Indentifies a PR as containing just a patch Release-pending labels Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants