-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
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>
@LDong-Arm, thank you for your changes. |
@@ -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); |
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.
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()
Either this or #13908 need to be rebased, when one of them is merged |
CI started |
Jenkins CI Test : ✔️ SUCCESSBuild Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
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 thansizeof(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
Test results
Reviewers
@ARMmbed/mbed-os-core