Commit graph zephyr/subsys/mgmt
Author SHA1 Message Date
Gerson Fernando Budke
3424082022 mgmt: updatehub: validate inner metadata object length
z_impl_updatehub_probe() checks that the outer metadata object
array has exactly two elements, but then accesses objects[1].objects[0]
without checking that the inner array is non-empty. A server response
whose second object array is empty leaves that element zero-initialized,
so objects[1].objects[0].objects.sha256sum is NULL and the following
strlen() dereferences a NULL pointer, crashing the agent.

Reject metadata whose inner object array is empty before dereferencing
it, for both the 'any boards' and 'some boards' layouts.

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
2026-06-09 13:41:55 +02:00
Gerson Fernando Budke
8747634ed7 mgmt: updatehub: avoid closing fd 0 in cleanup_connection()
ctx.sock was set to 0 after cleanup, but 0 is a valid file
descriptor (stdin). If cleanup_connection() were called without an
open socket, zsock_close(0) would close stdin.

Guard the close with ctx.sock >= 0 and use -1 as the invalid
socket sentinel.

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
2026-06-09 13:41:55 +02:00
Gerson Fernando Budke
4a7bdd9347 mgmt: updatehub: use msgtype parameter in send_request()
coap_packet_init() was hardcoded to COAP_TYPE_CON, ignoring the
msgtype parameter. This meant report() calls passing COAP_TYPE_NON_CON
were silently sent as confirmable messages.

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
2026-06-09 13:41:55 +02:00
Gerson Fernando Budke
eafc077d52 mgmt: updatehub: fix hardware compatibility prefix match
strncmp with strlen(CONFIG_BOARD) only compares the first N
characters, allowing a supported_hardware entry like
"frdm_k64f_extra" to incorrectly match CONFIG_BOARD="frdm_k64f".
This could cause the device to accept firmware intended for a
different board variant.

Use strcmp for an exact match. Both strings are null-terminated.

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
2026-06-09 13:41:55 +02:00
Gerson Fernando Budke
69bbed5e60 mgmt: updatehub: fix missing null terminator in metadata copy
memcpy(metadata_copy, metadata, strlen(metadata)) does not copy the
null terminator. Since metadata_copy comes from k_malloc (unzeroed),
the subsequent strlen(metadata_copy) reads past the copied data into
uninitialized heap memory, and json_obj_parse may process garbage
data or crash.

Zero the buffer before copying to ensure proper null termination.

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
2026-06-09 13:41:55 +02:00
Gerson Fernando Budke
d09db89a87 mgmt: updatehub: fix error message never sent in report()
strncmp(report.previous_state, "", sizeof("") - 1) always returns 0
because sizeof("") - 1 is 0, and strncmp with length 0 always
returns 0 per the C standard. This means report.error_message was
always set to "" and the server never received actual error details.

Replace with a direct check for a non-empty string. Guard the check
against a NULL previous_state, which state_name() can return for an
out-of-range state (the UPDATEHUB_FLASH_INIT_ERROR case passes a
response code instead of a state), so the new check does not
dereference a NULL pointer.

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
2026-06-09 13:41:55 +02:00
Gerson Fernando Budke
29e3476501 mgmt: updatehub: fix socket leak in start_coap_client()
When DTLS setsockopt or zsock_connect failed after socket creation,
the error path used ret to decide whether to call cleanup_connection().
However ret was set to -1 after socket creation, so the check
(ret > 0) was false and the socket was never closed.

Additionally, ret was set to 1 before socket creation, so if
zsock_socket itself failed, cleanup_connection() would be called
on an invalid file descriptor.

Replace the ret-based cleanup check with (ctx.sock >= 0) which
directly reflects whether a socket exists that needs closing.

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
2026-06-09 13:41:55 +02:00
Gerson Fernando Budke
551d3f92b3 mgmt: updatehub: Fix race condition
The UpdateHub subsystem has a race condition between the background
autohandler (system workqueue) and user-triggered operations (shell
commands or direct API calls). Both paths share the global ctx
structure without synchronization, allowing concurrent calls to
prepare_fds() which writes beyond the single-element ctx.fds[1]
array when ctx.nfds is already 1, corrupting adjacent memory
(ctx.sock) and leading to DoS or undefined behavior.

Replace the unused struct k_sem semaphore with a static K_MUTEX_DEFINE
to serialize access to the shared ctx across z_impl_updatehub_probe(),
z_impl_updatehub_update(), and z_impl_updatehub_report_error().

Add a bounds check to prepare_fds() (returning -ENOMEM when ctx.nfds
>= ARRAY_SIZE(ctx.fds)) as defense-in-depth against Out-of-Bounds
writes, and propagate the error through start_coap_client().

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
2026-06-09 13:41:55 +02:00
Silesh C V
ad249444a5 arch: arm: add support for Cortex-A32
Add support for the Cortex-A32 processor. The Cortex-A32 processor
is built on the ARMv8-A architecture and supports only the AArch32
execution state.

Signed-off-by: Silesh C V <silesh@alifsemi.com>
2026-06-09 08:41:24 +02:00
Fin Maaß
59d7ab58d8 mgmt: hawkbit: fix of by one error
Make sure that the the added `/0`
char has enough space at the end.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-06-04 09:07:09 +02:00
Fin Maaß
0e922e29f5 mgmt: hawkbit: use k_malloc instead of k_calloc
the buffer doesn't need to be zero initialized.
therefore we don't need to use K_calloc.
It can already be seen, when we need to increase the
buffer we do it with k_realloc, which doesn't set the
additional space to zeros.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-06-03 18:38:36 +02:00
Anas Nashif
d0b389da9e kernel: remove redundant kernel_structs.h includes
kernel.h implies kernel_structs.h via kernel_includes.h, making
explicit inclusion of kernel_structs.h unnecessary whenever kernel.h
is already included in the same translation unit.

Remove the redundant includes across arch, boards, drivers, kernel,
lib, samples, subsys, and tests trees.

in include/zephyr/kernel_structs.h:
 *  2. kernel.h shall imply kernel_structs.h, such that it shall not be
 *    necessary to include kernel_structs.h explicitly when kernel.h is
 *    included.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-06-02 20:24:14 +02:00
Fin Maaß
6e054c9f60 mgmt: updatehub: select MPU_ALLOW_FLASH_WRITE only if ARM_MPU
only when ARM_MPU is enabled, the option
MPU_ALLOW_FLASH_WRITE needs to be enabled.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-05-29 22:09:37 +02:00
Fin Maaß
a3233c2eaf mgmt: hawkbit: select MPU_ALLOW_FLASH_WRITE only if ARM_MPU
only when ARM_MPU is enabled, the option
MPU_ALLOW_FLASH_WRITE needs to be enabled.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-05-29 22:09:37 +02:00
Valerio Setti
c15cba4e7a modules: mbedtls: rename mbedTLS library and documentation usage
Having an interface library named "mbedTLS" and the real library named
"mbedtls" (as provided by the Mbed TLS module) is misleading.
This commit replaces:
- mbedTLS -> mbedtls_iface for the CMake library. "mbedTLS" is still
             available as alias to "mbedtls_iface" for backward
             compatibility, but this should be removed in the future.
- mbedTLS -> Mbed TLS in comments and documentation.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-05-27 15:16:06 +01:00
Fin Maaß
4d859419d9 drivers: serial: don't check return value of uart_irq_update()
Remove return value checks of uart_irq_update().
Needed for changing it's return value to void.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-05-19 17:46:51 -04:00
Egill Sigurdur
16ac4a5b78 kernel: mem_slab: add K_MEM_SLAB_DEFINE_TYPE for automatic alignment
Introduces K_MEM_SLAB_DEFINE_TYPE() and K_MEM_SLAB_DEFINE_STATIC_TYPE()
helpers to allow the user to declare slabs for types without having to
manually ensure the alignment is correct.

Manual slab alignment was very error-prone and this change fixes several
instances of misalignment that would be trapped by the undefined
behavior sanitizer when running on 64-bit targets.

Signed-off-by: Egill Sigurdur <egill@egill.xyz>
2026-05-07 18:09:41 -05:00
Tomasz Chyrowicz
ce334a9c9f mgmt: img_mgmt: Add a transport-specific req
Add a dependency on the NETBUF size if the UART transport and the
img_mgmt group is selected.

Signed-off-by: Tomasz Chyrowicz <tomasz.chyrowicz@nordicsemi.no>
2026-05-07 13:19:00 +01:00
Tomi Fontanilles
7d65b380e2 modules: mbedtls: link to mbedTLS only when CONFIG_MBEDTLS_BUILTIN
393350fd65 made it so that the `mbedTLS`
library is only created when `CONFIG_MBEDTLS_BUILTIN`.

Before this commit, users of Mbed TLS did the following:
`zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS)`

If the `mbedTLS` CMake library doesn't exist but is still linked to
(as is the case when `CONFIG_MBEDTLS && !CONFIG_MBEDTLS_BUILTIN`),
the linker command is populated with `-lmbedTLS` which makes the build
fail because there is no `libmbedTLS.a` in the build.

Make it so that users of Mbed TLS only link to the `mbedTLS` CMake
library when the builtin version is used.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2026-05-07 09:11:36 +02:00
Jamie McCrae
a64883ef5d mgmt: mcumgr: grp: os_mgmt: Fix MPSTAT invalid map
Fixes wrongly having an extra map entry for this response

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-05-05 14:05:44 -05:00
Jamie McCrae
6f363ec6f7 mgmt: mcumgr: transport: Fix resetting invalid buffer
Fixes an issue whereby the buffer was not checked to be valid
before resetting it

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-04-27 14:20:21 +02:00
Martin Stumpf
b00f4a1e28 mcumgr: serial: fix tx frame size
The `max_input` variable gets reduced by 3 bytes to make room for the
size header in the first frame; it does not however get reset to its
previous value in the following frame, which permanently reduces
the frame size by three bytes.

Signed-off-by: Martin Stumpf <finomnis@gmail.com>
2026-04-23 08:16:34 -04:00
Jamie McCrae
9da5c07615 mgmt: mcumgr: grp: img_mgmt: Fix non-progressive swap offset erase
Fixes not erasing the first sector when using swap using offset mode

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-04-20 13:22:14 +02:00
Jamie McCrae
f99dbd622e mgmt: mcumgr: grp: fs_mgmt: Fix not checking if write completed
Fixes an issue whereby a write might have partially been successful
but failed due to insufficient space in the storage device by
re-attempting the write again with the offset, and if it still
fails, return an error

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-04-15 17:16:25 -04:00
Jan Kowalewski
e69cafdbb4 mgmt: hawkbit: add missing CONFIG_ prefix
Adds missing CONFIG_ prefix to HAWKBIT_USE_STATIC_CERT_TAG ifdef.

Signed-off-by: Jan Kowalewski <jkowalewski@cthings.co>
2026-03-23 15:00:10 -05:00
Tony Han
587c212277 subsys/mgmt: declare PROCESSOR_NAME for arm926ej-s
Add the declaration of PROCESSOR_NAME for arm926ej-s CPU.

Signed-off-by: Tony Han <tony.han@microchip.com>
2026-03-23 12:27:55 -05:00
Joel Holdsworth
a737213c98 tests: Add basic test-set for OpenRISC architecture port
The OpenRISC 1000 architecture can be tested through the qemu_or1k emulated
SoC and board. Because this emulated device has minimal external hardware
by default, this patch enables a minimal suite of tests covering core
kernel features for the CPU architecture.

When running the test suite, OpenRISC was found to require additional stack
space to prevent an overflow. Therefore, a minimal additional amount of
storage: 128-bytes, was added that was found in practice to allow tests to
complete.

Note that Qemu version 9.2.0 or newer is required so as to include the
following commit:

    commit 3eb43aeb164f1f83c97ff693c7d464b49755110c
    Author: Joel Holdsworth <jholdsworth@nvidia.com>
    Date:   Fri Jun 7 15:29:33 2024 -0700

        hw/openrisc: Fixed undercounting of TTCR in continuous mode

This fixes a bug in the implementation of the emulated OpenRISC Tick Timer
which prevents the Zephyr OpenRISC port from task-scheduling properly.

Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
2026-03-21 07:50:57 -05:00
Jamie McCrae
f22592cbc5 tree: Replace FIXED_PARTITION_* macro usage with PARTITION_*
Replaces usage of these deprecated macros with ones that support
fixed and mapped partition compatibles. Also includes an update to
hal_espressif which also (rightly or wrongly) has zephyr specific
code in it

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-03-17 18:24:52 -04:00
Jamie McCrae
872905f2f3 mgmt: mcumgr: grp: img_mgmt: Add support for zephyr,mapped-partition
Prevents checking if the flash offset Kconfig is defined

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-03-17 18:24:52 -04:00
Fin Maaß
f4e724a56a mgmt: hawkbit: remove CONFIG_HAWKBIT_DDI_NO_SECURITY
remove the deprecated option
CONFIG_HAWKBIT_DDI_NO_SECURITY.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-03-17 18:23:41 -04:00
Jordan Yates
cc53c73263 mgmt: mcumgr: img_mgmt: typo fix
Fix `Faled` -> `Failed`.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2026-03-10 12:39:23 +01:00
Martin Stumpf
2ef7ee567e mcumgr: Fix 'stat' group error codes
Error codes of group 'stat' were incorrectly labeled as group 'zbasic'.

Signed-off-by: Martin Stumpf <finomnis@gmail.com>
2026-03-03 18:00:54 +01:00
Alberto Escolar Piedras
61e6c0b2a1 mgmt: updatehub: Use renamed network APIs
In
d45cd6716b
f27a26f9ec
the mayority of this code was changed to use the new native networking
API naming, but one macro was forgotten.

Let's change it now so this code builds also without
CONFIG_NET_NAMESPACE_COMPAT_MODE

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2026-02-27 13:56:24 +01:00
Jamie McCrae
861079f1fe storage: flash_map: Fix macros for offset/address
Fixes macros that broke after changes were merged which started
using the unit address of partition nodes. This also fixes the
test to ensure devices not starting at 0x0 are properly checked
which previously would silently be unknown

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-02-04 13:51:57 +01:00
Jamie McCrae
bcc5529eae mgmt: mcumgr: transport: Add raw dummy transport
Adds a raw dummy UART transport which can be used for testing
MCUmgr without a real transport

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-01-27 10:23:45 -06:00
Jamie McCrae
d5df08a1cc mgmt: mcumgr: transport: uart: Add support for non-console raw mode
Adds support for using MCUmgr over UART (not via shell) in a raw
mode which does not include base64 and other SMP over console
encoding

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-01-27 10:23:45 -06:00
Gaetan Perrot
654dfddc7d mgmt: mcumgr: transport: smp_bt: reduce ret variable scope
The return value variable was initialized but immediately
overwritten before.

Remove the redundant initialization and limit the variable scope to
where it is actually used.

No functional change.

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2026-01-25 17:07:05 +01:00
Ibrahim Abdalkader
0c5e7a6a95 sensing: sensor_mgmt: Use kernel heap for allocations
Use the kernel heap instead of the libc heap, improving
security and consistency.

Signed-off-by: Ibrahim Abdalkader <i.abdalkader@gmail.com>
2026-01-22 08:38:34 +00:00
Ibrahim Abdalkader
afa47a2765 mgmt: mcumgr: grp: Use kernel heap for allocations
Use the kernel heap instead of the libc heap, improving
security and consistency.

Signed-off-by: Ibrahim Abdalkader <i.abdalkader@gmail.com>
2026-01-22 08:38:34 +00:00
Jamie McCrae
917404f5d7 mgmt: mcumgr: transport: uart: Change Kconfig to depends on
Changes CONFIG_MCUMGR_TRANSPORT_UART from selecting
CONFIG_UART_MCUMGR to instead of depending upon it, as it should
never have selected a driver Kconfig and instead always depended
upon it, and is needed for supporting different UART transports

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-01-21 11:21:46 +00:00
Jamie McCrae
e3371aaf24 mgmt: mcumgr: Add name to CMake libraries
Adds names to these libraries to prevent using auto-generated
names of the paths, which can be longer than the maximum supported
length on the current version of gcc for windows

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-01-20 15:31:50 +00:00
Jamie McCrae
42ee9832b4 mgmt: mcumgr: kconfig: Fix various issues
Fixes various issues in the Kconfigs including not properly having
abbreviations in the correct case, line lengths, duplicating other
Kconfigs, etc.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-01-20 15:31:50 +00:00
Samuel Kleiser
0fbbba2dc0 mcumgr: fs_mgmt: forward return values from fs_close
A new error code FS_MGMT_ERR_FILE_CLOSE_FAILED is returned when
closing a file fails. This is done on write or close operations - read
operations remain unchecked.

Signed-off-by: Samuel Kleiser <s.kleiser@vega.com>
2026-01-14 09:18:10 -06:00
Jaagup Averin
f430cdef60 subsys/mgmt: Declare PROCESSOR_NAME for native_sim
In case of native build, the CONFIG_architecture
cannot currently be resolved with Kconfig, so we
must fall back to resolving it during compilation
using compiler definitions.

Signed-off-by: Jaagup Averin <jaagup.averin@gmail.com>
2026-01-01 21:27:23 +01:00
Alberto Escolar Piedras
fe1607844c mgmt: mcumgr: Fix remaining net API use
In d45cd6716b the mayority of the
Zephyr codebased was changed to use the Zephyr native net_ prefixed
types, but some were forgotten.
Without this fix/change the code still builds as we are by now setting
CONFIG_NET_NAMESPACE_COMPAT_MODE. But when this is not set, things
fail to build.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-12-18 18:52:06 +00:00
Sylvio Alves
f8d2e00a0e includes: remove duplicated entries in zephyr-tree
Remove duplicated #include directives within the same
preprocessor scope across the Zephyr tree.

Duplicates inside different #ifdef branches are preserved
as they may be intentional.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2025-12-17 13:57:38 -05:00
Tomasz Chyrowicz
26128ab73d mcumgr: Prevent FW loader from self-destruction
The FW loader reports and manages exactly two slots:
 - slot 0: this is the slot for the application code to update
 - slot 1: this is the slot, in which the FW loader is placed

The slot 1 is reported, so tools can fetch metadata about the
FW loader installed on the device.
Unfortunately, currently SMP-based FW loader allows to issue slot erase
command for the slot 1, effectively erasing the FW loader code that is
being executed.

This change correctly identifies the slot 1 as an active one, marking it
as used and blocking erase operation on that slot.

Signed-off-by: Tomasz Chyrowicz <tomasz.chyrowicz@nordicsemi.no>
2025-12-11 16:34:55 -05:00
Martin Stumpf
ffb046b797 MCUmgr: OS: fix set datetime millisecond handling
According to the docs the millis were in the format `.SSSSSS`. In
reality though, it only accepted exactly `.SSS`, not `.SS` or `.SSSS`
and specifically also not `.SSSSSS`, contrary to the docs. Further, it did
not fail with an error message but simply produced the wrong value.

With this change it accepts everything from `.` to `.SSSSSS` and
produces the correct result. This is compatible with the previous
behavior, with the documentation and with everything in between.

Signed-off-by: Martin Stumpf <finomnis@gmail.com>
2025-12-11 16:59:35 +01:00
Tomasz Chyrowicz
764f0d183b img_mgmt: Use absolute address in active partition
Use absolute addresses while determining a running application
partition.

Signed-off-by: Tomasz Chyrowicz <tomasz.chyrowicz@nordicsemi.no>
2025-12-09 09:51:07 -05:00
Ayush Singh
4f98eede4b mcumgr: client: Allow specifying server address
- Currently, it is not possible to use mcumgr client with smp server
  since there is no way to specify smp server address for requests.
- This patch series adds support for creating smp_client_object
  containing information regarding the host server. This design allows
  multiple smp_client_object to exist for the same underlying smp_udp
  transport, making it much easier to use the same udp socket for multiple
  OTAs.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-12-08 11:41:30 -05:00