Commit graph zephyr/subsys
Author SHA1 Message Date
Jukka Rissanen
1d19bb3d5c net: quic: Fix off-by-one when setting the ALPN list
tls_opt_ciphersuite_list_set() rejects a list only when it is strictly
larger than alpn_list, but the array has to hold a NULL terminator as
well. A list with exactly ALPN_MAX_PROTOCOLS + 1 entries is therefore
accepted, memcpy fills the array, and the terminator is written one
element past the end, over the hostname pointer that follows it.

Require room for the terminator, matching the check that the sibling
cipher suite handler already performs.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:45:36 -04:00
Jukka Rissanen
ebfda7bc35 net: quic: Bound-check TLS handshake message parsing
parse_client_hello() read the extensions length without checking that
the declared extensions actually fit in the message. The extension loop
then bounded itself against that attacker-supplied end rather than the
real buffer, so a short ClientHello claiming 65535 bytes of extensions
walked far past the crypto RX buffer and past the endpoint it lives in.
Bytes found there were also copied into the peer transport parameters
and the peer public key. This is reachable on the first packet of a
connection, before any authentication.

The same missing check existed in parse_certificate_request(), reached
on the client from a malicious server, and parse_certificate() ran a
memcmp over an attacker-chosen context length with only a four byte
message guaranteed.

parse_client_hello() also read the cipher suite list length and the
compression method length without first confirming those bytes were
present, and its suite loop read two bytes per entry without requiring
an even list length, so an odd length read one byte past the list.

Add the missing bounds checks. Every other extension parser in this
file already validates its length this way.

parse_client_hello() becomes ZTESTABLE_STATIC so the accompanying tests
can reach it.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:45:36 -04:00
Jukka Rissanen
a86976de42 net: quic: Fix out-of-bounds read of the long header SCID length
When parsing a long header, the guard after the destination connection
ID used "pos > data_len", which permits pos to be exactly data_len.
The source connection ID length byte is then read at data[data_len],
one byte past the datagram.

A remote peer triggers this with a datagram whose destination
connection ID consumes the last byte, for example the seven bytes
c0 00 00 00 01 01 aa. The stale byte is only used as a length and
every path after it rejects the packet, so there is no information
leak, but the read itself faults under a sanitizer and can cross an
MPU or page boundary on a real target.

Use "pos >= data_len", matching the guards this function already uses
before reading the token and the payload length varint.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:45:36 -04:00
Jukka Rissanen
1a690925c9 net: quic: Use cryptographic RNG for security-relevant values
The QUIC code sourced all its random values from sys_rand_get(),
which is backed by the non-cryptographic xoshiro128++ PRNG on many
configurations. That generator writes full consecutive 32-bit words
verbatim, so its 128-bit state can be recovered from a handful of
outputs, and several of those outputs are visible to an unauthenticated
peer: the TLS client random travels in the Initial packet, connection
IDs sit in cleartext headers, and the certificate request context is
echoed back by the client. Recovering the state lets an attacker forge
address validation tokens, re-enabling the amplification vector that
Retry and NEW_TOKEN exist to prevent, and predict or link connection
IDs. The generator is shared with the rest of the system, so the
disclosure also affects TCP initial sequence numbers.

Switch every value whose unpredictability has a security role, or that
is disclosed to a peer, to sys_csrand_get() and propagate its failure
return: the address validation token secret and token nonces, client
and server connection IDs (initial, Retry and server-generated), the
TLS client and server randoms, the certificate request context, and
session ticket material (nonce, ticket ID, ticket_age_add). The token
secret is now seeded through a helper that records success so token
generation and validation fail cleanly instead of silently operating
with a predictable secret.

The greasing bits in the Version Negotiation and Retry first bytes keep
using sys_rand_get(). RFC 9000 sections 17.2.1 and 17.2.5.1 make those
fields arbitrary and require peers to ignore them, so they need no
unpredictability and bind nothing.

Select CSPRNG_NEEDED so a cryptographically secure generator is pulled
in. That only works on platforms that have an entropy source, and
sys_csrand_get() otherwise degrades silently to the plain generator
while still returning success, so assert CSPRNG_ENABLED at build time.
QUIC_ALLOW_NON_CSPRNG overrides the assert for testing on platforms
without an entropy source.

Tested with twister on native_sim: tests/net/lib/quic passes (162
test cases), and the echo_server sample builds with overlay-quic.conf.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:45:36 -04:00
Jukka Rissanen
24c7b44f08 net: zperf: Check getsockname result before leaving mcast group
zperf_udp_leave_mcast() ignored the return value of
zsock_getsockname() and then inspected the address it was
supposed to fill in to decide whether an IGMP or MLD leave is
needed. If the call fails the address is not filled in, so the
family check operated on data the socket layer never wrote.

Return early when the call fails.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:44:14 -04:00
Jukka Rissanen
1894992b57 net: socks: Initialize proxy address length before getsockopt
net_socks5_connect() passed an uninitialized proxy_len to
net_context_get_option(). For NET_OPT_SOCKS5 the length is an
in/out parameter: get_context_proxy() rejects the call with
-EINVAL when the caller supplied value is smaller than the
stored proxy address length. With an indeterminate stack value
the call could therefore fail even though a proxy address had
been configured.

Set the length to the size of the address storage before the
call.

Tested by building samples/net/mqtt_publisher for native_sim
with overlay-socks5.conf.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:44:14 -04:00
Jukka Rissanen
2bfe692ec7 net: sockets: tls: Use net_sockaddr_storage for address storage
Set DTLS recvfrom/accept addrlen to sizeof(sockaddr_storage) now
that peer address locals use storage buffers. Using sizeof(sockaddr)
undersized the buffer and could truncate IPv6 peer addresses.

Assisted-by: Cursor:composer-2.5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:44:14 -04:00
Jukka Rissanen
a43066427a net: shell: Use net_sockaddr_storage for address storage
Use sockaddr_storage locals in net shell UDP/TCP bind, connect, and
send commands, and extend the ping context union with a storage
member. Shell commands parse user-supplied addresses that may be
IPv4 or IPv6.

Assisted-by: Cursor:composer-2.5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:44:14 -04:00
Jukka Rissanen
cd1336de10 net: capture: Use net_sockaddr_storage for address storage
Add storage union siblings to capture tunnel peer/local fields and
use storage locals when parsing tunnel setup addresses. IPIP capture
stores inner tunnel endpoints that may be IPv4 or IPv6.

Assisted-by: Cursor:composer-2.5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:44:14 -04:00
Jukka Rissanen
2bd3db56d5 net: wireguard: Use net_sockaddr_storage for address storage
Use sockaddr_storage for the local address passed to
net_udp_register() during WireGuard init. Registration needs a
buffer large enough for the selected address family.

Assisted-by: Cursor:composer-2.5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:44:14 -04:00
Jukka Rissanen
1779637bad net: midi2: Use net_sockaddr_storage for address storage
Use sockaddr_storage for the peer address in the UDP service
handler recvfrom path. Incoming MIDI2 command packets carry
IPv4 or IPv6 source addresses.

Assisted-by: Cursor:composer-2.5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:44:14 -04:00
Jukka Rissanen
c5a0d74822 net: socks: Use net_sockaddr_storage for address storage
Use a storage local when reading the SOCKS5 proxy address from
net_context and passing it to connect. get_option may return a
full IPv4 or IPv6 address.

Assisted-by: Cursor:composer-2.5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:44:14 -04:00
Jukka Rissanen
4fabaea447 net: ocpp: Use net_sockaddr_storage for address storage
Use sockaddr_storage for the OCPP upstream connect address buffer.
The charging-station client builds IPv4 or IPv6 sockaddr_in/in6
content before opening the websocket.

Assisted-by: Cursor:composer-2.5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:44:14 -04:00
Jukka Rissanen
94b8b43df3 net: ptp: Use net_sockaddr_storage for address storage
Use storage for PTP message sender addresses and UDP transport
multicast destination locals. IPv6 multicast addresses exceed
struct net_sockaddr capacity.

Assisted-by: Cursor:composer-2.5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:44:14 -04:00
Jukka Rissanen
7087ef641e net: ftp: Use net_sockaddr_storage for address storage
Wrap ftp_client.remote in a union with remote_storage. The FTP
client context stores the server address for the control/data
connections and requires full address storage.

Assisted-by: Cursor:composer-2.5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:44:14 -04:00
Jukka Rissanen
e1920097fe net: tftp: Use net_sockaddr_storage for address storage
Wrap tftpc.server in a union and use storage for recvfrom/connect
in the TFTP client. Server and reply addresses may be IPv4 or IPv6.

Assisted-by: Cursor:composer-2.5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:44:14 -04:00
Jukka Rissanen
be1d34f11f net: mqtt_sn: Use net_sockaddr_storage for address storage
Add a storage sibling to mqtt_sn_transport_udp.bcaddr and use a
storage local for bind setup. Broadcast and bind addresses need
IPv4 or IPv6 sized storage.

Assisted-by: Cursor:composer-2.5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:44:14 -04:00
Jukka Rissanen
0634e02529 net: mqtt: Use net_sockaddr_storage for address storage
Wrap mqtt_client.proxy.addr (SOCKS) in a union with addr_storage.
Proxy configuration stores a full socket address and must not use
the undersized generic sockaddr type.

Assisted-by: Cursor:composer-2.5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:44:14 -04:00
Jukka Rissanen
e4159d9804 net: lwm2m: Use net_sockaddr_storage for address storage
Add a storage sibling to lwm2m_ctx.remote_addr and use a storage
buffer in the engine recvfrom path. LwM2M UDP traffic may use IPv6
addresses that do not fit in struct net_sockaddr alone.

Assisted-by: Cursor:composer-2.5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:44:14 -04:00
Jukka Rissanen
c2d40b3010 net: coap: Use net_sockaddr_storage for address storage
Wrap coap_pending.addr in a union with addr_storage so pending
request remote addresses can hold IPv6.
Field name and sockaddr storage is changed for internal CoAP code.
Public API field (struct sockaddr addr) is left in order not to cause
API break.

Assisted-by: Cursor:composer-2.5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:44:14 -04:00
Jukka Rissanen
c96a28f95b net: zperf: Use net_sockaddr_storage for address storage
Add storage union siblings to zperf upload/download params and use
storage buffers in receiver statics and shell address parsing.
recvfrom/accept and session tracking need family-sized address
space, not the generic sockaddr type.

Assisted-by: Cursor:composer-2.5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:44:14 -04:00
Jukka Rissanen
ce315b30d9 net: dhcp: Use net_sockaddr_storage for address storage
Use sockaddr_storage locals in DHCPv4/v6 UDP registration init paths.
The unspecified bind addresses are written as full IPv4 or IPv6
sockaddr structures and must not be stored in struct net_sockaddr.

Assisted-by: Cursor:composer-2.5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:44:14 -04:00
Jukka Rissanen
a33f4fbcd9 net: dns: Use net_sockaddr_storage for address storage
Wrap stored DNS addresses (resolver servers, dispatcher local
address, addrinfo results, mDNS server) in unions with a storage
sibling. Use storage-sized buffers for recv, server compare/copy,
and management event payloads.

Assisted-by: Cursor:composer-2.5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:44:14 -04:00
Jukka Rissanen
64b66141de net: ip: Use net_sockaddr_storage for address storage
Store connection and context endpoint addresses in sockaddr_storage
siblings so IPv4 and IPv6 fit in net_conn, tcp_endpoint, and
net_context connect/recv paths. Existing remote_addr/local_addr and
sa union members are unchanged; socket APIs use net_sad() where a
full buffer is required.

Assisted-by: Cursor:composer-2.5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 13:44:14 -04:00
Emil Gydesen
cc79bc51b0 Bluetooth: Classic: HFP: Fix bad disconnect reason
BT_HCI_ERR_LOCALHOST_TERM_CONN is not a valid reason to
send to the remote.
Changed to BT_HCI_ERR_REMOTE_USER_TERM_CONN

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-08-11 13:43:18 -04:00
Jani Hirsimäki
b0b0e8973d net: ipv6: route: avoid net_nbr_get_lladdr() when neighbor LL is unknown
Neighbors can exist with NET_NBR_LLADDR_UNKNOWN. Passing that idx to
net_nbr_get_lladdr() trips the bounds assert in nbr.c.
Return -ESRCH from net_route_ipv6_packet() before resolving LL when idx
is unknown inside the net_route_ll_addr_supported() path.
Fixes assert-driven failures when forwarding via nexthops without a
linked link-layer address.

Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
2026-08-11 07:49:52 -04:00
Jukka Rissanen
81dbe9942e net: shell: ipv6: Print more status and config information
Print more information for IPv6 configuration and status like this:

  IPv6 forwarding                           : enabled
  IPv6 routing                              : enabled
  Transmit IPv6 RA messages                 : enabled
  IPv6 RA transmit interval                 : 30 sec
  IPv6 RA router lifetime                   : 1800 sec
  DHCPv6 client                             : enabled
  DHCPv6 requesting router (downstream RA)  : enabled
  DHCPv6 max downstream links               : 1
  DHCPv6 server                             : disabled

This helps figuring out what is being supported by the system.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 07:44:03 -04:00
Jukka Rissanen
0a3d31723e net: shell: ipv6: Right pad address type in printout
Print address type (autoconf vs DHCP) right padded so that
the output is properly printed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 07:44:03 -04:00
Jukka Rissanen
f3d3961bed net: shell: Add DHCPv6 server start/stop/status commands
Extend the "net dhcpv6" shell command with a "server" subcommand to
start and stop the DHCPv6 server on an interface, mirroring the
existing "net dhcpv4 server" commands. The "status" subcommand will
show currently allocated leases.

"net dhcpv6 server start <index> <prefix> <prefix len> [<address>]"
configures the prefix delegation (IA_PD) pool and, when an address is
given, the non-temporary address (IA_NA) pool, then starts the server.
"net dhcpv6 server stop <index>" stops it. Argument parsing and error
reporting (already running / not running / invalid input) follow the
DHCPv4 server commands.

Assisted-by: Claude:Opus-4.8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 07:44:03 -04:00
Jukka Rissanen
247c94aded net: dhcpv6: Add DHCPv6 server with prefix delegation
Add a DHCPv6 server so Zephyr can act as a delegating router. It
listens on UDP port 547 and implements the address assignment (IA_NA)
and prefix delegation (IA_PD) parts of RFC 8415.

The server handles the Solicit/Request/Renew/Rebind/Confirm/Release/
Decline exchanges, hands out addresses and prefixes from configured
pools and keeps a statically allocated binding table keyed by client
DUID. Addresses and prefixes are allocated uniquely per binding and
carry configurable preferred/valid lifetimes.

Join All_DHCP_Relay_Agents_and_Servers multicast group (ff02::1:2)
on the server interface in net_dhcpv6_server_start() and
leave it in net_dhcpv6_server_stop(), mirroring the router role's
all-routers (ff02::2) join. When MLD is disabled the address is still
registered locally so that the input path accepts it.

Behaviour is gated by CONFIG_NET_DHCPV6_SERVER with lease count and
lifetime tunables. The build wiring is adjusted so the dhcpv6 library
is compiled when either the client or the server is enabled.

A public API (net_dhcpv6_server_start()/stop()) starts the server on a
given interface with address/prefix pool parameters.

Assisted-by: Claude:Opus-4.8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 07:44:03 -04:00
Jukka Rissanen
24178782c1 net: dhcpv6: Delegate received prefix onto downstream link
A requesting router obtains an IPv6 prefix via DHCPv6 IA_PD but so far
Zephyr only installed it on the upstream (requesting) interface. To
actually act as a requesting router the delegated prefix has to be made
available to a downstream LAN.

Add a downstream_iface field to net_dhcpv6_params. When set (and
CONFIG_NET_IPV6_RA is enabled), a /64 sub-prefix is derived from the
delegated prefix and installed on the downstream interface as an
advertised prefix, together with a generated global address, so hosts
on the LAN can autoconfigure via the transmitted Router Advertisements.
The delegation is torn down when the prefix changes or the client is
stopped.

Assisted-by: Claude:Opus-4.8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 07:44:03 -04:00
Jukka Rissanen
6006f182b0 net: dhcpv6: Add Release, Decline and NoBinding handling
Improve the DHCPv6 client's RFC 8415 conformance for lease lifecycle
handling.

When a Reply to a Renew or Rebind reports NoBinding for an IA, the
client now restarts negotiation from the Request state instead of
treating the lease as valid (RFC 8415 ch. 18.2.10.1).

Two opt-in behaviours are added, both disabled by default to preserve
the existing behaviour and to avoid exhausting packet buffers in
constrained setups:

  - CONFIG_NET_DHCPV6_SEND_RELEASE_ON_STOP makes the client send a
    Release when stopped while holding a lease (ch. 18.2.7).
  - CONFIG_NET_DHCPV6_DECLINE_ON_DAD_FAILURE makes the client send a
    Decline, drop the address and restart when Duplicate Address
    Detection fails for a DHCPv6-assigned address (ch. 18.2.8).

Assisted-by: Claude:Opus-4.8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 07:44:03 -04:00
Jukka Rissanen
07e5dcf0b8 net: ipv6: Add Router Advertisement transmit and router role
Until now the native IPv6 stack could only receive Router
Advertisements; it had no way to act as a router. This adds the
ability for an interface to transmit RAs so that a prefix can be
advertised on a downstream link (required for DHCPv6 prefix
delegation, RFC 8415).

Add CONFIG_NET_IPV6_RA together with the RA interval and router
lifetime options. net_ipv6_send_ra() builds a Router Advertisement
with a Source Link-Layer Address option and one Prefix Information
Option per prefix marked for advertisement. A received Router
Solicitation is answered via a new handle_rs_input() handler and
unsolicited RAs are sent periodically from a work item.

The public API net_if_ipv6_router_start()/stop() enables the router
role on an interface and net_if_ipv6_prefix_set_advertise() marks a
prefix for advertisement. A per-prefix is_advertised flag and a
per-interface is_router flag back these.

Assisted-by: Claude:Opus-4.8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-11 07:44:03 -04:00
Sanjay Varghese
739652328f mcumgr: add SPI SMP transport
Add an SPI SMP transport for mcumgr where the device operates as an
SPI peripheral and exchanges raw SMP packets with the SPI controller,
with no additional framing layer. A single data-ready GPIO signals
the controller when a response is ready to be read, avoiding a
resident polling thread. Zero-byte packets are handled via
smp_reassembly_drop() to clear a partial reassembly buffer.

Includes the Kconfig, the zephyr,smp-spi devicetree binding, and the
SMP_SPI transport enum entry.

Signed-off-by: Sanjay Varghese <Varghesemela@gmail.com>
2026-08-11 07:41:54 -04:00
Nam Nguyen
c994c79021 arch: arm64: Add support for ARM Cortex-A720 CPU
Add ARMv9-A Cortex-A70 CPU support.

Signed-off-by: Nam Nguyen <nam.nguyen.xn@renesas.com>
2026-08-10 16:31:01 -04:00
Anas Nashif
4b5293a24c posix: net: zero-initialise the if_nameindex array
if_nameindex() allocated the array with malloc() and, on an allocation
failure part way through the loop, called if_freenameindex(), which walks
every entry and frees if_name - including entries still holding
uninitialised heap data.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-10 16:22:50 -04:00
Carlo Kirchmeier
a732d5aec1 net: coap: add OSCORE Echo challenge replay-window resync
This change adds RFC 8613 Appendix B.1.2 replay-window re-synchronization
for OSCORE context reuse after reboot.

When a server reuses an OSCORE context, it may lose recipient replay-window
state in RAM. In that state, incoming protected requests cannot be safely
accepted yet. The server now responds with a protected 4.01 Unauthorized
that carries an Echo option challenge. When the client retries with that
Echo value, the server verifies freshness and reinitializes replay-window
tracking from the request PIV/SSN, then resumes normal request processing.

Signed-off-by: Carlo Kirchmeier <carlo.kirchmeier.ext@siemens.com>
2026-08-10 16:22:40 -04:00
Carlo Kirchmeier
7c410c66eb net: coap: Add SSN persistence support
When the same OSCORE master secret and master salt
are reused across multiple device reboots, and no
new shared secret is established by other means,
the Sender Sequence Number (SSN) must be preserved
to prevent sequence number reuse.

Add support for periodically storing the SSN in
non-volatile memory (NVM), allowing the sender to
restore the last persisted value after a reboot and
continue operation in compliance with OSCORE security
requirements.

Signed-off-by: Carlo Kirchmeier <carlo.kirchmeier.ext@siemens.com>
2026-08-10 16:22:40 -04:00
Al Semjonovs
0636e65c82 ec_host_cmd: shi_ite: Fix race condition in request header processing
Prevent race condition where a secondary SPI request header
could overwrite in_msg while host command processing is active.

1. Add state check to ignore CS callbacks and RVLI interrupts when not
   in SHI_STATE_READY_TO_RECV / SHI_STATE_RECEIVING.
2. Read header into a local buffer for length and version validation
   before copying into in_msg.

Signed-off-by: Al Semjonovs <asemjonovs@google.com>
2026-08-10 16:22:11 -04:00
Robert Lubos
626931f395 net: lwm2m: Zero-initialize OMA TLV read buffer
oma_tlv_get() reads each byte through buf_read_u8() before use, so the
local buffer is never actually read uninitialized. The static analyzer
cannot model that across buf_read(), so it flags a use of an
uninitialized value. Zero-initialize the buffer to make the defined
state explicit and silence the false positive; the change has no
runtime effect.

Assisted-by: Cursor:claude-opus-4.8
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-08-10 16:18:58 -04:00
Robert Lubos
861e1b68da net: dns: Bound dispatcher local address copy by source length
register_dispatcher() copied a full family-sized address
(sizeof(struct net_sockaddr_in6) or net_sockaddr_in) from the
caller-supplied local buffer based on the address family, without
knowing how large that buffer actually was. For an IPv4 responder or
resolver the source is only a struct net_sockaddr_in, so a family that
did not match the buffer would read past it. Pass the source buffer
length and verify it is large enough before copying, in both the mDNS
responder and the DNS resolver.

Assisted-by: Cursor:claude-opus-4.8
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-08-10 16:18:58 -04:00
Robert Lubos
ba0bd94d4e net: mdns_responder: Use static storage for listener poll arrays
The socket service dispatcher stores the pointer to the poll fd array
passed at registration and reuses it later (e.g. when a peer
dispatcher on the same service is unregistered). The IPv6 and IPv4
poll arrays in init_listener() had automatic storage, so this stored
pointer dangled once the function returned, leading to a
stack-use-after-return. Move the arrays to file scope so they outlive
the registration, as the LLMNR responder already does.

Assisted-by: Cursor:claude-opus-4.8
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-08-10 16:18:58 -04:00
Robert Lubos
b85eb81e5e net: lwm2m: Validate buffer size against resource data type
lwm2m_check_buf_sizes() only verified that the resource data length
and the user buffer length matched each other, not that they matched
the width of the C type actually accessed by the get/set switch
statements (e.g. sizeof(double) for a float resource). Two equal but
wrong lengths would still pass, so a misconfigured resource or a
read/write callback returning a length inconsistent with the declared
type could access memory past the buffers.

Check both lengths against the exact size of the resource data type.
This hardens the get and set paths against such inconsistencies and
gives the static analyzer a local bound for the type-punned accesses.

Assisted-by: Cursor:claude-opus-4.8
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-08-10 16:18:58 -04:00
Robert Lubos
a26228e5ff net: lib: tls_credentials: Prevent digest wipe from being optimized out
A plain memset() used to clear the intermediate digest buffer can be
elided by the compiler. Clear it through a volatile pointer so the
wipe is always performed.

Assisted-by: Cursor:claude-opus-4.8
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-08-10 16:18:58 -04:00
Robert Lubos
00d15d5d8b net: lwm2m: Fix NULL access in SenML CBOR write handling
do_write_op_item() is called with a NULL record for block-wise
transfer continuations, so guard the record dereference. Also avoid
passing a NULL source to memcpy() when decoding a zero-length string.

Assisted-by: Cursor:claude-opus-4.8
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-08-10 16:18:58 -04:00
Erik Bérceš
99b18594b1 net: lib: wifi_credentials: fix overwriting a PSA-backed entry
Destroy the key held under the entry's key ID before importing the new
one to prevent psa_import_key() refusing to import onto a key ID that
is already taken. The entry keeps its index, so the documented
guarantee that overwriting credentials does not change internal
indices still holds.

Updated Doxygen notes to document then overwriting for the same SSID.

Signed-off-by: Erik Bérceš <erik.berces@nordicsemi.no>
2026-08-10 16:18:40 -04:00
Anas Nashif
ba63eb7414 debug: gdbstub: fix off-by-one in bin2hex buffer size check
gdb_bin2hex() rejected hexlen when (hexlen + 1) < buflen * 2, which
admitted hexlen == 2*buflen - 1. The loop writes indices 0..2*buflen-1,
so a one-byte write past the destination occurred for odd-length inputs.

Tighten the check to hexlen < buflen * 2.

Assisted-by: Claude:claude-sonnet-4-6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-10 11:34:25 -07:00
Robert Lubos
427d508f83 net: if: Clean up the IP config before releasing it
net_if_config_ipv{4,6}_put() only cleared the config pointers, so the
released config kept its addresses, prefixes and routers, left their
timer nodes linked in the file scope timer lists, and passed the previous
hop limit, TTL and gateway on to the next interface allocating the slot,
as the defaults are only applied at boot.

Remove everything the interface still holds and reset the config to its
defaults before returning it to the pool. The address removal is forced,
so a lingering reference cannot keep the slot populated.

Assisted-by: Cursor:claude-opus-5
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-08-10 09:18:08 -07:00
Jordan Yates
d00885d386 modem: chat: conditional chat scripts
Add the ability to attach a conditional check to an individual command
within a chat script that determines whether the command is run or not.
This is intended for use in long init or configuration scripts, where
dynamically creating the script is infeasible, but there is still a
query that should be run on the modem that triggers different
behaviours.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2026-08-10 09:12:41 -07:00
Jukka Rissanen
4938e6777d net: mqtt_sn: Drop message on failed payload extraction
decode_data() stored buf->len in dest->size and the pull_mem() result in
dest->data without checking it. With CONFIG_NET_BUF_HARDENING the pull can
fail closed and return NULL for a corrupted receive buffer, which would
have left the decoded mqtt_sn_data with a NULL data pointer but a non-zero
size for the caller to dereference.

Return an error from decode_data(), assigning the output only once the
pull has succeeded, and propagate it from the GWINFO, REGISTER and
PUBLISH decoders so the malformed message is dropped instead of consumed.
Without hardening the check is still compiled in but the pull never
returns NULL, so the only cost on the normal path is one always-false
branch per message.

Assisted-by: Claude:opus-4.8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-08-10 07:11:04 -07:00