DFU FW downgrade protection

Hi Nordic 

What is the best way to protect against downgrading the APP FW via DFU.

I seems that im able to downgrade even 2 config below are set.

I tested it on SDK 2.7.0 and here it was not possible to downgrade, but on latest it is

 

Im Using SDK 3.0.2 and 54L15

Can it be done with the config parameter, or are more needed 

CONFIG_BOOT_UPGRADE_ONLY=y

CONFIG_MCUBOOT_HW_DOWNGRADE_PREVENTION=y

Best regards
Tommy F Kristensen
Parents Reply Children
  • Hi Vidar

    I Have just succeded to compile the bootloader with SB_CONFIG_MCUBOOT_HARDWARE_DOWNGRADE_PREVENTION=y enabled in sysbuild, where I disabled logging in bootloader to make space.

    Now the device will NOT startup. 

    Are im missing any config

    Below prj.conf for mcuboot

    CONFIG_PM=n
    
    CONFIG_MAIN_STACK_SIZE=10240
    CONFIG_MBEDTLS_CFG_FILE="mcuboot-mbedtls-cfg.h"
    
    CONFIG_BOOT_SWAP_SAVE_ENCTLV=n
    CONFIG_BOOT_ENCRYPT_IMAGE=n
    
    CONFIG_BOOT_UPGRADE_ONLY=y
    CONFIG_BOOT_BOOTSTRAP=n
    
    ### mbedTLS has its own heap
    # CONFIG_HEAP_MEM_POOL_SIZE is not set
    
    ### We never want Zephyr's copy of tinycrypt.  If tinycrypt is needed,
    ### MCUboot has its own copy in tree.
    # CONFIG_TINYCRYPT is not set
    # CONFIG_TINYCRYPT_ECC_DSA is not set
    # CONFIG_TINYCRYPT_SHA256 is not set
    
    CONFIG_FLASH=y
    #fffCONFIG_FPROTECT=y
    CONFIG_FLASH_JESD216_API=y
    
    CONFIG_SPI_NOR_SFDP_MINIMAL=y
    ### Various Zephyr boards enable features that we don't want.
    # CONFIG_BT is not set
    # CONFIG_BT_CTLR is not set
    # CONFIG_I2C is not set
    
    CONFIG_LOG=n
    CONFIG_LOG_MODE_MINIMAL=y # former CONFIG_MODE_MINIMAL
    ### Ensure Zephyr logging changes don't use more resources
    CONFIG_LOG_DEFAULT_LEVEL=0
    ### Use info log level by default
    CONFIG_MCUBOOT_LOG_LEVEL_INF=y
    ### Decrease footprint by ~4 KB in comparison to CBPRINTF_COMPLETE=y
    CONFIG_CBPRINTF_NANO=y
    ### Use the minimal C library to reduce flash usage
    CONFIG_MINIMAL_LIBC=y
    CONFIG_NRF_RTC_TIMER_USER_CHAN_COUNT=0
    
    # NCS boot banner
    CONFIG_NCS_APPLICATION_BOOT_BANNER_STRING="MCUboot"
    
    CONFIG_FW_INFO=n
    #CONFIG_FW_INFO_FIRMWARE_VERSION=1
    
    #CONFIG_SECURE_BOOT_DEBUG_UART=n
    CONFIG_SAPHE=n
    CONFIG_INPUT_FT3168=n
    CONFIG_INPUT_FT3168_INTERRUPT=n
    CONFIG_SH8601Z=n
    CONFIG_SAPHE_LIS2DH=n
    CONFIG_I2S=n
    # Enable GPIO
    CONFIG_GPIO=n
    # Enable ADC
    CONFIG_ADC=n

    This is my sysbuild config:

    SB_CONFIG_BOOTLOADER_MCUBOOT=y
    
    SB_CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256=y
    
    SB_CONFIG_MCUBOOT_MODE_SWAP_WITHOUT_SCRATCH=y
    
    SB_CONFIG_DFU_MULTI_IMAGE_PACKAGE_BUILD=y
    SB_CONFIG_DFU_MULTI_IMAGE_PACKAGE_APP=y
    
    SB_CONFIG_MCUBOOT_MODE_OVERWRITE_ONLY=y
    
    
    # Settings required for external flash to be used for DFU
    SB_CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y
    SB_CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y
    
    
    SB_CONFIG_PARTITION_MANAGER=y
    
    
    SB_CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256=y
    
    SB_CONFIG_MCUBOOT_HARDWARE_DOWNGRADE_PREVENTION=y

    Best Regards

    Tommy

    Ps. I did try to remove the pm_static.conf, and let partion tool generate the partions, but then it failed allocating the external flash for for fat_fs. Below is my pm_static.yml 

    app:
      address: 0xe800
      end_address: 0x15f000
      region: flash_primary
      size: 0x150800
    # https://docs.nordicsemi.com/bundle/ncs-2.9.0/page/nrf/scripts/partition_manager/partition_manager.html#configuration_file_format
    fatfs_storage:
      address: 0x151000
      affiliation:
      - disk
      device: DT_CHOSEN(nordic_pm_ext_flash)
      end_address: 0x800000
      extra_params:
        disk_cache_size: 0x1000
        disk_name: NAND
        disk_read_only: 0x0
        disk_sector_size: 0x200
      placement:
        align:
          start: 0x1000
        before:
        - end
      region: external_flash
      size: 0x6AF000
    mcuboot:
      address: 0x0
      end_address: 0xe000
      placement:
        align:
          end: 0x1000
        before:
        - mcuboot_primary
      region: flash_primary
      size: 0xe000
    mcuboot_pad:
      address: 0xe000
      end_address: 0xe800
      placement:
        before:
        - mcuboot_primary_app
      region: flash_primary
      size: 0x800
    mcuboot_primary:
      address: 0xe000
      end_address: 0x15f000
      orig_span: &id001
      - mcuboot_pad
      - app
      region: flash_primary
      size: 0x151000
      span: *id001
    mcuboot_primary_app:
      address: 0xe800
      end_address: 0x15f000
      orig_span: &id002
      - app
      region: flash_primary
      size: 0x150800
      span: *id002
    mcuboot_secondary:
      address: 0x0
      device: DT_CHOSEN(nordic_pm_ext_flash)
      end_address: 0x151000
      placement:
        align:
          start: 0x4
      region: external_flash
      share_size:
      - mcuboot_primary
      size: 0x151000
    otp:
      address: 0xffd500
      end_address: 0xffd9fc
      region: otp
      size: 0x4fc
    sram_primary:
      address: 0x20000000
      end_address: 0x2002f000
      region: sram_primary
      size: 0x2f000
    zms_storage:
      address: 0x15f000
      end_address: 0x165000
      placement:
        after:
        - app
        before:
        - end
      region: flash_primary
      size: 0x6000
    

  • Hi Tommy, 

    Thanks for the additional details. You may be able to keep logging enabled if you enable link time optimization, which we now have on by default for nrf54l bootloader builds (see https://github.com/nrfconnect/sdk-mcuboot/commit/671513cb7dad7598986fe3b4a4dd11e9edfb6c9a).  Could you try this and see if the logs provide any clues?

    Tommy F Kristensen said:
    Ps. I did try to remove the pm_static.conf, and let partion tool generate the partions, but then it failed allocating the external flash for for fat_fs. Below is my pm_static.yml 

    It's possible to remove everything but the fatfs_storage storage partition and let the other partitions be allocated dynamically.

    Best regards,

    Vidar

  • Hi Vidar

    Sorry for the delayed answer, but I have had some other more critical bugs to fix.

    I ended up gettting it to run with your fix and reducing the loglevel to warn. 

    Now I get log out 

    • *** Booting MCUboot v2.1.0-dev-ae1ee57f3906 ***
      *** Using nRF Connect SDK v3.0.2-89ba1294ac9b ***
      *** Using Zephyr OS v4.0.99-f791c49f492c ***
      [00:16:30.780,660] ←[1;31m<err> mcuboot: Security counter update failed after image validation.←[0m
      [00:16:30.780,844] ←[1;31m<err> mcuboot: Unable to find bootable image←[0m
      I have been checking that there should be a OTP area to hold the counter i the partitions table.
    • I have patched the SDK 3.0.2, with your above patch, so im not sure if im missing anything

    Best Regards

    Tommy F Kristensen

  • Hi Tommy,

    Please check the return code from boot_update_security_counter() if you haven't already. It would also be good if you could quickly test the same with SDK v3.1.x or later.

    Best regards,

    Vidar

Related