Commit graph

167 commits

Author SHA1 Message Date
hackerman-kl
c7f4108eff module-avb: milan: acmp: fix activate to work according to the Milan specication, just SRP 2026-04-27 10:56:44 +00:00
hackerman-kl
6c5c184e6d module-avb: milan: acmp: return IMCOMPATIBLE if the interface is invalid 2026-04-27 10:56:44 +00:00
hackerman-kl
fdcd818fba module-avb: milan: return if server endity-id is different than the talker_guid 2026-04-27 10:56:44 +00:00
hackerman-kl
b8b58c81f2 module-avb: milan: implement the acmp's talker 2026-04-27 10:56:44 +00:00
hackerman-kl
baec6f9e33 module-avb: milan: use the msrp and store the vlan_id 2026-04-27 10:56:44 +00:00
hackerman-kl
393a1809ca module-avb: milan: use the msrp etc... instead of duplicating things 2026-04-27 10:56:44 +00:00
hackerman-kl
45a94f58bd milan-avb: stream: initialisation of the msrp/mrp stream components 2026-04-27 10:56:44 +00:00
hackerman-kl
5b06b5457a milan-avb: msrp/acmp: talker failed can be handled now 2026-04-27 10:56:44 +00:00
hackerman-kl
f5e97f0f6b milan-avb: adjust the msrp/adp and acmp state machine to communicate talker discovery and srp reserveration 2026-04-27 10:56:44 +00:00
hackerman-kl
219adaa456 milan-avb: adjusting the msrp-domain to work accordingly to the milan specification 2026-04-27 10:56:44 +00:00
hackerman-kl
2746898e9a milan-avb: rework mrp join/begin:
* join/begin mrp protocol for attributes of mvrp and msrp within stream_activate.
 * Creation of the attribute done on stream creation during es_buidler
2026-04-27 10:56:44 +00:00
hackerman-kl
0309d598a1 milan-avb: use vlan and mac address from the stream itself 2026-04-27 10:56:44 +00:00
hackerman-kl
e9a51bd84f milan-avb: rename msrp attribute to stream_attr 2026-04-27 10:56:44 +00:00
hackerman-kl
42925490bd milan-avb: a SRP domain may be defined per interface, make it possiblie ot have multiple avb domain per interface 2026-04-27 10:56:44 +00:00
hackerman-kl
4856f85de2 first draft for ACMP/ timeout handling, and communication between SRP/ADP and the ACMP state machine 2026-04-27 10:56:44 +00:00
hackerman-kl
ad543e37f5 milan-avb: split the acmp module into milan and legacy-avb 2026-04-27 10:56:44 +00:00
hackerman-kl
9ee0ddf24f milan-avb: preparing acmp state machine dividing between milan and legacy avb 2026-04-27 10:56:44 +00:00
hackerman-kl
d46523e6ad module-avb: milan: introducing GET_DYNAMIC_INFO 2026-04-27 10:56:44 +00:00
Wim Taymans
931505a0e4 security: validate packet length in AVB IEC 61883 stream handler
Input Validation: High

The on_socket_data() handler only checked that the received packet was
at least avb_packet_header size before casting to avb_packet_iec61883,
which is larger. A packet between these two sizes would cause
out-of-bounds reads when accessing iec61883 fields like data_len.

Additionally, handle_iec61883_packet() used the data_len field from the
packet to determine how many bytes to copy into the ring buffer without
checking that the claimed data_len didn't exceed the actual received
data. A crafted packet with an inflated data_len could cause an
out-of-bounds read from the receive buffer.

Fix by requiring the minimum packet size to cover both the ethernet
header and the iec61883 header, and by validating that the claimed
payload size doesn't exceed the received data length.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-27 12:37:54 +02:00
Wim Taymans
918d0f2f8a security: validate packet bounds in AVB MRP protocol parser
Input Validation: High

The avb_mrp_parse_packet() function, used by both MSRP and MVRP
protocol handlers, had several missing bounds checks:

1. No minimum length validation: the parser began accessing packet
   data at sizeof(avb_packet_mrp) without checking len was large
   enough, causing out-of-bounds reads on truncated packets.

2. Unsafe loop terminator checks: the while loops checked m[0] and
   m[1] without ensuring at least 2 bytes remained in the buffer.

3. Missing hdr_size bounds check: the header size returned by the
   check_header callback was used to advance the pointer without
   verifying it stayed within the packet bounds.

Fix by adding a minimum packet length check, using structure-size-aware
bounds checks in loop conditions, and validating hdr_size against
remaining packet data before advancing the pointer.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-27 12:37:51 +02:00
Wim Taymans
f16042d52a security: validate packet length in AVB MAAP message handler
Input Validation: High

The maap_message() handler cast the incoming network data directly to
avb_packet_maap without checking that the received data was at least
sizeof(avb_packet_maap) bytes. The caller only validates the packet is
at least avb_packet_header size, which is smaller. A truncated MAAP
packet could cause out-of-bounds reads when accessing request_start,
request_count, conflict_start, and conflict_count fields in the probe
and defend handlers.

Fix by adding a minimum packet length check at the beginning of
maap_message().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-27 12:37:49 +02:00
Wim Taymans
c9d4854114 security: validate packet length in AVB ADP message handler
Input Validation: High

The adp_message() handler accessed avb_ethernet_header and
avb_packet_adp fields from network packet data without checking that
the packet was large enough to contain these structures. A truncated
ADP packet could cause out-of-bounds reads when accessing entity_id,
message_type, and other header fields.

Fix by adding a minimum packet length check before any field access.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-27 12:37:46 +02:00
Wim Taymans
11226544f7 security: validate packet length in AVB ACMP message handler
Input Validation: High

The acmp_message() handler accessed fields of avb_ethernet_header and
avb_packet_acmp from network packet data without first checking that
the received packet was large enough to contain these structures.
A short packet could cause out-of-bounds reads when accessing packet
header fields.

The VLA-based reply buffers in reply_not_supported(),
handle_connect_tx_command(), and handle_disconnect_tx_command() also
lacked an upper bound on the packet length, allowing a packet claiming
a very large size to cause excessive stack allocation.

Fix by adding minimum length (sizeof(header) + sizeof(acmp)) and
maximum length (MTU) validation at the entry point before any field
access or buffer allocation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-27 12:37:43 +02:00
Wim Taymans
710414730d security: validate packet length in AVB AECP AEM command handlers
Memory Safety: High

Multiple AVB AECP AEM command handler functions copied network packet
data into stack buffers via memcpy(buf, m, len) without validating
that len fits within the destination buffer. A crafted AVB packet with
an oversized length could overflow the stack buffer.

Added bounds validation before each memcpy in:
- cmd-available.c: handle_cmd_entity_available_milan_v12
- cmd-get-set-configuration.c: set and get configuration handlers
- cmd-get-set-sampling-rate.c: unsolicited, invalid response, and get handlers
- cmd-get-set-stream-format.c: get and set stream format handlers
- cmd-lock-entity.c: handle_cmd_lock_entity_milan_v12

This matches the bounds checking pattern already used in
cmd-get-set-control.c, cmd-get-set-clock-source.c, and
cmd-get-set-name.c.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-27 11:35:41 +02:00
Wim Taymans
88a3bf8aab security: validate packet length in AVB get_avb_info handler
Memory Safety: High

The handle_get_avb_info_common() function copied network packet data
into a stack buffer using memcpy(buf, m, len) without validating that
len fits within the 2048-byte buffer. A crafted AVB packet with a
large length could overflow the stack buffer. Added bounds validation
matching the pattern already used in handle_read_descriptor_common().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-27 11:24:11 +02:00
Wim Taymans
46eefd16ee security: fix out-of-bounds read in AVB AECP AEM command handler
Memory Safety: High

The cmd_names[] array was indexed with a network-provided command type
value before the bounds check, allowing an out-of-bounds read when
processing crafted AVB network packets. Moved the bounds validation
before the array access to prevent reading past the end of the array.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-27 11:23:44 +02:00
Wim Taymans
e01ca8919e security: fix integer underflow in AVB stream packet handling
Memory Safety: Critical

In handle_iec61883_packet(), the data_len field from an incoming network
packet is converted via ntohs() and then unconditionally has 8 subtracted
from it. If an attacker sends a malformed AVB packet with data_len < 8,
the subtraction wraps the uint32_t n_bytes to a very large value
(~4 billion). This corrupted size is then passed to
spa_ringbuffer_write_data(), which can overwrite the ring buffer and
adjacent heap memory with attacker-controlled network data.

Add a bounds check to verify data_len >= 8 before the subtraction,
returning early on malformed packets.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-24 15:55:35 +02:00
hackerman-kl
0ac8b1c5fa module-avb: fix GET_NAME to validate length before field reads and reply with fixed size 2026-04-24 11:50:23 +02:00
hackerman-kl
01dd7e607c module-avb: bound packet copy length in reply_status helper 2026-04-24 11:50:20 +02:00
hackerman-kl
f091b85b03 module-avb: enforce minimum AECP packet length and replace VLA on dispatch 2026-04-23 17:25:26 +02:00
hackerman-kl
6ca2f509e3 module-avb: bound descriptor size in READ_DESCRIPTOR reply to prevent stack overflow 2026-04-22 19:19:10 +02:00
hackerman-kl
a8832c74d0 module-avb: bound packet copy length in get-set-name handlers 2026-04-20 18:29:56 +02:00
hackerman-kl
e6b4de6442 milan-avb: guard against size_t underflow on short packets in unsol reply prepare 2026-04-19 18:58:01 +02:00
hackerman-kl
09f9100ce7 milan-avb: validate packet length before dereferencing SET_CONTROL value byte 2026-04-19 07:39:03 +02:00
hackerman-kl
0291895498 milan-avb: zero-pad oversized SET_CONTROL reply buffer to avoid stack info leak 2026-04-18 17:13:05 +02:00
hackerman-kl
b831fd857f milan-avb: bound packet copy length in get-set-control handlers 2026-04-16 19:50:33 +02:00
hackerman-kl
f06234fda8 milan-avb: bound packet copy length in clock-source handlers 2026-04-16 19:07:59 +02:00
hackerman-kl
d1deabe5ac milan-avb: fix descriptor field and endianness in GET_CLOCK_SOURCE lookup 2026-04-14 19:00:02 +02:00
hackerman-kl
8fbeb23bbf milan-avb: implement deregister unsolicited notifications to actually clear registration 2026-04-13 18:52:30 +02:00
hackerman-kl
f0a33cddbd module-avb: es_builder: use the descriptor rather than a pointer to avoid overwriting it 2026-04-20 10:10:58 +02:00
hackerman-kl
e66a24dc5b modules-avb: legacy-avb: entity warnings 2026-04-19 08:15:55 +02:00
hackerman-kl
c551acf4d1 milan-avb: lock: make it lockable:
1. The period calls were added to handle timeouts.
2. Handle the case where lock must be unlocked after 60s if the
   controller owning the locked does not release it.
2026-04-16 12:42:23 +02:00
zuozhiwei
11d28c661b Fix spelling errors in comments and log messages
- Fix durring → during in es-builder.c error message
- Fix capabilty → capability in impl-port.c debug log
- Fix supress → suppress in rate-control.h comment

Improve code readability
2026-04-13 07:20:11 +00:00
Christian F.K. Schaller
14310e66fe module-avb: extend transport abstraction to stream data path
Add stream_setup_socket and stream_send ops to avb_transport_ops so the
stream data plane can use the same pluggable transport backend as the
control plane. Move the raw AF_PACKET socket setup from stream.c into
avdecc.c as raw_stream_setup_socket(), and add a raw_stream_send()
wrapper around sendmsg().

Add a stream list (spa_list) to struct server so streams can be iterated
after creation, and add stream_activate_virtual() for lightweight
activation without MRP/MAAP network operations.

Implement loopback stream ops: eventfd-based dummy sockets and no-op
send that discards audio data. This enables virtual AVB nodes that work
without network hardware or privileges.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 07:43:19 +00:00
Christian F.K. Schaller
ef4ff8cfd0 test: add AVB protocol test suite with loopback transport
Add a test suite for the AVB (Audio Video Bridging) protocol stack that
runs entirely in software, requiring no hardware, root privileges, or
running PipeWire daemon.

The loopback transport (avb-transport-loopback.h) replaces raw AF_PACKET
sockets with in-memory packet capture, using a synthetic MAC address and
eventfd for protocol handlers that need a valid fd.

Test utilities (test-avb-utils.h) provide helpers for creating test
servers, injecting packets, advancing time, and building ADP packets.

Tests cover:
- ADP entity available/departing/discover/timeout
- MRP attribute lifecycle (create, begin, join)
- Milan v1.2 mode server creation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 07:43:19 +00:00
Christian F.K. Schaller
a73988d38d module-avb: add transport abstraction for pluggable network backends
Introduce struct avb_transport_ops vtable with setup/send_packet/
make_socket/destroy callbacks. The existing raw AF_PACKET socket code
becomes the default "raw" transport. avdecc_server_new() defaults to
avb_transport_raw if no transport is set, and avdecc_server_free()
delegates cleanup through the transport ops.

This enables alternative transports (e.g. loopback for testing) without
modifying protocol handler code.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 07:43:19 +00:00
Christian F.K. Schaller
d9821d09c7 module-avb: fix Milan lock entity error response and re-lock timeout
Fix two bugs in handle_cmd_lock_entity_milan_v12():

1. When server_find_descriptor() returns NULL, reply_status() was called
   with the AEM packet pointer instead of the full ethernet frame,
   corrupting the response ethernet header.

2. When refreshing an existing lock, the expire timeout was extended by
   raw seconds (60) instead of nanoseconds (60 * SPA_NSEC_PER_SEC),
   causing the lock to expire almost immediately after re-lock.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 07:43:19 +00:00
Christian F.K. Schaller
4e62826e01 module-avb: fix legacy AECP handlers reading payload at wrong offset
handle_acquire_entity_avb_legacy() and handle_lock_entity_avb_legacy()
incorrectly treated the full ethernet frame pointer as the AEM packet
pointer, causing p->payload to read descriptor_type and descriptor_id
from the wrong offset. Fix by properly skipping the ethernet header,
matching the pattern used by all other AEM command handlers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 07:43:19 +00:00
Christian F.K. Schaller
3f386ecd34 module-avb: fix ACMP error responses sent with wrong message type
In handle_connect_tx_command() and handle_disconnect_tx_command(),
AVB_PACKET_ACMP_SET_MESSAGE_TYPE() is called after the goto done
target. When find_stream() fails and jumps to done, the response
is sent with the original command message type (e.g., CONNECT_TX_COMMAND)
instead of the correct response type (CONNECT_TX_RESPONSE).

Move the SET_MESSAGE_TYPE call before find_stream() so error responses
are always sent with the correct response message type.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 07:43:19 +00:00
Christian F.K. Schaller
1d0c51f057 module-avb: fix MRP NEW messages never being transmitted
AVB_MRP_SEND_NEW was defined as 0, making it indistinguishable from
"no pending send" in the MSRP and MVRP event handlers which check
`if (!pending_send)`. This meant that when an attribute was first
declared (applicant state VN or AN), the NEW message was silently
dropped instead of being transmitted on the network.

Fix by shifting all AVB_MRP_SEND_* values to start at 1, so that 0
unambiguously means "no send pending". Update the MSRP and MVRP
encoders to subtract 1 when encoding to the IEEE 802.1Q wire format
(which uses 0-based event values).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 07:43:19 +00:00