The nonce is stored in a static variable, so multiple threads generating
a nonce at the same time could potentially interfere with one another
and the final nonce values used.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
We already have CMake and boot-time warnings for this insecure option,
add yet another one at the Kconfig level.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
The kernel already calls sys_trace_sys_init_enter/exit around every
SYS_INIT and device init, but the CTF backend stubbed them out. Implement
them so per-init timing is captured.
Record the device name when the entry is a device, so the event is
self-describing in any CTF reader. Bare SYS_INIT entries have no runtime
name, so the init_fn pointer is recorded instead for offline resolution.
The init level and result are included as well.
Assisted-by: Claude:claude-opus-4.8
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
The tracing backend initialized at a fixed APPLICATION level. Make the
SYS_INIT level (TRACING_INIT_LEVEL) and priority (TRACING_INIT_PRIORITY)
configurable so tracing can come up earlier and capture more of the boot
sequence.
The earliest level is PRE_KERNEL_2 (sync tracing only — async needs the
kernel for its drainer thread), and it requires a priority above the
system timer (SYSTEM_CLOCK_INIT_PRIORITY) so the cycle counter is live
and event timestamps are valid. The defaults (APPLICATION, priority 0)
preserve the previous behavior.
Assisted-by: Claude:claude-opus-4.8
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
The state->pa_sync was not properly assigned a few places, causing
invalid behavior in the shell.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The entropy-device generator performs no atomic operations; no atomic_*
or ATOMIC_* symbols are used. Remove the unused <zephyr/sys/atomic.h>
include.
Signed-off-by: Flavio Ceolin <flavio@hubble.com>
The timer-based generator only uses k_cycle_get_32() (kernel.h),
k_spin_lock() (spinlock.h), memcpy() and MIN(). Nothing from
<zephyr/drivers/timer/system_timer.h> is referenced. Remove the unused
include.
Signed-off-by: Flavio Ceolin <flavio@hubble.com>
The Xoshiro128++ generator seeds its state lazily on first use via the
'initialized' flag in z_impl_sys_rand_get(); it registers no SYS_INIT
handler and uses nothing from <zephyr/init.h>. Remove the unused include.
Signed-off-by: Flavio Ceolin <flavio@hubble.com>
SDIO public API documentation already lives in the public header.
Drop duplicate Doxygen blocks from the implementation file.
Signed-off-by: Hongquan Li <hongquan.li@processmission.com>
In Zephyr, POLLHUP on a TCP socket indicates that the peer closed the
connection normally (TCP FIN). It is set via sock_set_eof() in
zsock_received_cb() when pkt==NULL, and simultaneously triggers POLLIN
so that recv() can be called to consume the EOF (returning 0).
Commit 704c7d3073 incorrectly added POLLHUP to the error condition,
causing normal TCP connection close to be reported as socket error
(ECONNRESET/128) and losing throughput results. UDP is not connection-
oriented and does not use POLLHUP for session termination, so removing
POLLHUP from the UDP error condition is sufficient.
For TCP, also add a dedicated POLLHUP handler to cover the case where
POLLHUP arrives without POLLIN (recv_q empty at the time of FIN). This
ensures session completion even when the two events are not delivered
together. When both POLLIN and POLLHUP are set, the existing recv()
path handles EOF naturally (recv() returns 0).
Fixes: 704c7d3073 ("net: zperf: handle socket hangup events")
Signed-off-by: Li Long <li.long@nxp.com>
When USB control request cannot be handled the endpoint should be
stalled regardless of the reason. Simplify control request to host
handlers by changing the return type to the allocated buffer. Returning
NULL is enough to indicate to device stack that the request should be
stalled.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
For control transfers with data stage from device to host, only the
handler knows how large buffer is necessary (by specification host is
allowed to request up to 65535 bytes for every control read transfer).
While generally hosts do keep wLength relatively low, there are cases
where the value is big enough that the buffer cannot be allocated with
default UDC_BUF_POOL_SIZE value. Right now the only workaround is to
increase UDC_BUF_POOL_SIZE to large enough value but this is not a
viable solution on memory constrained targets. For example USB3CV
Mass Storage tests read string descriptor 0 with wLength set to 4096,
while the Zephyr response to this request is 4 bytes (and therefore 4
byte long buffer is enough).
Move the allocation to handler to allow the code to allocate as small
buffer as possible to handle the transfer. This allows MSC sample to
pass USB3CV with default UDC_BUF_POOL_SIZE value.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
If an ethernet driver sets NET_L2_ETHERNET_EXTRA_TX_PKT_HEADROOM, we
also need to add this extra headroom to the vlan packet just like we do
for the regular one on a regular ethernet interface. Otherwise, the
packet will not have the required headroom and the driver will not be
able to send it.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
add a Kconfig, that has to be selected by the
ethernet driver, when extra headroom on tx
is needed, that way we don't need to include that
code when only using NET_L2_ETHERNET_RESERVE_HEADER.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
1. use enum net_ip_protocol proto instead of uint16_t proto
2. use vlan_alloc_buffer() directly without having virtual_l2_alloc()
as a function that only calls vlan_alloc_buffer()
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
When CONFIG_NET_VLAN_COUNT == 0 and CONFIG_NET_VLAN is enabled,
priority tagged frames are allowed on the regular ethernet interface.
In this case, the functions net_eth_is_vlan_enabled() and
net_eth_get_vlan_iface() have a special behavior. This can be
implemented inline, for better performance and to avoid unnecessary
function calls.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
When we use get_reserve_ll_header_size we already have the info if the
packet is for a vlan iface or not.
So we can simplify the function and remove the unnecessary checks.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
Fix MCUboot shell command for TFM-merged slot builds.
In such case, the MCUboot header is placed at the end of
slot*_partition instead of the slot*_ns_partition.
Signed-off-by: Tomasz Chyrowicz <tomasz.chyrowicz@nordicsemi.no>
When a UVC device is removed, signal any waiting threads that buffers
have been aborted by raising the VIDEO_BUF_ABORTED signal. This ensures
proper cleanup and prevents threads from waiting indefinitely on buffers
that will never complete.
Signed-off-by: Mark Wang <yichang.wang@nxp.com>
When calling bt_le_per_adv_sync_get_info we should not provide
information from the PA sync object if it is not longer valid.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The previous '&& o_p->path.obj_inst_id' would
always return false if the obj_inst_id was 0,
which would lead to the deletion of all
observations for paths <obj_id>/0/<res_id>.
Signed-off-by: Diogo Sousa <sousadiogo7@gmail.com>
Remove the _transport_type field from bt_map_mce_mas, bt_map_mce_mns,
bt_map_mse_mas, and bt_map_mse_mns structures.
Replace all usages of `_transport_type` with `goep.v2` to determine
whether the active transport is L2CAP (v2) or RFCOMM (v1), since this
information is already encoded in the GOEP instance after
BT_GOEP_INIT_V1/V2.
Signed-off-by: Can Wang <can.wang@nxp.com>
Return -ENODATA when the End of Body header is missing.
Previously, the code did not return an error when End of Body
was absent, which could cause the caller to treat the message as
valid. Fix this by returning `-ENODATA` in this case.
Signed-off-by: Can Wang <can.wang@nxp.com>
The server-selection guard in dns_resolve_name_internal() only prevented
mDNS (.local) queries from being sent to unicast DNS servers. It did not
prevent the reverse: a regular query was still sent to the mDNS
multicast servers.
With CONFIG_DNS_RESOLVER_QUERY_ALL_AVAILABLE_SERVERS the loop breaks
after the first mDNS/LLMNR server (multicast only needs one send), so a
regular query that hit an mDNS server first was never forwarded to the
real DNS servers and timed out.
Make the guard symmetric: skip unicast servers for mDNS queries and skip
mDNS servers for non-mDNS queries.
Signed-off-by: Gerhard Jörges <joerges@metratec.com>
dns_resolve_init_locked() uses single stack-allocated local_addr4 and
local_addr6 structs that are reused for every server in the bind loop.
When mDNS is enabled, the local port of these structs is overwritten to
5353 for mDNS servers, but it was never reset for the unicast DNS
servers processed in later iterations.
Because the well-known mDNS multicast servers are added before the
unicast servers learned via DHCP/RA, any unicast DNS server of the same
address family that follows an mDNS server inherited the stale 5353
port and got bound to it. Its queries then went out with source port
5353 and the replies were no longer delivered to the unicast socket,
so all non-.local name resolution timed out whenever CONFIG_MDNS_RESOLVER
was enabled.
Reset the port to the configured value (ephemeral when port == 0) for
non-mDNS servers so that unicast DNS sockets bind to the correct port.
Signed-off-by: Gerhard Jörges <joerges@metratec.com>
Add a binary min-heap as a selectable timeout backend alongside the
sorted delta list, plugging into the backend abstraction rather than
forking timeout.c. Pending timeouts are kept in a min-heap keyed on
absolute expiry tick; insertion and arbitrary removal are O(log n),
which scales better than the delta list's O(n) insertion when many
timeouts are pending.
The backend is a new kernel/timeout_minheap.h: the heap instance (a
min_heap_ref from the previous commit), its comparator and the
z_timeout_q_*() operations, included only by timeout.c (after curr_tick)
so the whole backend stays private to that translation unit. struct
_timeout gains the abs_ticks + heap_handle representation, selected by
Kconfig (the delta list's node + dticks is the #else), with the common
fn pointer kept as a shared trailing member; the per-node helpers in
timeout_q.h grow a matching min-heap variant. The kernel shell thread
dump prints the backend's raw scheduling field (dticks or abs_ticks)
under #ifdef.
Because the shared z_add_timeout() already applies the post-#107452
conditional tick round-up, the heap inherits it: the backend's insert
simply stores abs_ticks = curr_tick + dticks. Likewise in-flight
handler synchronization (PR #109977) lives in timeout.c, so the heap
node carries no ANNOUNCING/ABORTED sentinels -- "not queued" is just
heap_handle.idx == 0.
The backend is EXPERIMENTAL, depends on TIMEOUT_64BIT (absolute ticks
need 64-bit precision), and uses a fixed-capacity heap
(CONFIG_TIMEOUT_HEAP_MAX_ENTRIES) whose overflow is a fatal error.
The min-heap algorithm, struct fields, Kconfig and capacity model are
derived from Sayooj K Karun's min-heap timeout subsystem (#106013),
reworked here to fit the pluggable backend and the current in-tree
in-flight-handler synchronization.
Co-authored-by: Sayooj K Karun <sayooj@aerlync.com>
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
The external-PSK binder was computed over the ClientHello truncated at the
binder value, i.e. including the 2-byte binders vector length and the
1-byte binder length prefix. RFC 8446 4.2.11.2 truncates the transcript at
the end of the pre_shared_key identities field, before those bytes.
Because both the Zephyr client and server used the same over-long
transcript, resumption and 0-RTT interoperated Zephyr-to-Zephyr but not
with a standards-compliant TLS 1.3 / QUIC peer, which would compute the
binder over the shorter transcript and reject the PSK with a decrypt or
bad-binder error.
Truncate the transcript at the end of the identities field on both sides:
the server uses identities_end (independent of which identity matched, as
the RFC requires), and the client subtracts the binders-header length from
the binder value offset. No change to the Zephyr-to-Zephyr result; the
tests keep passing.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
endpoint_alloc() memsets the reused slab slot when an endpoint is
allocated. If an endpoint were ever freed with its recovery pto_work
delayable still linked in the recovery work queue's timeout list, that
memset would zero a live _timeout node and corrupt the global kernel
timeout list, surfacing later as a baffling assertion in unrelated code.
The teardown path already cancels pto_work: quic_endpoint_unref() calls
quic_recovery_begin_shutdown(), which sets recovery.closing under
recovery.lock (so no reset path can re-arm the timer) and then
synchronously cancels it. Add a debug assertion right before the slab
free so any future teardown regression that breaks this invariant fails
immediately and locally instead of corrupting the timeout list.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
RFC 9001 4.9.3 says a client SHOULD discard its 0-RTT keys once 1-RTT
keys are installed and a server MUST discard them a short time after the
handshake completes. The stack instead kept the early crypto context
alive until the endpoint was torn down, leaving replayable early-traffic
key material resident for the whole connection.
Destroy the early crypto context when the handshake completes, for both
roles. A 0-RTT packet that arrives late or reordered after that point can
no longer be deferred until early keys appear (they are gone), so drop it
on the server; the client retransmits any unacknowledged stream data
under 1-RTT.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
RFC 8446 4.2.11 and RFC 9001 4.6.1 require that 0-RTT early data is only
valid when the resuming handshake negotiates the same application
protocol (ALPN) as the connection that issued the ticket. The server did
not check this, so a resuming ClientHello that selected a different ALPN
could still have its early data accepted.
Remember the negotiated ALPN in each server ticket-cache entry and, when
deciding whether to accept early data, compare it against the ALPN
negotiated by the resuming ClientHello. On a mismatch, fall back to a
1-RTT resumption with early data refused. An ALPN name that does not fit
the remembered buffer disables 0-RTT for that ticket rather than risking
a truncated match.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
RFC 9001 4.6.1 requires that, in QUIC, the NewSessionTicket early_data
extension carries the fixed 0xffffffff sentinel and that the amount of
early data a client may send is bounded by the connection's flow-control
limits (transport parameters), not by a separate byte value. A client
MUST treat any other extension value as a connection error.
The server previously wrote its configured byte cap into the extension
and enforced that cap with a bespoke per-frame counter, while the client
accepted and stored the value verbatim. That is non-compliant, would not
interoperate with a standard QUIC peer, and could spuriously close a
compliant client that stayed within the advertised flow-control window.
Advertise the sentinel from the server and validate on the client that
the received value is the sentinel, rejecting anything else with a
protocol violation. Drop the bespoke early-data byte counter and rely on
the existing stream and connection flow-control checks (restored from the
remembered transport parameters on resumption) to bound early data. The
configured max_early_data_size is now only an enable signal for newly
issued tickets, not an advertised or enforced byte cap.
Add a unit test for the client-side sentinel validation and update the
resumption test to expect the sentinel in the exported session state.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
h3_stream_received_early_data() returned false (treating a request as not
early data) when the early-data getsockopt failed, which would skip the
425 Too Early replay protection. Treat an undetermined status as early
data instead, so replay protection is applied conservatively.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Intermediate PSK-derived key material was left on the stack after use.
Zeroize it once it is no longer needed: the external-PSK binder keys
(early/binder/finished secrets), the client early-traffic secret, and the
resumption PSK stack copy after it is stored in the ticket cache. This
limits how long long-lived 0-RTT/resumption secrets linger in reusable
stack memory.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
handle_stream_frame() delivered 0-RTT STREAM data into the stream receive
buffer first and only afterwards checked it against max_early_data_size,
so data beyond the negotiated early-data limit could be read by the
application before the connection was torn down. The check also used the
flow-control acceptance delta rather than the received STREAM frame length
the RFC specifies.
Check the early-data limit on the received frame length before delivering
the bytes to the stream, so over-limit early data never reaches the
application (RFC 9001 4.6.1).
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Server session tickets could be replayed for their full 24h lifetime:
tls_server_ticket_cache_lookup() only invalidated entries on expiry,
never on use, and the client's obfuscated_ticket_age was parsed but
never checked. A network attacker could therefore replay a captured
ClientHello (and its 0-RTT early data) repeatedly, completing PSK-resumed
handshakes and, when early data is enabled, having the server re-accept
and re-deliver the replayed bytes (RFC 8446 8.1/8.2, RFC 9001 9.2).
Make tickets single-use: once the PSK binder is verified, consume the
matching cache entry so a replayed ClientHello can no longer resume or
replay 0-RTT. Add a freshness check that only accepts 0-RTT when the age
the client reports is within a window of the age the server expects.
Add unit tests for the single-use cache behaviour and the age check
(test_086, test_087).
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
quic_retransmit_stream_frame() read the stream TX buffer and sent
directly from it without holding tx_lock, while still calling
k_mutex_unlock(&stream->tx_lock) on its exit paths. The callers do not
hold tx_lock, so those unlocks were no-ops and the buffer was accessed
unlocked, racing with the ACK path that advances and compacts the same
buffer.
Acquire tx_lock, copy the lost frame payload into a scratch buffer, then
release the lock before sending. The lock must not be held across the
send: the send records the packet under recovery.lock while the ACK path
takes recovery.lock then tx_lock, which would invert the lock order. The
scratch buffer is kept in .bss (it can be up to CONFIG_QUIC_TX_BUFFER_SIZE
bytes) rather than on the stack, and a dedicated mutex serializes the two
threads that can retransmit (ACK-driven loss and PTO).
Tested with tests/net/lib/quic (net.quic) on native_sim and qemu_x86.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Wire QUIC session ticket and early data socket options from the
HTTP/3 service configuration so that servers can advertise
resumption parameters and accept 0-RTT traffic.
After creating the QUIC listen socket, apply
QUIC_SO_SESSION_TICKET_ENABLE when h3_enable_session_tickets or
h3_max_early_data_size is set.
Add h3_stream_received_early_data() helper that checks
QUIC_SO_STREAM_EARLY_DATA via getsockopt and caches the result
in http3_stream_ctx.early_data.
Add h3_request_method_is_replay_safe() to allow only GET, HEAD,
and OPTIONS on 0-RTT streams; all other methods are rejected
with 425 Too Early.
Assisted-by: Copilot:claude-sonnet-4.6
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Defer server-side 0-RTT packets until early keys are available
so queued early data is not decrypted and dropped before the
server decides whether to accept it.
Derive application traffic secrets before finalizing TLS
resumption state. The previous order used incomplete state for
ticket resumption, which made the peers compute different PSKs
and fail binder validation on resumed handshakes.
Also preserve queued peer streams when moving an accepted
connection to its child context, and mark accepted streams
readable immediately when data was already buffered.
When closing the connection, drain all incoming stream sockets
that were not yet accepted. This issue was seen with incoming
early data that was received at the same time in the server.
Assisted-by: Copilot:gpt-5.4
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Add CONFIG_QUIC_0RTT, defaulting to n, so builds can keep
session resumption support while compiling out 0-RTT offer,
acceptance, replay, and policy handling when desired.
0-RTT early data is replayable by a network attacker
(RFC 9001 section 9.2), so shipping it on by default risks surprising
applications that expose non-idempotent operations.
When disabled, the stack no longer advertises or arms early
data, imported/exported session state clears the remembered
early-data limit, and ZSOCK_QUIC_SO_MAX_EARLY_DATA_SIZE
rejects non-zero values with -ENOTSUP. Update the QUIC tests
to keep the same assertions meaningful in both modes.
Keep test coverage of both paths: the base net.quic scenario
builds the default (0-RTT disabled) configuration, while the
net.quic.0rtt scenario and the HTTP/3 server test enable
CONFIG_QUIC_0RTT=y explicitly to exercise the enabled build.
Assisted-by: Copilot:gpt-5.4
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Derive and install the client early traffic secret once the
ClientHello transcript is available so ticket-based 0-RTT
can arm the early crypto context at runtime.
Add regression coverage for 0-RTT policy export and import
through session tickets, keep explicit checks that rejected
early data disables the send path, and document in the QUIC
API that imported 0-RTT state only permits replay-safe data
and can still be rejected by the peer.
Assisted-by: Copilot:gpt-5.4
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Add the missing policy and TLS state needed to negotiate
ticket-backed 0-RTT cleanly. The server now exports a
max_early_data_size sockopt, advertises that limit in
NewSessionTicket, and confirms accepted early data in
EncryptedExtensions.
When 0-RTT is rejected, stop treating the early packets as
in flight, reset stream send accounting to the ACKed point,
and replay queued stream data under 1-RTT protection and the
newly negotiated flow-control limits. Also tighten the
client so only session-ticket resumptions offer early data,
and add focused coverage for the accept/reject decision and
rejected-packet cleanup paths.
Assisted-by: Copilot:gpt-5.4
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Handle 0-RTT packets with the early crypto level instead of dropping
them, and enforce the RFC frame restrictions for 0-RTT packets.
Allow client stream open/send/FIN and stream retransmission to use
early keys when imported session state has armed 0-RTT, while keeping
the normal handshake wait for connections that do not have resumable
state.
Add focused regression coverage for the 0-RTT frame allowlist and the
client-side early-data arming logic.
Assisted-by: Copilot:gpt-5.4
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Store the server transport-parameter snapshot in QUIC session
state and restore those limits when resumable state is imported
on a new client connection.
This preserves the peer flow-control values that a later 0-RTT
attempt will need before fresh transport parameters arrive.
Add the resumed-parameter compatibility check for remembered
initial limits, but gate it on early-data acceptance so normal
resumed handshakes keep existing behavior until the 0-RTT data
path is wired in.
Bump the session-state format version to 2 for the new transport
parameter fields.
Assisted-by: Copilot:gpt-5.4
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Add QUIC session ticket handling for the staged 0-RTT work.
Derive and retain the resumption master secret at handshake
completion, generate NewSessionTicket on the server, parse and
store the ticket on the client, and expose resumable session
state through a QUIC socket option.
Keep ticket issuance disabled by default and gate it with a new
QUIC sockopt so existing server behavior stays unchanged until a
caller opts in. Add a regression test that enables tickets,
exports the stored session state, imports it into a fresh client
connection, and verifies the state round trip.
Assisted-by: Copilot:gpt-5.4
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>