-
Notifications
You must be signed in to change notification settings - Fork 8.2k
[mcumgr] Increment data_off after reading the SHA
#98347
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
[mcumgr] Increment data_off after reading the SHA
#98347
Conversation
|
Hello @skalldri, and thank you very much for your first pull request to the Zephyr project! |
|
Background: I discovered this issue while developing a "simulated flash" driver for the Nordic NRF5340. On the Nordic NRF5340, the However, this doesn't allow MCUMgr to read information about the network core image. To support this, I've been developing my own simulated flash driver that detects reads to the MCUboot header / TLV regions and returns simulated headers and TLVs, rather than reading junk data from RAM. This driver is very strict about what addresses it will allow reads to, and it detected invalid reads (ex: attempting to read the SHA data as a TLV) from the MCUMgr subsystem. I was then quickly able to discover this issue. |
2b1a970 to
0581382
Compare
Fix a bug where the image's SHA would be interpreted as TLV headers due to missing a data_off increment. Signed-off-by: Stuart Alldritt <[email protected]>
0581382 to
bada5d1
Compare
|
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.
From my understanding, the offset computation should only happen when hash!=NULL. Or am I missing something?
|
@skalldri - can you please create an issue for this bug fix? |
|
Hi @skalldri! To celebrate this milestone and showcase your contribution, we'd love to award you the Zephyr Technical Contributor badge. If you're interested, please claim your badge by filling out this form: Claim Your Zephyr Badge. Thank you for your valuable input, and we look forward to seeing more of your contributions in the future! 🪁 |



This PR fixes a bug in
img_mgmt_read_info()which causes it to read invalid TLV keys after it locates the TLV containing the image's SHA.The bug occurs because, after reading the SHA with
img_mgmt_read(image_slot, data_off, hash, IMAGE_SHA_LEN);,data_offis not incremented to account for theIMAGE_SHA_LEN.Instead, it loops back around and begins interpreting the SHA data as additional TLVs.
The SHA is normally 32 bytes long, and a
struct image_tlvis 4 bytes, so it normally reads an additional 8 garbage TLVs.If the SHA contains the bytes
0xfforIMAGE_TLV_SHAin a position that aligns with atlv.it_type, then the entireimg_mgmt_read_info()function will fail due to checks in the loop.The fix for this issue is to increment the
data_offappropriately after reading the SHA data.Fixes #98747