Skip to content

Commit 5d541f5

Browse files
committed
[nrf fromlist] 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. Upstream PR #: 95467 Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent 5408ed3 commit 5d541f5

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
@@ -679,6 +679,17 @@ int img_mgmt_set_next_boot_slot(int slot, bool confirm)
679679
}
680680
#endif
681681

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

733745
LOG_DBG("(%d, %s)", slot, confirm ? "confirm" : "test");
734746
LOG_DBG("aimg = %d, aslot = %d, slot = %d",
@@ -738,6 +750,12 @@ int img_mgmt_set_next_boot_slot(int slot, bool confirm)
738750
return IMG_MGMT_ERR_IMAGE_SETTING_TEST_TO_ACTIVE_DENIED;
739751
}
740752

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

0 commit comments

Comments
 (0)