Skip to content

Commit db6ec69

Browse files
tomchyrlubos
authored andcommitted
[nrf fromtree] mgmt: Allow to block confirming non-acive slots
In Direct XIP with revert, it should be possible to block confirmation of the non-active slot, so only a bootable binaries are marked as valid. Signed-off-by: Tomasz Chyrowicz <[email protected]> (cherry picked from commit c1baf2f)
1 parent 68a48ec commit db6ec69

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

subsys/mgmt/mcumgr/grp/img_mgmt/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,20 @@ config MCUMGR_GRP_IMG_REJECT_DIRECT_XIP_MISMATCHED_SLOT
117117
The base address can be set, to an image binary header, with imgtool,
118118
using the --rom-fixed command line option.
119119

120+
config MCUMGR_GRP_IMG_ALLOW_CONFIRM_NON_ACTIVE_SLOT
121+
bool "Allow to confirm non-active slots of any image"
122+
depends on MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT || \
123+
MCUBOOT_BOOTLOADER_MODE_RAM_LOAD_WITH_REVERT || \
124+
MCUBOOT_BOOTLOADER_MODE_SWAP_SCRATCH || \
125+
MCUBOOT_BOOTLOADER_MODE_SWAP_USING_MOVE || \
126+
MCUBOOT_BOOTLOADER_MODE_SWAP_USING_OFFSET
127+
default y
128+
help
129+
Allows to confirm non-active slot of any image.
130+
Normally it should not be allowed to confirm any slots via MCUmgr
131+
commands, to prevent confirming something that is broken and was not
132+
verified to boot correctly.
133+
120134
config MCUMGR_GRP_IMG_FRUGAL_LIST
121135
bool "Omit zero, empty or false values from status list"
122136
help

subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,17 @@ int img_mgmt_set_next_boot_slot(int slot, bool confirm)
680680
}
681681
#endif
682682

683+
/* The rules above apply only to the inactive image.
684+
* To effectively prevent confirming something that might not have been
685+
* verified to actually be bootable, a new policy was introduced,
686+
* that applies to both active and inactive images.
687+
*/
688+
#ifndef MCUMGR_GRP_IMG_ALLOW_CONFIRM_NON_ACTIVE_SLOT
689+
if (confirm && slot != active_slot) {
690+
return IMG_MGMT_ERR_IMAGE_CONFIRMATION_DENIED;
691+
}
692+
#endif
693+
683694
/* Setting test to active slot is not allowed. */
684695
if (!confirm && slot == active_slot) {
685696
return IMG_MGMT_ERR_IMAGE_SETTING_TEST_TO_ACTIVE_DENIED;
@@ -728,8 +739,9 @@ int img_mgmt_set_next_boot_slot(int slot, bool confirm)
728739
#else
729740
int img_mgmt_set_next_boot_slot(int slot, bool confirm)
730741
{
742+
int image = img_mgmt_slot_to_image(slot);
743+
int active_slot = img_mgmt_active_slot(image);
731744
int active_image = img_mgmt_active_image();
732-
int active_slot = img_mgmt_active_slot(active_image);
733745

734746
LOG_DBG("(%d, %s)", slot, confirm ? "confirm" : "test");
735747
LOG_DBG("aimg = %d, aslot = %d, slot = %d",
@@ -739,6 +751,12 @@ int img_mgmt_set_next_boot_slot(int slot, bool confirm)
739751
return IMG_MGMT_ERR_IMAGE_SETTING_TEST_TO_ACTIVE_DENIED;
740752
}
741753

754+
#ifndef MCUMGR_GRP_IMG_ALLOW_CONFIRM_NON_ACTIVE_SLOT
755+
if (slot != active_slot && confirm) {
756+
return IMG_MGMT_ERR_IMAGE_CONFIRMATION_DENIED;
757+
}
758+
#endif
759+
742760
return img_mgmt_set_next_boot_slot_common(slot, active_slot, confirm);
743761
}
744762
#endif

0 commit comments

Comments
 (0)