Skip to content

[DNM] test: fprotect #446

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

Open
wants to merge 69 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
2231c99
[nrf noup] github: Add a commit tags check workflow
carlescufi Oct 10, 2023
c71e7f1
[nrf noup] zephyr: Remove duplication from cmake
sigvartmh Mar 26, 2019
bc6443a
[nrf noup] zephyr: add 'minimal' configuration files
mbolivar-nordic Sep 3, 2021
0eaf666
[nrf noup] boards: add support for Thingy:91
bjda Sep 20, 2019
b3f6133
[nrf noup] zephyr: Restore default RTC user channel count
Damian-Nordic Mar 21, 2022
8faf542
[nrf noup] boards: thingy91x: add board config
maxd-nordic Dec 8, 2023
bf49658
[nrf noup] treewide: add NCS partition manager support
SebastianBoe Dec 12, 2018
7d87b4c
[nrf noup] boot: nrf53-specific customizations
sigvartmh Aug 27, 2020
5ee8caf
[nrf noup] zephyr: clean peripherals state before boot
nvlsianpu Feb 27, 2020
b91113f
[nrf noup] zephyr: Clean up non-secure RAM if enabled
sigvartmh Jan 6, 2023
63e8532
[nrf noup] loader: Fix reading reset addr to support ext flash
chrta Feb 10, 2022
b38eae0
[nrf noup] loader: Do not check reset vector for XIP image
de-nordic Sep 22, 2023
728d6c5
[nrf noup] zephyr: Add RAM flash configuration to cache for sysbuild
nordicjm Sep 18, 2023
f20868c
[nrf noup] zephyr: Boot even if EXT_ABI is not provided
sigvartmh Oct 17, 2023
9ef055e
[nrf noup] loader: Add firmware version check downgrade prevention
sigvartmh Sep 27, 2023
39f03d5
[nrf noup] boards: thingy53: disable GPIO ISR support
nika-nordic Oct 9, 2023
57dedc5
[nrf noup] boot/zephyr/boards: nRF54l15pdk ext flash cfg
nvlsianpu Apr 11, 2024
40eba0c
[nrf noup] loader: work-around for multi-image builds
sigvartmh Mar 30, 2021
c7536bb
[nrf noup] loader: Fix missing PCD define check
nordicjm Aug 31, 2023
a517e70
[nrf noup] boot: Add support for NSIB and multi-image
sigvartmh May 31, 2023
33160a8
[nrf noup] sysflash: Move partition manager definitions to pm_sysflash.h
de-nordic Aug 10, 2023
00e8af0
[nrf noup] sysflash: Add support for three images
de-nordic Aug 11, 2023
57db786
[nrf noup] loader: introduced cleanup of unusable secondary slot
nvlsianpu Feb 15, 2024
84fc0bc
[nrf noup] boards: nrf54l15: Disable FPROTECT
gchwier Apr 16, 2024
1059df9
[nrf noup] loader: remove cleanup for direct xip mode
gchwier May 17, 2024
b23a6b5
[nrf noup] boot/zephyr/boards: nrf54l15pdk ext-flash partition
nvlsianpu Apr 15, 2024
767c5d3
[nrf noup] boot/zephyr/boards: nrf54l15pdk ext-flash update
nvlsianpu May 20, 2024
2fb6ba0
[nrf noup] boards: thingy91x: enable serial recovery
maxd-nordic Mar 12, 2024
fbba4d9
[nrf noup] boot: zephyr: Disable boot banner if NCS_BOOT_BANNER is used
rlubos May 17, 2024
914e9a7
[nrf noup] boot/zephyr: fix fw_info search
nvlsianpu May 27, 2024
d995953
[nrf noup] zephyr/boards: fix nrf54l15pdk ext flash dts overlay
nvlsianpu Jun 5, 2024
10a2bf0
[nrf noup] boot: zephyr: Add NCS boot banner
nordicjm Jun 11, 2024
95253e1
[nrf noup] boot/../loader: skip downgrade prevention for s1/s0
nvlsianpu Jun 13, 2024
5e4f255
[nrf noup] boot/../loader: reboot after updating s0/s1
nvlsianpu Jun 18, 2024
ec1805a
[nrf noup] bootutil: loader: Fix netcore address checking
nordicjm Aug 29, 2024
22d3492
[nrf noup] boards: nrf54l15dk: Disable FPROTECT
nvlsianpu Sep 18, 2024
e3d6091
[nrf noup] boot: Add shared crypto for ECDSA and SHA
sigvartmh Feb 14, 2019
5ed18b7
[nrf noup] boot: zephyr: Do not lock PCD region with TF-M
MarkusLassila Aug 30, 2024
28de21a
[nrf noup] treewide: Add support for sysbuild assigned images
nordicjm Sep 10, 2024
aaf851a
[nrf noup] boot: bootutil: loader: Add s0/s1 checking of MCUboot image
nordicjm Oct 15, 2024
4cf6bdc
[nrf noup] boards: Thingy:91 X release config
maxd-nordic Oct 23, 2024
7c2f15e
[nrf noup] workflows: Add a backport workflow
carlescufi Oct 25, 2024
4a7fca1
[nrf noup] boot/zephyr: add nrf54l15dk ext flash configs
michalek-no Nov 7, 2024
315d2f5
[nrf noup] boot/zephyr/Kconfig: conditionally disable BOOT_MAX_IMG_SE…
nvlsianpu Sep 19, 2024
e041019
[nrf noup] boot: zephyr: serial_recovery: Add nRF5340 Kconfig override
nordicjm Dec 9, 2024
514a007
[nrf noup] boot/zephyr/boards: configure fastest RRAM operations
nvlsianpu Dec 17, 2024
1d1ca9b
[nrf noup] boot: Remove child/parent references
nordicjm Dec 5, 2024
298f630
[nrf noup] sysflash: Add missing _FLASH_0_ID definitions
de-nordic Jan 15, 2025
1d96021
[nrf noup] boot: zephyr: boards: Disabled NCS boot banner for thingy 53
kkasperczyk-no Jan 24, 2025
19d25e4
[nrf noup] partition_manager: Add support for internal flash netcore DFU
hellesvik-nordic Feb 6, 2025
a6b51f1
[nrf noup] zephyr: sdk-nrf specific overrides on PSA Kconfigs
de-nordic Mar 4, 2025
ab3b5d7
[nrf noup] zephyr: Fix path variables
nordicjm Jul 11, 2023
2f691b7
[nrf noup] zephyr: Add support for compressed image updates
nordicjm Aug 22, 2024
3e3db4b
[nrf noup] bootutil: Add support for KMU stored ED25519 signature key
de-nordic Sep 20, 2024
26b638c
[nrf noup] boot: zephyr: Add experimental selection to compression
nordicjm Nov 7, 2024
8a366a3
[nrf noup] boot: bootutil: Allow configuring number of KMU keys
nordicjm Dec 2, 2024
7f9f7e1
[nrf noup] zephyr: Use mbedTLS specific C functions with RSA
de-nordic Mar 14, 2025
1ec9e79
[nrf noup] boot/zephyr: nrf54h20dk board support
nordic-mik7 Mar 10, 2025
ede9b99
[nrf noup] boot/zephyr: nrf54h20dk cleanup adaptations
nordic-mik7 Mar 28, 2025
22c2cac
[nrf noup] bootutil: key revocation
michalek-no Mar 17, 2025
1e75d5d
[nrf noup] boot/zephyr/nrf_cleanup: cleanup uarte pins
nvlsianpu Mar 5, 2024
e80f8ed
[nrf noup] boot/zephyr/Kconfig: fix MBEDTLS_CFG_FILE value
nvlsianpu Apr 1, 2025
62ee7ad
[nrf noup] nrf_cleanup: nRF54l: disable cleanup on UARTE pins
nvlsianpu Apr 11, 2025
ce377b6
[nrf noup] boot: zephyr: boards: nrf54lm20pdk
michalek-no Apr 23, 2025
e92888b
[nrf noup] nrf_cleanup: nRF54h: fix missing peripheral cleanup
ahasztag Apr 28, 2025
e110d76
[nrf noup] decompression: Align to changes in nrfcompress API
nordic-mik7 May 13, 2025
766081b
[nrf fromtree] boot/zephyr/main: fix placement of pointer to arm vector
nvlsianpu May 14, 2025
4532c33
[nrf fromtree] zephyr: nRF54l15_cpuapp configuration with LTO enabled
de-nordic May 7, 2025
ab160b6
[DNM] test: fprotect
nordicjm Jun 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/backport.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Backport
on:
pull_request_target:
types:
- closed
- labeled
branches:
- main

jobs:
backport:
name: Backport
runs-on: ubuntu-22.04
# Only react to merged PRs for security reasons.
# See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target.
if: >
github.event.pull_request.merged &&
(
github.event.action == 'closed' ||
(
github.event.action == 'labeled' &&
contains(github.event.label.name, 'backport')
)
)
steps:
- name: Backport
uses: zephyrproject-rtos/[email protected]
with:
github_token: ${{ secrets.NCS_GITHUB_TOKEN }}
issue_labels: Backport
labels_template: '["Backport"]'
28 changes: 28 additions & 0 deletions .github/workflows/commit-tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Commit tags

on:
pull_request:
types: [synchronize, opened, reopened, edited, labeled, unlabeled,
milestoned, demilestoned, assigned, unassigned, ready_for_review,
review_requested]

jobs:
commit_tags:
runs-on: ubuntu-22.04
name: Run commit tags checks on patch series (PR)
steps:
- name: Update PATH for west
run: |
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Checkout the code
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0

- name: Run the commit tags
uses: nrfconnect/action-commit-tags@main
with:
target: .
upstream: mcu-tools/mcuboot/main
64 changes: 58 additions & 6 deletions boot/bootutil/include/bootutil/crypto/ecdsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#if (defined(MCUBOOT_USE_TINYCRYPT) + \
defined(MCUBOOT_USE_CC310) + \
defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO) + \
defined(MCUBOOT_USE_PSA_OR_MBED_TLS)) != 1
#error "One crypto backend must be defined: either CC310/TINYCRYPT/MBED_TLS/PSA_CRYPTO"
#endif
Expand Down Expand Up @@ -70,12 +71,18 @@
#include "bootutil/sign_key.h"
#include "common.h"

#if defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)
#include <bl_crypto.h>
#define NUM_ECC_BYTES (256 / 8)
#endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */

#ifdef __cplusplus
extern "C" {
#endif

#if (defined(MCUBOOT_USE_TINYCRYPT) || defined(MCUBOOT_USE_MBED_TLS) || \
defined(MCUBOOT_USE_CC310)) && !defined(MCUBOOT_USE_PSA_CRYPTO)
defined(MCUBOOT_USE_CC310) || defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)) \
&& !defined(MCUBOOT_USE_PSA_CRYPTO)
/*
* Declaring these like this adds NULL termination.
*/
Expand Down Expand Up @@ -127,8 +134,6 @@ static int bootutil_import_key(uint8_t **cp, uint8_t *end)
}
#endif /* (MCUBOOT_USE_TINYCRYPT || MCUBOOT_USE_MBED_TLS || MCUBOOT_USE_CC310) && !MCUBOOT_USE_PSA_CRYPTO */

#if defined(MCUBOOT_USE_TINYCRYPT)
#ifndef MCUBOOT_ECDSA_NEED_ASN1_SIG
/*
* cp points to ASN1 string containing an integer.
* Verify the tag, and that the length is 32 bytes. Helper function.
Expand Down Expand Up @@ -178,8 +183,8 @@ static int bootutil_decode_sig(uint8_t signature[NUM_ECC_BYTES * 2], uint8_t *cp
}
return 0;
}
#endif /* not MCUBOOT_ECDSA_NEED_ASN1_SIG */

#if defined(MCUBOOT_USE_TINYCRYPT)
typedef uintptr_t bootutil_ecdsa_context;
static inline void bootutil_ecdsa_init(bootutil_ecdsa_context *ctx)
{
Expand Down Expand Up @@ -248,16 +253,20 @@ static inline int bootutil_ecdsa_verify(bootutil_ecdsa_context *ctx,
{
(void)ctx;
(void)pk_len;
(void)sig_len;
(void)hash_len;
uint8_t dsig[2 * NUM_ECC_BYTES];

if (bootutil_decode_sig(dsig, sig, sig + sig_len)) {
return -1;
}

/* Only support uncompressed keys. */
if (pk[0] != 0x04) {
return -1;
}
pk++;

return cc310_ecdsa_verify_secp256r1(hash, pk, sig, BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE);
return cc310_ecdsa_verify_secp256r1(hash, pk, dsig, BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE);
}

static inline int bootutil_ecdsa_parse_public_key(bootutil_ecdsa_context *ctx,
Expand Down Expand Up @@ -613,6 +622,49 @@ static inline int bootutil_ecdsa_parse_public_key(bootutil_ecdsa_context *ctx,

#endif /* MCUBOOT_USE_MBED_TLS */

#if defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)
typedef uintptr_t bootutil_ecdsa_context;
static inline void bootutil_ecdsa_init(bootutil_ecdsa_context *ctx)
{
(void)ctx;
}

static inline void bootutil_ecdsa_drop(bootutil_ecdsa_context *ctx)
{
(void)ctx;
}

static inline int bootutil_ecdsa_verify(bootutil_ecdsa_context *ctx,
uint8_t *pk, size_t pk_len,
uint8_t *hash, size_t hash_len,
uint8_t *sig, size_t sig_len)
{
(void)ctx;
(void)pk_len;
(void)hash_len;
uint8_t dsig[2 * NUM_ECC_BYTES];

if (bootutil_decode_sig(dsig, sig, sig + sig_len)) {
return -1;
}

/* Only support uncompressed keys. */
if (pk[0] != 0x04) {
return -1;
}
pk++;

return bl_secp256r1_validate(hash, BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE, pk, dsig);
}

static inline int bootutil_ecdsa_parse_public_key(bootutil_ecdsa_context *ctx,
uint8_t **cp,uint8_t *end)
{
(void)ctx;
return bootutil_import_key(cp, end);
}
#endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */

#ifdef __cplusplus
}
#endif
Expand Down
32 changes: 32 additions & 0 deletions boot/bootutil/include/bootutil/crypto/sha.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#if (defined(MCUBOOT_USE_PSA_OR_MBED_TLS) + \
defined(MCUBOOT_USE_TINYCRYPT) + \
defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO) + \
defined(MCUBOOT_USE_CC310)) != 1
#error "One crypto backend must be defined: either CC310/MBED_TLS/TINYCRYPT/PSA_CRYPTO"
#endif
Expand Down Expand Up @@ -270,6 +271,37 @@ static inline int bootutil_sha_finish(bootutil_sha_context *ctx,
}
#endif /* MCUBOOT_USE_CC310 */

#if defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)

#include <bl_crypto.h>

typedef bl_sha256_ctx_t bootutil_sha_context;

static inline void bootutil_sha_init(bootutil_sha_context *ctx)
{
bl_sha256_init(ctx);
}

static inline void bootutil_sha_drop(bootutil_sha_context *ctx)
{
(void)ctx;
}

static inline int bootutil_sha_update(bootutil_sha_context *ctx,
const void *data,
uint32_t data_len)
{
return bl_sha256_update(ctx, data, data_len);
}

static inline int bootutil_sha_finish(bootutil_sha_context *ctx,
uint8_t *output)
{
bl_sha256_finalize(ctx, output);
return 0;
}
#endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */

#ifdef __cplusplus
}
#endif
Expand Down
30 changes: 30 additions & 0 deletions boot/bootutil/include/bootutil/key_revocation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#ifndef H_KEY_REVOCATION_
#define H_KEY_REVOCATION_

#include <inttypes.h>

#ifdef __cplusplus
extern "C" {
#endif

#define BOOT_KEY_REVOKE_OK 0
#define BOOT_KEY_REVOKE_NOT_READY 1
#define BOOT_KEY_REVOKE_INVALID 2
#define BOOT_KEY_REVOKE_FAILED 2


void allow_revoke(void);

int revoke(void);

#ifdef __cplusplus
}
#endif

#endif
9 changes: 9 additions & 0 deletions boot/bootutil/include/bootutil/security_cnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ extern "C" {
*/
fih_ret boot_nv_security_counter_init(void);

/**
* Checks if the specified image should have a security counter present on it or not
*
* @param image_index Index of the image to check (from 0).
*
* @return FIH_SUCCESS if security counter should be present; FIH_FAILURE if otherwise
*/
fih_ret boot_nv_image_should_have_security_counter(uint32_t image_index);

/**
* Reads the stored value of a given image's security counter.
*
Expand Down
80 changes: 63 additions & 17 deletions boot/bootutil/src/bootutil_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
#include "bootutil/enc_key.h"
#endif

#if defined(MCUBOOT_DECOMPRESS_IMAGES)
#include <nrf_compress/implementation.h>
#include <compression/decompression.h>
#endif

BOOT_LOG_MODULE_DECLARE(mcuboot);

/* Currently only used by imgmgr */
Expand Down Expand Up @@ -523,35 +528,76 @@ boot_read_image_size(struct boot_loader_state *state, int slot, uint32_t *size)
fap = BOOT_IMG_AREA(state, slot);
assert(fap != NULL);

off = BOOT_TLV_OFF(boot_img_hdr(state, slot));
#ifdef MCUBOOT_DECOMPRESS_IMAGES
if (MUST_DECOMPRESS(fap, BOOT_CURR_IMG(state), boot_img_hdr(state, slot))) {
uint32_t tmp_size = 0;

if (flash_area_read(fap, off, &info, sizeof(info))) {
rc = BOOT_EFLASH;
goto done;
}
rc = bootutil_get_img_decomp_size(boot_img_hdr(state, slot), fap, &tmp_size);

if (rc) {
rc = BOOT_EBADIMAGE;
goto done;
}

off = boot_img_hdr(state, slot)->ih_hdr_size + tmp_size;

rc = boot_size_protected_tlvs(boot_img_hdr(state, slot), fap, &tmp_size);

protect_tlv_size = boot_img_hdr(state, slot)->ih_protect_tlv_size;
if (info.it_magic == IMAGE_TLV_PROT_INFO_MAGIC) {
if (protect_tlv_size != info.it_tlv_tot) {
if (rc) {
rc = BOOT_EBADIMAGE;
goto done;
}

if (flash_area_read(fap, off + info.it_tlv_tot, &info, sizeof(info))) {
off += tmp_size;

if (flash_area_read(fap, (BOOT_TLV_OFF(boot_img_hdr(state, slot)) +
boot_img_hdr(state, slot)->ih_protect_tlv_size), &info,
sizeof(info))) {
rc = BOOT_EFLASH;
goto done;
}
} else if (protect_tlv_size != 0) {
rc = BOOT_EBADIMAGE;
goto done;
}

if (info.it_magic != IMAGE_TLV_INFO_MAGIC) {
rc = BOOT_EBADIMAGE;
goto done;
if (info.it_magic != IMAGE_TLV_INFO_MAGIC) {
rc = BOOT_EBADIMAGE;
goto done;
}

*size = off + info.it_tlv_tot;
} else {
#else
if (1) {
#endif
off = BOOT_TLV_OFF(boot_img_hdr(state, slot));

if (flash_area_read(fap, off, &info, sizeof(info))) {
rc = BOOT_EFLASH;
goto done;
}

protect_tlv_size = boot_img_hdr(state, slot)->ih_protect_tlv_size;
if (info.it_magic == IMAGE_TLV_PROT_INFO_MAGIC) {
if (protect_tlv_size != info.it_tlv_tot) {
rc = BOOT_EBADIMAGE;
goto done;
}

if (flash_area_read(fap, off + info.it_tlv_tot, &info, sizeof(info))) {
rc = BOOT_EFLASH;
goto done;
}
} else if (protect_tlv_size != 0) {
rc = BOOT_EBADIMAGE;
goto done;
}

if (info.it_magic != IMAGE_TLV_INFO_MAGIC) {
rc = BOOT_EBADIMAGE;
goto done;
}

*size = off + protect_tlv_size + info.it_tlv_tot;
}

*size = off + protect_tlv_size + info.it_tlv_tot;
rc = 0;

done:
Expand Down
Loading
Loading