Nothing has called the get_mtu callback of struct smp_transport_api_t
since commit c56b45c3e8 ("mgmt: mcumgr: Fix output packet to frame
issue on serial transport") removed SMP-level response fragmentation.
Each transport fragments outgoing packets itself in its output
function, using its own link limits.
Deprecate the smp_transport_get_mtu_fn type and the get_mtu member,
and document on smp_transport_out_fn that fragmentation and reassembly
are the transport's responsibility. In-tree transports keep providing
the callback until it is removed, with the deprecation warning
suppressed where they set it. The test stubs no longer set it.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Aric Radzin <aric.radzin@gmail.com>
dns_write() and dns_resolve_init_locked() scan ctx->fds testing two things
per element - "is this my socket" and "is this slot free" - and act on
whichever hits first. That is only correct while the array has no holes.
Since commit 7bc1c58188 ("net: lib: dns: Keep polling remaining servers
on single close"), dns_server_close() clears only the closed server's slot
instead of blanking the array, so a hole can outlive the next query. A
socket sitting later in the array is then duplicated into the hole in
front of it:
close server 0 when its interface goes down -> fds = [-1, 5]
next query to server 1 (socket 5) -> index 0 is a hole and is
claimed first
-> fds = [5, 5]
a replacement server arrives, socket 6 -> no match, no free slot
The array now holds the same fd twice and the new server can never get a
poll slot. Every lookup reports "Cannot set polling to socket (-2)" and
falls back to the server on the interface that just went down. With two
interfaces this makes failover work in one direction only, which is the
tell.
dns_resolve_init_locked() has a second, quieter half: it never reset ret
before its scan, so ret still held bind_to_iface()'s 0 (or the socket fd),
and a full array fell through the "Cannot set polling" branch entirely.
The server was registered and then never polled, with nothing logged.
Scan the whole array for an existing entry, remember the first hole, and
claim it only if nothing matched; reset ret first so that a full array is
a real error.
Verified on hardware with two interfaces, one Ethernet and one PPP: three
back-to-back failover cycles, six transitions, each resolving on the
returning interface's server with no DNS errors.
Fixes#117951
Assisted-by: Claude:claude-opus-5
Signed-off-by: Joel Simmons <jsimmons22250@gmail.com>
Without this fix, a simple IPv6 ping from a host on an adjacent link
(e.g. the AIL) to a device reachable via a different egress interface
fails: when the next hop is not yet in the neighbor cache,
net_route_ipv6_packet() returned -ENOENT and the packet (for a ping,
the ICMPv6 Echo Reply) was dropped by the router.
Instead of dropping it, clear the link-layer destination the packet was
received with. net_send_data() then re-enters net_ipv6_prepare_for_send(),
which already solicits the next hop and queues the packet until the
Neighbor Advertisement arrives, reusing the existing forwarding path
(hop-limit decrement, egress interface selection, NULL NS source address
when forwarding). This mirrors the unknown-neighbor handling already used
for locally-originated packets. When CONFIG_NET_IPV6_ND is disabled the
previous -ENOENT behavior is kept.
Add a regression test (net.route.ipv6.forward_nd): forward a packet to an
unresolved next hop on an Ethernet interface, verify one NS is sent and
the packet is queued, then resolve the neighbor and verify the queued
packet is transmitted on the outbound interface.
Assisted-by: Claude:claude-sonnet-4.6
Signed-off-by: Jean-Yves Salaun <jean-yves.salaun@nxp.com>
Use new I3C_MSG_NOACK_EXPECTED to mark the periodic reads of the polling
mode as expecting NACKs. This way, controller drivers that support it
can be less verbose about them.
As this new contract uses `-ENODATA` to sinalise expected NACKs, we can
also restart logging true errors when using polling.
Assisted-by: Claude:claude-sonnet-5
Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
Up until now offloaded sockets bind their local port inside the
offload engine, outside the net_context list, so
net_context_port_in_use() cannot see them.
This commit adds recording of each offloaded socket's local
binding in the socket layer and adds net_socket_port_in_use()
which consults both the socket and the context layer for
in use ports.
Signed-off-by: Carlo Kirchmeier <carlo.kirchmeier.ext@siemens.com>
Make the mDNS responder work over offloaded sockets:
- Join the multicast groups through IP_ADD_MEMBERSHIP /
IPV6_ADD_MEMBERSHIP and pin egress with IP_MULTICAST_IF /
IPV6_MULTICAST_IF, instead of calling the native igmp/mld helpers, so
offloaded stacks manage the membership themselves. The leave stays on
igmp/mld because a socket close does not drop the net_if membership on
native.
- Set SO_REUSEADDR on the responder sockets: 5353 is a shared mDNS port
meant to be co-bound by multiple listeners.
- Skip the port-in-use check on offloaded interfaces, where net_context
cannot see the host binding.
Signed-off-by: Carlo Kirchmeier <carlo.kirchmeier.ext@siemens.com>
The offloaded interface has no Zephyr-side IP addresses because the host
stack owns them, so responders such as mDNS cannot answer hostname
queries (e.g. zephyr.local).
Enumerate the represented host interface's addresses and register them on
the offloaded net_if when it comes up, including the netmask. The
snapshot is taken once at interface-enable; later host address changes
(DHCP renew, add or remove) are not reflected. Raise the default
per-interface unicast address counts for NSOS builds to hold them.
Signed-off-by: Carlo Kirchmeier <carlo.kirchmeier.ext@siemens.com>
A timed benchmark fences before taking its starting timestamp but not
before taking the ending one, so the work it measures need not have
retired by the time the clock is read: on an out-of-order core the
reported duration can be short by whatever is still in flight, and the
error grows with how much the benchmark leaves outstanding.
Fence on the way out as well, so that both ends of the measurement are
ordered against the work between them.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
The outlier count reported every sample above the median. The
baseline of a benchmark is not one exact value: the resolution of
the timing counter spreads it over a few counts, and where that
counter is coarse relative to what is measured the whole
distribution can span as little as two values. Half the samples
then land above the median and are counted as outliers although
nothing disturbed them, and the count grows as the measurement
improves.
Require a sample to exceed the median by a margin, configurable
as a divisor of the median and floored at two counts. Also record
why a corrected statistic is allowed to come out negative.
Assisted-by: Claude:opus-4-8
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
The standard error describes how precisely the mean of one stochastic
population has been estimated. A kernel latency distribution is not
that: it is a baseline the operation hits on almost every run plus a
handful of runs that something interrupted. Ten thousand samples of
760 cycles and one of 1240 give a mean of 760.042 and a standard error
of 0.048, which reads as precision about an average that no single
execution ever produced.
Spend that space on the number of samples slower than the median
instead. For these distributions that is exactly the count of
disturbed runs, and it says so plainly: 1 / 10000. It comes from the
sorted percentile buffer, so it is reported wherever percentiles are.
Restructure the human-readable block around the distribution as a
result, leading with the sample size, mean, standard deviation and
minimum, then the percentiles, then the maximum with the run that
produced it, and closing with the outlier count, the cold cost and the
warmup. The standard error stays in the CSV output, whose column
layout is fixed; the percentile row gains the outlier count.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
A benchmark's first execution runs with cold caches, branch predictors
and TLBs and can be an order of magnitude slower than its steady state.
Folded into the distribution it moves the maximum and the standard
deviation while describing a state the benchmark is never in again, and
it is the number an application that runs a path once at startup
actually cares about.
Record it separately as the cold cost, reported alongside the
distribution rather than instead of it, and add
CONFIG_ZTEST_BENCHMARK_WARMUP for the iterations to execute before
sampling starts.
The warmup applies to every benchmark in the image rather than being
selectable per benchmark, and defaults to zero, so sampling starts at
the first iteration exactly as it did before. Discarding iterations is
not free: on a micro benchmark whose whole cost is comparable to a cache
miss it costs accuracy, and with a large enough sample count the first
iteration has no measurable effect on the mean. The cold cost is
reported either way, so a cold start stays visible without discarding
anything.
Warmup and measurement run as two loops rather than one loop with a test
on the iteration number. Such a test flips exactly once, on the first
measured iteration, so the mispredict lands on the one sample the warmup
exists to protect; the loop bounds fold at build time instead, the
warmup count being a Kconfig constant.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
The mean was corrected by the full control measurement while the
discrete statistics were corrected by its integer part, so the two
stopped describing one set of samples whenever the control was below
one cycle. On a Cortex-M board with a control of 0.996 cycles, a
benchmark whose samples were all exactly 171 reported:
Mean(u): 170.004
Min: 171
Max: 171
which is not arithmetically possible for any set of values. The
minimum, maximum, total and percentiles had in effect not been
corrected at all, since the integer part of 0.996 is zero.
Correct every statistic by the same real-valued control and report the
corrected values as real numbers. They no longer coincide with any
single measurement, which is inherent to subtracting a fractional
overhead estimate, but they now describe the same distribution. This
went unnoticed under emulation, where the control measurement is an
exact integer with no variance.
The minimum, maximum and total columns of the CSV output become real
numbers as a result.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
The mean and the standard error describe how precisely the average was
estimated. That is the right question for throughput, but not for
latency: a real-time system is characterised by how bad an individual
operation can be, and that lives in the tail rather than near the mean.
Welford's method keeps no samples, so the framework could not report a
tail at all.
Add CONFIG_ZTEST_BENCHMARK_PERCENTILES, which retains the samples of
each sampled or manual benchmark and reports min, p50, p90, p99,
p99.9, p99.99 and max alongside the existing statistics, as an extra
'P' row in CSV mode so that existing parsers keep working.
Measuring interrupt entry latency on a loaded system shows why this
matters: the mean is 1264 cycles with a standard error of 34, which
describes no interrupt that actually occurred, while the percentiles
show 1216 cycles out to p99 and 25184 beyond it.
Samples are retained in a buffer of CONFIG_ZTEST_BENCHMARK_MAX_SAMPLES
entries; anything beyond it is dropped and the report says how many,
since percentiles over a truncated prefix are biased. A percentile
also has to be resolvable by the sample count, p99.9 needing a
thousand samples and p99.99 ten thousand, which the documentation
spells out.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Standard and timed benchmarks are timed by the framework, which takes
both timestamps in thread context around each invocation of the body.
Some measurements cannot be expressed that way, because the span to
measure is not the whole body and does not necessarily begin and end in
the same execution context: the latency from raising an interrupt to the
first instruction of its ISR, or from the end of an ISR to the thread it
wakes.
Add ZTEST_BENCHMARK_MANUAL(), which keeps the loop, the setup and the
teardown in the framework and hands the body only the choice of what is
measured. The body brackets the interesting part with
ztest_benchmark_start() and ztest_benchmark_end().
Neither hook records anything: they only take timestamps, so both are
safe to call from an ISR and a span may begin in one context and end in
another. The runner turns the marked span into a sample once the body
has returned, which is what keeps the floating point of update_metrics()
out of interrupt context, where it is not allowed on every architecture.
That also keeps the timing API out of the public header.
A manual span costs the two timestamps that bracket it and nothing else:
the body is not called from inside the span, so the indirect call that
the sampled control measures is not part of one. Correcting against the
sampled control would subtract an overhead a manual sample never paid,
so manual benchmarks get a control of their own, an empty span with the
framework's own hooks around it. Results are reported as an "M" record
with the same statistics as a sampled benchmark.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Hopefully a script that helps the zassert migration for various subsystems.
1. ./scripts/coccicheck --mode=patch \
--cocci=subsys/debug/zassert/zassert.cocci ${path} > patch.diff
2. git apply patch.diff
3. Pray to what ever deity you feel like and verify
Known limitations:
* It will not be able to add a ZASSERT_MODULE(...) to the TUs it modifies,
so you will have to do that manually.
* It will not know the distinction between a .c and .h file so it will not
add the ZASSERT_MODULE(...) neccesary for the .h files. You will have to
do that manually as well.
Signed-off-by: Måns Ansgariusson <mansgariusson@gmail.com>
When the malloc arena uses the RAM left after the image, a
nearly full image can leave less space than a heap needs. With
assertions disabled, the heap was still set up on that space
and allocations corrupted the memory past it.
Treat such an arena as empty, including when its size wraps or
its mapping fails, so allocations fail with ENOMEM, and log a
warning. Since the malloc partition is then empty, ztest no
longer adds it to the default memory domain.
Assisted-by: Claude:opus-5
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
Do not bind the driver instance if the usbh_class_probe() return value
is not 0.
Reported-by: Github user zups
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Fix two problems in the SNTP resync path.
First, the SNTP resync could re-enable itself after the connection manager
disabled it. If any async callbacks or timeouts were active when the
NET_EVENT_L4_DISCONNECTED occured, they could reenqueue the
sntp_resync_work after the l4_event_handler canceled it. This was a
pre-existing issue in the resync code.
Second, the new net_config_sntp_set_server allowed the application to
schedule a resync, which did not check if there was already a resync in
progress with pending async callbacks or timeouts. It would also re-enable
the resync if it was disabled by the l4_event_handler.
Fix both issues by tracking whether the resync is currently in progress
with the sntp_resync_in_progress flag, and track if it is enabled with the
sntp_resync_enabled flag. Both of these flags are protected by a mutex. The
enabled flag is toggled only by the l4_event_handler. The other points
where a resync can be initiated, net_config_sntp_set_server and
net_config_init_clock_via_sntp, only queue the resync work if the enabled
flag is set. The in_progress flag is set only by the sntp_resync_handler,
and cleared on error or when the last callback in the async resync chain is
reached. If the sntp_resync_handler happens to be called while the
in_progress flag is already set, it reschedules itself and does
nothing. This prevents multiple resyncs being active at the same time.
Signed-off-by: Matthias Blankertz <matthias.blankertz@inovex.de>
In addition to the existing options of getting the SNTP server from
DHCPv4, or using a hardcoded server from the
CONFIG_NET_CONFIG_SNTP_INIT_SERVER option, add an API to allow the
application to set the SNTP server at runtime.
When enabled with the new CONFIG_NET_CONFIG_SNTP_INIT_SERVER_RUNTIME
option, the application can call the net_config_sntp_set_server function
to set a hostname or IP address to use as an SNTP server. This server is
used by subsequent calls to net_config_init_clock_via_sntp. If
CONFIG_NET_CONFIG_SNTP_INIT_RESYNC is enabled, a resync with the new
server is immediately queued.
Implementation-wise, this hooks into the existing sntp_init_helper and
sntp_resync_handler functions. The last configured server name is copied
into a secondary buffer at the start of each (re)sync, to ensure it does
not change while a (re)sync is running.
Signed-off-by: Matthias Blankertz <matthias.blankertz@inovex.de>
Rename net_init_clock_via_sntp to net_config_init_clock_via_sntp so that
it has the same net_config prefix as the other functions defined here.
Also declare the net_config_init_clock_via_sntp function in the
net_config.h header and remove the 'extern' declaration from init.c.
Signed-off-by: Matthias Blankertz <matthias.blankertz@inovex.de>
When building for native_sim, the reference to gmtime_r in
timespec_to_rtc_time causes a compilation error. Fix this by moving the
entirety of timespec_to_rtc_time and sntp_set_rtc inside the
CONFIG_NET_CONFIG_CLOCK_SNTP_SET_RTC block.
Signed-off-by: Matthias Blankertz <matthias.blankertz@inovex.de>
Use the public bt_att_get_max_ntf_size function to get the
current notification size, rather than using the
LE Audio specific one.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Applications that send notifications larger than the ATT_MTU have to
truncate them to ATT_MTU - 3, but the 3-octet ATT_HANDLE_VALUE_NTF
header size was only available in the internal ATT header, so every
user had to define it again.
Add bt_att_get_max_notify_size() and bt_att_get_max_indicate_size()
to the public ATT API.
Assisted-by: Copilot:claude-sonnet-4.5
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
net_if_try_send_data() checks net_pkt_family(pkt) twice, in two
separate if statements, with the call to net_ipv6_prepare_for_send()
between the two reads.
A prepare function that returns NET_CONTINUE has handed the packet
over and the caller must not look at it any more. Two paths do that:
the IPv6 neighbor discovery pending queue, where the packet is sent
and freed while the caller is descheduled inside net_ipv6_send_ns(),
and IPv6 fragmentation, which unrefs the packet before returning.
Once the block is released the packet slab gives it to the next
allocation. If that is an IPv4 packet, the second if reads
NET_AF_INET from memory the caller no longer owns,
net_ipv4_prepare_for_send() replaces NET_CONTINUE with NET_OK, and the
stale pointer is queued for transmission. Depending on whether the
IPv4 packet is still referenced, it is transmitted and unreferenced
twice, or the TX thread dereferences a released buffer in
ethernet_fill_in_dst_on_ipv4_mcast() and the system faults.
net_try_send_data() already follows this rule one frame up: it caches
the interface and the family before the call, because the packet
might contain garbage once the call returns.
Read the family once, before the call, and make the branches
exclusive, so the packet is not looked at after a prepare function has
returned.
Signed-off-by: Кирило Шипачов <kshypachov@outlook.com>
dsa_xmit() decided whether to wait for a TX timestamp based on the
frame's EtherType (NET_ETH_PTYPE_PTP) rather than the packet's
timestamp-request flag. This mismatched the NETC driver, which uses
net_pkt_is_tx_timestamping(pkt), so DSA could wait for a timestamp on
a PTP frame (e.g. a gPTP announce) the driver never generates, hanging
the TX path.
Use net_pkt_is_tx_timestamping(pkt) instead, matching the NETC driver.
This also removes the outdated DSA PTP EtherType condition.
Signed-off-by: Youri Tils <youri.tils@nxp.com>
An ERROR packet answering a data block only left send_data()'s inner
loop, so the client fell through to retransmitting the block the server
had just refused. It kept that up until the retry count ran out and then
reported retries exhausted, hiding the rejection it had already handed
to the callback. tftp_get() and tftp_put()'s own request handling both
return TFTPC_REMOTE_ERROR on an ERROR packet instead.
Return TFTPC_REMOTE_ERROR from that branch, and log it at error level
now that it ends the transfer rather than costing a retransmit. The
return after the outer loop was already unreachable, since nothing
breaks out of it, and is dropped.
The two rejection cases in tests/net/lib/tftp/src/error_response.c
discarded tftp_put()'s result, so neither noticed the transfer
continuing past the rejection. Both now assert TFTPC_REMOTE_ERROR;
without the change above they fail with retries exhausted.
Signed-off-by: Arkadiusz Grzelka <devitwise@gmail.com>
Assisted-by: Claude:claude-opus-5
send_data() checks the length of the server's response before it reads
the opcode, and treats anything longer than a bare header as a
malformed reply: it drops the packet and retransmits the data block.
An ERROR packet grows past a bare header as soon as the server says why
it refused, which RFC1350 both allows and expects. tftp_get() and
tftp_put() pass that message on when it answers the request, but
send_data() drops it, so a rejected data block reaches the application
only when it carries no message. Against a server that explains itself
the callback never fires and the transfer ends in retries exhausted.
Read the opcode first, and demand the exact header length only of the
replies that have nothing legal to follow it. A response shorter than a
header is still refused, and so is an ACK with bytes trailing it.
Signed-off-by: Arkadiusz Grzelka <devitwise@gmail.com>
Assisted-by: Claude:claude-opus-5
When the server rejects a data block, send_data() passes block_no to
the callback. That is the block the client is transmitting; the code
parsed out of the server's ERROR packet is in blockno. An application
acting on what it is given sees the wrong thing in both directions: a
rejection of block 3 arrives as 'disk full', and a genuine disk-full
rejection of block 1 arrives as 'file not found'.
The warning logged beside it described a stale block number, which is
the case the branch directly above handles.
Signed-off-by: Arkadiusz Grzelka <devitwise@gmail.com>
Assisted-by: Claude:claude-opus-5
RFC 1350 requires the message in an ERROR packet to be NUL terminated.
The client does not check this. It hands the application a char * into
tftp_buf with no length. A server that fills the datagram and omits the
terminator makes the application read past the buffer. tftp_buf is the
last member of struct tftpc, which the application owns, so the read
runs off the end of that object.
Put the terminator right after the last received byte, clamped to the
last byte of tftp_buf, so the helper stays inside the buffer whatever
size its caller passes. A terminated message is unaffected, and an
unterminated one arrives whole unless it fills the buffer, in which
case its last character gives way to the terminator. An ERROR packet
with no message is terminated at the start of the message field, so the
callback gets an empty string instead of stale data from the previous
packet.
Suggested-by: Jukka Rissanen <jukka.rissanen@nordicsemi.fi>
Suggested-by: Robert Lubos <robert.lubos@nordicsemi.no>
Signed-off-by: Arkadiusz Grzelka <devitwise@gmail.com>
Assisted-by: Claude:claude-opus-5
Zephyr does not load a wpa_supplicant.conf, so the P2P Device Name
that wpa_supplicant would otherwise take from the config file is
never set and P2P discovery advertises an empty name.
Add a WIFI_P2P_SET_DEV_NAME operation to enum wifi_p2p_op and a
device_name member to struct wifi_p2p_params so the name can be set
at runtime, plus a WIFI_P2P_STATUS operation and a status.buf /
status.buf_size pair to read back the device name, MAC address, P2P
state and listen channel. Add the "wifi p2p set_dev_name" and
"wifi p2p status" shell commands on top of these operations.
Assisted-by: Claude:claude-sonnet-5
Signed-off-by: Swaminathan Gurumurthy <swaminathan.gurumurthy@nordicsemi.no>
RISC-V extensions can run in user-mode threads since the syscall
path stopped reading a thread-local symbol inline, and the llext
suite has a writable_mpu scenario covering that case. Remove the
configure-time warning that still claims it is not supported.
Assisted-by: Claude:opus-5
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
Commit 12d57bd872 ("net: invert `ETH_DRIVER` and `NET_L2_ETHERNET`")
dropped the `default y if NET_L2_ETHERNET` of ETH_DRIVER and left it to
each board with an Ethernet controller to default the symbol. The QEMU
boards that reach the host over SLIP were not converted. The TAP
variant of the SLIP device lives in drivers/ethernet/eth_slip_tap.c,
which is only built when ETH_DRIVER is set. Every networking sample
built for qemu_x86, qemu_x86_64, qemu_cortex_m3 or mps2/an385 therefore
boots without a network interface:
net_if: There is no network interface to work with!
net_config: No auto-started network interface
Let NET_SLIP_TAP imply ETH_DRIVER, mirroring NET_QEMU_ETHERNET.
Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
Add response builders for direct service-instance SRV and TXT queries and
dispatch them from the mDNS responder. Include address records with SRV
answers and check service availability before responding.
Add DNS-SD wire-format and responder tests.
Assisted-by: Codex:GPT-6
Signed-off-by: Markus Fuchs <markus.fuchs@sautergroup.com>
qpack_decode_int() accumulated continuation bytes without limit, so a
long enough integer wrapped the 64-bit value. h3_parse_qpack_headers()
then checked each name and value length as pos + len > buflen, which a
wrapped length passes because the sum is computed in 64 bits, and handed
that length to http_hpack_huffman_decode(), which reads past the end of
the header block.
Reject an integer with more continuation bytes than fit in 64 bits, as
hpack_integer_decode() already does for HPACK, and compare each length
against the bytes left in the block. The literal with a static name
reference also read its Huffman flag without checking that a byte was
left; check that as well.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
http_parser_parse_url() takes a (buf, buflen) span but converted the
port with strtoul(), which reads until a non-digit or NUL. When the
caller passes a URL slice that is not NUL-terminated and ends inside
the port, digits located after buflen were consumed and changed the
resulting port, or caused a valid port to be rejected.
Convert only the UF_PORT.len digits recorded by http_parse_host() and
reject values above 65535 while accumulating.
Signed-off-by: Flavio Ceolin <flavio@hubble.com>
The reassembly timeout handler and the RX path modify the same cache
entry without synchronization, so the handler can free a packet the RX
path is still using. Serialize both on a mutex, have the handler skip
entries released or reused while it waited, and initialize the entry
timers once instead of on every allocation.
Assisted-by: Claude:claude-opus-5.5
Signed-off-by: Flavio Ceolin <flavio@hubble.com>
Add CONFIG_SCHED_STATS_SHELL (stats_service.c): a per-CPU busy/idle
summary and per-thread CPU usage shell built on
CONFIG_SCHED_THREAD_USAGE. Commands: sched cpus, sched threads,
sched top. Supports interval sampling (-i ms), delta mode (-d), CPU
filter (-c), and repeat count (-n). Uses k_thread_runtime_stats_*()
APIs.
Named CONFIG_SCHED_STATS_SHELL / "sched" (not "stats") to avoid a
naming conflict with the existing CONFIG_STATS_SHELL mcumgr module.
The per-CPU and per-thread table buffers are static to avoid a
multi-KB stack allocation that can overflow the shell thread's stack;
the command body is serialized with a mutex so concurrent use from two
shell backends cannot corrupt the shared tables and baselines.
Signed-off-by: Appana Durga Kedareswara rao <appana.durga.kedareswara.rao@amd.com>
A CNAME answer makes dispatcher_cb() query again for the alias from
inside the dispatch of the server that sent it, reusing the query slot.
dns_server_is_idle() does not count that slot, so dns_write() renews
the server's source port: the dispatcher is unregistered and registered
again, and the registration runs k_mutex_init() on the lock that the
running dispatch holds. The dispatch then no longer owns its lock, an
unregister from another thread does not wait for it, and with priority
inheritance the thread's list of held mutexes is corrupted. A lookup
started from the result callback takes the same path. Possible since
commit 289c14b910 ("net: dns: Use a fresh source port for each
query").
Mark a server while its reply is being dispatched and do not renew the
source port of a marked server. The next lookup renews it.
Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
dns_randomize_source_port() runs with the resolver lock held and
unregisters the server's dispatcher, which waits for a dispatch in
progress on it. A reply being dispatched on that socket holds the
dispatcher's lock and waits for the resolver lock, so the two threads
deadlock and DNS stops. A late reply arriving while a new lookup renews
the port is enough. Possible since commit 289c14b910 ("net: dns: Use
a fresh source port for each query").
Add dns_dispatcher_try_unregister(), which fails with -EBUSY instead of
waiting when a dispatch is in progress, and keep the current port for
the query in that case. The next lookup renews it. Like the drain in
dns_dispatcher_unregister(), it touches the context's lock only for a
context that was registered.
Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The drain barrier in dns_dispatcher_unregister() locks ctx->lock, but
that mutex is only initialized in dns_dispatcher_register(). The
resolver can reach unregister with a context that never got there:
register_dispatcher() in resolve.c has error returns before the
registration call while the server socket stays open, and a later
dns_server_close() unregisters the dispatcher anyway. The barrier then
locks a zero-filled mutex, which the kernel does not detect.
Skip the drain when the context was neither on the registration list,
nor in the dispatch table, nor registered as the pair of another
context; no dispatch can be in flight on it. A paired context is on
neither the list nor, when it shares the socket, in the table, but a
delegated dispatch runs its callback under its lock, so a flag set at
pairing time keeps the drain for it. The same flag makes a second
dns_dispatcher_register() of a paired context fail with -EALREADY
before it re-initializes a lock that a delegated dispatch may hold;
the list check alone does not see a paired context.
Registration claims a dispatch table slot for every descriptor in
ctx->fds that had no owner, while unregister released only the slot
of ctx->sock. The resolver hands all its server dispatchers one shared
descriptor array, so a context can own another descriptor's slot, and
that slot then outlived the context: the next datagram on the
descriptor ran the unregistered context's callback. Unregister now
releases every slot the context owns. A descriptor whose slot was
released may stay polled through another context's copy of the array;
a datagram on it is now read and discarded, or the socket service
would report it again at once and spin. The resolver's source-port
renewal now drops the old descriptor from its shared array before it
unregisters, so the re-registration does not keep polling a descriptor
that is closed right after, and whose number an unrelated socket may
reuse.
The paired path recorded the pairing before it checked the descriptor
range, so a failed registration could leave the primary delegating to
it. The check now runs first. The primary path likewise claimed its
slots before registering the socket service and kept them when that
failed; it now claims them only once nothing can fail any more.
Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
dns_dispatch() delegated to dispatcher->pair->cb while holding only
the delegating context's lock. Unregister cleared the peer's pair
pointer with a plain store and drained only its own lock, which the
delegated call never held, so a dispatch that had already read the
pointer could still be running the unregistered context's callback
when dns_dispatcher_unregister() returned. The mDNS/LLMNR responder
and resolver pairing on the shared local port hits this path.
Read the pair pointer and take the pair's lock in recv_data(), under
the global lock and right after the dispatching context's own lock,
and run the delegated callback with both held. Unregister clears the
pointer under the same global lock, so a dispatch either read it
before the clear and then already holds the pair's lock, which the
drain barrier in unregister waits for, or reads NULL. Every context's
callback thus runs with that context's lock held, whether reached
directly or through a pairing, and the barrier covers both.
The barrier must not run with the global lock held. A dispatch can
re-enter the dispatcher before it returns: the resolver's result
callback may close the resolver, and a CNAME re-query re-randomizes
its source port through unregister and register. Both need the global
lock while the dispatch still holds the context locks. The lock order
is the global lock, then the dispatching context, then its pair; only
recv_data() waits for a context lock with the global lock held, and
nothing waits for the global lock while holding a context lock except
the dispatch itself, which does not hold the global lock at that
point, so no cycle is added.
Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
recv_data() read the dispatch table slot and then locked the found
context, with no lock held in between. dns_dispatcher_unregister()
could clear the slot and run its drain barrier in that window: the
barrier saw an uncontended lock and returned, while recv_data() went
on to lock the stale context and dispatch on it. A re-registration
then re-initialized a mutex that was still held, which the kernel
does not detect.
Do the slot lookup and the context lock acquisition under the
dispatcher module lock. Once unregister has cleared the slot, no new
dispatch can pick the context up, and the drain barrier waits out any
dispatch that already did.
This adds no lock ordering cycle: the socket service thread calls
handlers without holding its lock, and net_socket_service_register()
only takes that lock and writes an eventfd.
Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
readdir() copies the file name returned by fs_readdir() from struct
fs_dirent (sized MAX_FILE_NAME + 1) into the d_name field of struct
dirent (sized NAME_MAX + 1). The copy length was clamped only to
MAX_FILE_NAME, but the two limits are independent: with FAT long file
names MAX_FILE_NAME follows CONFIG_FS_FATFS_MAX_LFN (up to 255), while
NAME_MAX is the POSIX minimum (14). A directory entry whose name is
longer than NAME_MAX is then written past the end of the static d_name
buffer.
This is the caller-side FatFs long-name overflow of CVE-2026-6688, here
in the POSIX readdir() shim; the in-tree fs_readdir() path was already
bounded by the CVE-2020-13598 fix. Clamp the copy to the size of the
destination d_name[] instead. Names longer than NAME_MAX are truncated,
as POSIX allows for a small NAME_MAX, rather than exceeding the buffer.
Fixes: CVE-2026-6688
Link: https://github.com/advisories/GHSA-8vm2-mjff-2gg2
Assisted-By: Claude:opus-4.8
Signed-off-by: David Brown <david.brown@linaro.org>
pthread_attr_setstack() frees the stack currently held by the attribute
before installing the new one. When the caller passes the address the
attribute already holds, which is what an application does to shrink
the stack in place, the stack is freed while still in use and freed a
second time when the attribute is destroyed or the thread exits,
corrupting the heap.
Only free the previous stack when a different stack is installed.
Signed-off-by: Chris Friedt <chris@fr4.co>
The thread list command reads timeout.dticks unless the min-heap timeout
backend is selected, but the skip-list backend also stores abs_ticks and
has no dticks member, so the build fails. Select abs_ticks for the
skip-list backend too and update the comment to name all the
backends.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
Object tracking kept its own intrusive lists of kernel objects, prepended
from the init tracing hooks with a linear duplicate scan and never
removed from. They had the same lifetime flaw as the object core lists:
an object discarded without being unlinked left the list pointing into
dead memory.
Make CONFIG_TRACING_OBJECT_TRACKING select CONFIG_OBJ_CORE and walk the
objects through the object core API instead. The per-object
_obj_track_next field, the _track_list_k_* heads, SYS_PORT_TRACK_NEXT()
and the tracking side of the init tracing macros are removed with the
tracking.h header.
Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Statically defined sys_mem_blocks allocators and the socket object table
are permanent storage, so they are enumerated in place as the permanent
range of their object type instead of each taking a registry entry. The
section of allocator pointers is registered as an indirect range. Socket
objects that were never initialized do not carry the type tag and are
not reported.
Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Anas Nashif <anas.nashif@intel.com>