diff --git a/doc/releases/release-notes-3.6.rst b/doc/releases/release-notes-3.6.rst index 18394f75ac9b0..4918d1ce014ff 100644 --- a/doc/releases/release-notes-3.6.rst +++ b/doc/releases/release-notes-3.6.rst @@ -272,9 +272,12 @@ Libraries / Subsystems * Implemented datetime functionality in MCUmgr OS management group, this makes use of the RTC driver API. - * Fixes an issue in MCUmgr console UART input whereby the FIFO would be read outside of an ISR, + * Fixed an issue in MCUmgr console UART input whereby the FIFO would be read outside of an ISR, which is not supported in the next USB stack. + * Fixed an issue whereby the ``mcuboot erase`` DFU shell command could be used to erase the + MCUboot or currently running application slot. + * File systems * Modem modules diff --git a/subsys/dfu/boot/mcuboot_shell.c b/subsys/dfu/boot/mcuboot_shell.c index c069edf9c31a1..be4e558713f15 100644 --- a/subsys/dfu/boot/mcuboot_shell.c +++ b/subsys/dfu/boot/mcuboot_shell.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2020 Grinn + * Copyright (c) 2023 Nordic Semiconductor ASA * * SPDX-License-Identifier: Apache-2.0 */ @@ -91,6 +92,21 @@ static int cmd_mcuboot_erase(const struct shell *sh, size_t argc, id = strtoul(argv[1], NULL, 0); + /* Check if this is the parent (MCUboot) or own slot and if so, deny the request */ +#if FIXED_PARTITION_EXISTS(boot_partition) + if (id == FIXED_PARTITION_ID(boot_partition)) { + shell_error(sh, "Cannot erase boot partition"); + return -EACCES; + } +#endif + +#if DT_FIXED_PARTITION_EXISTS(DT_CHOSEN(zephyr_code_partition)) + if (id == DT_FIXED_PARTITION_ID(DT_CHOSEN(zephyr_code_partition))) { + shell_error(sh, "Cannot erase active partitions"); + return -EACCES; + } +#endif + err = boot_erase_img_bank(id); if (err) { shell_error(sh, "failed to erase bank %u", id);