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

loader: Add firmware info version check to downgrade prevention #277

Merged
merged 1 commit into from
Oct 19, 2023

Conversation

sigvartmh
Copy link
Contributor

For nRF53, the only existing version number metadata is stored in the firmware_info structure in the network core. This utilizes PCD to read out the version number and compares it against the version number found in the secondary slot for the network core.

Ref. NCSDK-21379

@sigvartmh
Copy link
Contributor Author

sigvartmh commented Oct 11, 2023

Not finalized I'm pulling things out into a single function something like boot_cmp_net to hide behind a #define flag .

I understand that this is not the best solution but it's what I've come up with as a stop gap to get something in before RC1.

See https://github.com/nrfconnect/sdk-nrf/pull/12409/files

For the function refactoring into boot_hooks_nrf53.

@maciejpietras maciejpietras added this to the ncs-2.5.0 milestone Oct 11, 2023
@sigvartmh
Copy link
Contributor Author

@nordicjm So I've fetched out the idea a bit more, but I'm not 100% happy with the end result. ideally, I would have boot_cmp as a hook with a Regular and unique case.

The problem is that boot_cmp does not take in any state or slot, so you don't know which slot you are doing the comparison against.

Anyways please review the idea if possible, some one is waiting for this to go in for RC1

@sigvartmh
Copy link
Contributor Author

To answer both @de-nordic and @nordicjm, the idea here is to do something like this:

int boot_read_image_header_hook(int img_index, int slot, struct image_header *img_head)
So inside, you would either do regular compare or do the boot_cmp_net when if image == 1 I'll refactor this to reflect this better.

@sigvartmh
Copy link
Contributor Author

@de-nordic @nordicjm So I've reworked it a bit but I'm uncertain if I should push even more of the logic over into the nrf53_hook file.

boot/bootutil/src/loader.c Outdated Show resolved Hide resolved
boot/bootutil/src/loader.c Outdated Show resolved Hide resolved
Copy link
Contributor

@nordicjm nordicjm left a comment

Choose a reason for hiding this comment

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

There is probably a PCD hook file somewhere that would need a check adding too

@sigvartmh
Copy link
Contributor Author

So currently the placement of the function is a bit weird and I think I should change the naming back to boot_ instead of pcd. Tried to move all of it into PCD but it had some dependencies to MCUBoot so it was easier just to leave it in nrf53_hooks.c added #ifdefs there. I wonder if you prefer the naming boot_version_cmp_net ?

#include <dfu/pcd.h>
int pcd_version_cmp_net(const struct flash_area *fap, struct image_header *hdr);
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: wouldn't it be more useful if the function would rather extract version out of PCD and comparison would happen on the MCUboot side?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't use the same versioning scheme. Netcore uses FW_INFO which is just a single value while MCUBoot does the major.minor.rev semantic versioning.

The end goal is to consolidate them but for now, this is what we can provide.

The command is running on the MCUBoot side but it fetches the current version number through PCD from the network core and does the comparison on Application(MCUBoot side).

@sigvartmh
Copy link
Contributor Author

So do you belive we can get this in for 2.5.0 @nordicjm @de-nordic ?

@de-nordic
Copy link
Contributor

de-nordic commented Oct 12, 2023

So do you belive we can get this in for 2.5.0 @nordicjm @de-nordic ?

Yes, but post rc1.

We have to actually, as this is bugfix.

@maciejpietras maciejpietras added the bug Something isn't working label Oct 16, 2023
@sigvartmh sigvartmh force-pushed the feature/netcore-prevention branch 2 times, most recently from 73e3822 to 49ceaa7 Compare October 19, 2023 08:20
@de-nordic de-nordic added the bugfix Fixes a known bug label Oct 19, 2023
@sigvartmh sigvartmh force-pushed the feature/netcore-prevention branch 2 times, most recently from c1be6e1 to d8bf41e Compare October 19, 2023 12:21
For nRF53, the only existing version number metadata is stored in the
`firmware_info` structure in the network core. This utilizes PCD to read
out the version number and compares it against the version number found
in the secondary slot for the network core.

Ref. NCSDK-21379

Signed-off-by: Sigvart Hovland <sigvart.hovland@nordicsemi.no>
@cvinayak cvinayak merged commit 1b6571d into nrfconnect:main Oct 19, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bugfix Fixes a known bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants