Commit graph

5594 commits

Author SHA1 Message Date
Wim Taymans
398326f19c security: add missing NULL checks after calloc in Bluetooth backend
Memory Safety: Medium

Two calloc() calls in backend-native.c do not check the return value
before dereferencing the pointer:

1. rfcomm_send_cmd_enqueue() allocates an rfcomm_cmd struct and
   immediately passes cmd->cmd to vsnprintf without a NULL check.

2. rfcomm_hfp_ag_clcc() allocates an updated_call struct and
   immediately dereferences updated_call->id without a NULL check.

Both would crash on allocation failure. Add NULL checks that return
an error instead of dereferencing NULL.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-29 14:22:53 +02:00
Wim Taymans
d4cf1d0d6f security: bound alloca size for udev property strings
Memory Safety: Low

The udev device enumeration code uses alloca(strlen(str) + 1) to
allocate stack buffers for unescaping ID_VENDOR_ENC and ID_MODEL_ENC
udev properties. These property values originate from the udev database
and could theoretically be manipulated through custom udev rules or
crafted USB device descriptors. An excessively long property value
would cause unbounded stack allocation.

Add a 1024-byte cap on the alloca size and skip the unescape step for
oversized values, falling back to the raw encoded string.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-29 14:22:33 +02:00
Wim Taymans
6bcefd0d59 security: add missing NULL checks after calloc/strdup in filter-graph
Memory Safety: Medium

parse_graph() does not check the return values of calloc() for
input_names/output_names arrays, or strdup() for individual name
entries. If any allocation fails, the code dereferences a NULL pointer
or stores NULL without detection. Add NULL checks that return -ENOMEM
on allocation failure.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-29 14:20:46 +02:00
Wim Taymans
715d1736e9 security: add missing NULL checks after calloc in LADSPA plugin
Memory Safety: Medium

ladspa_plugin_make_desc() calls calloc() twice without checking the
return value. If either allocation fails, the code dereferences a NULL
pointer, causing a crash. Add NULL checks after both calloc calls and
properly free the descriptor struct if the ports allocation fails.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-29 14:19:59 +02:00
Wim Taymans
bc93a745ab security: add missing NULL check after strdup in MIDI server
Memory Safety: Medium

spa_bt_midi_server_new() did not check the return value of strdup()
when duplicating the characteristic path. On allocation failure, a
NULL chr_path would be returned as part of the server object,
leading to a NULL pointer dereference when later used. Add a NULL
check that jumps to the existing fail cleanup path.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-29 11:36:53 +02:00
Wim Taymans
acabcf085d security: add missing NULL checks after strdup/calloc in backend-hsphfpd
Memory Safety: Medium

Multiple allocation results in the HSP/HFP daemon backend were not
checked for NULL:

- transport_data->transport_path strdup in new_audio_connection()
- endpoint->remote_address and local_address strdup in property parsing
- t_path strdup before spa_bt_transport_create()
- endpoint calloc and endpoint->path strdup in interface enumeration
- backend->hsphfpd_service_id strdup after registration

Each could cause a NULL pointer dereference under memory pressure. Add
appropriate NULL checks with error returns matching the existing patterns
in each function (DBUS_HANDLER_RESULT_NEED_MEMORY or -ENOMEM).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-29 11:36:32 +02:00
Wim Taymans
4de0f83aca security: add missing NULL checks after realloc/strdup in LV2 plugin
Memory Safety: Medium

Two issues in the LV2 filter-graph plugin:

1. uri_table_map(): realloc() result was assigned directly to
   table->data, losing the original pointer on failure (memory leak)
   and causing a NULL pointer dereference on the next access. Also
   the subsequent strdup() had no NULL check. Fixed by using a
   temporary pointer for realloc and checking strdup's return.

2. lv2_state_retrieve(): realloc() of sd->tmp was used without a
   NULL check, so a failed allocation would cause sd->tmp to become
   NULL and be immediately passed to spa_json_parse_stringn(). Fixed
   by checking the realloc result before assignment.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-29 11:35:08 +02:00
Wim Taymans
dcf28ff248 security: add missing NULL checks after strdup in modemmanager
Memory Safety: Medium

Four strdup() calls in the ModemManager Bluetooth integration had no
NULL checks, which could lead to NULL pointer dereferences under
memory pressure:

- mm_parse_call_properties(): call->number assignment
- mm_parse_interfaces(): this->modem.path assignment
- mm_filter_cb(): call_object->path assignment (also leaked calloc
  on failure)
- mm_register(): this->allowed_modem_device assignment

Each site now checks for NULL and handles the failure appropriately
for its context (early return, goto cleanup, or return error).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-29 11:34:37 +02:00
Wim Taymans
9a4e0e4c85 security: fix format string vulnerability in hook.h example code
Input Validation: Low

The documentation example code in hook.h passed the msg parameter
directly as the format string to printf() and fprintf(). If copied
by developers, this pattern creates a format string vulnerability
where specially crafted msg content with format specifiers (%x, %n,
etc.) could read/write memory. Use "%s" as the format string and
pass msg as a data argument instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-29 11:33:44 +02:00
Wim Taymans
7982f52830 security: replace sprintf with snprintf in spa_debugc_mem
Memory Safety: Medium

The spa_debugc_mem() function used unbounded sprintf() calls to format
hex dump output into a fixed 512-byte stack buffer. While the current
line-by-line output (16 bytes per line) fits within the buffer, sprintf
provides no overflow protection if the format changes or assumptions
are violated. Replace with snprintf() using sizeof(buffer) and remaining
space tracking to guarantee the buffer cannot be overflowed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-29 11:33:25 +02:00
Wim Taymans
eaaf125d13 filter-graph: protect against large values
Limit the delay in the convolver to 10 seconds.

Limit the convolver block sizes to 64K.

Avoid overflows when using large rates, file size or number of
channels in the provided impulse response.
2026-04-29 11:02:11 +02:00
Wim Taymans
08efbf2254 security: add missing NULL check after calloc in plugin_builtin
Memory Safety: Medium

In the fallback code path when spa-plugins support is not compiled in,
calloc() for the output sample buffer was not checked for NULL. If the
allocation fails (e.g., due to a large n_samples value from filter
configuration), spa_memcpy would dereference a NULL pointer.

Fixed by adding a NULL check and returning NULL on allocation failure.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-28 13:05:38 +02:00
Wim Taymans
1de8615caf security: fix missing NULL check and integer overflow in AVB ringbuffer
Memory Safety: Medium

The AVB PCM ringbuffer allocation used calloc(1, size * 4) which has
two issues: the multiplication can overflow for large ringbuffer_size
values (derived from quantum_limit config parameter), and the return
value was never checked for NULL.

Fixed by using calloc(size, 4) which lets calloc check for overflow
internally, and added a NULL check for the allocation result.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-28 13:05:09 +02:00
Wim Taymans
e3c20982a8 security: add missing NULL checks after calloc in filter-graph
Memory Safety: Medium

Multiple calloc() calls for node port arrays and the graph handle
array were not checked for NULL returns. If memory allocation fails,
the code immediately dereferences the NULL pointers in subsequent
loops, causing a crash. An attacker who can influence the filter
graph configuration (e.g., through config files specifying many
ports) could potentially trigger this condition.

Fixed by adding NULL checks after all unchecked calloc calls and
properly cleaning up on failure.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-28 13:02:50 +02:00
Wim Taymans
695f25600b security: add missing O_CLOEXEC flag to V4L2 device open
File and Resource Handling: Medium

The V4L2 device file descriptor was opened without the O_CLOEXEC flag.
If a child process is subsequently spawned (e.g., via fork+exec), the
video device fd would be inherited, potentially allowing the child
process unauthorized access to the camera device.

Fixed by adding O_CLOEXEC to the open() flags.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-28 12:56:40 +02:00
Wim Taymans
7bfa93de05 security: add missing O_CLOEXEC/SOCK_CLOEXEC flags
File and Resource Handling: Medium

Several file and socket operations were missing the close-on-exec flag,
which causes file descriptors to leak to child processes created via
fork+exec. This could allow child processes unintended access to
privileged resources.

- node-driver.c: SOCK_DGRAM socket for SIOCETHTOOL ioctl leaked to
  child processes
- pw-container.c: Unix domain listen socket leaked to spawned
  container processes
- compress-offload-api.c: ALSA compress-offload device fd leaked to
  child processes

Added O_CLOEXEC to open() calls and SOCK_CLOEXEC to socket() calls.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-28 12:20:33 +02:00
Wim Taymans
aaa7076b52 acp: partially revert f76327e076
The Line Out mute seems to break things.

See #5246
2026-04-28 12:01:06 +02:00
Wim Taymans
06421554d3 security: cap alloca size in JSON-to-POD string conversion
Memory Safety: Medium

spa_json_to_pod_part() uses alloca(len+1) to allocate a stack buffer
for JSON string values, where len comes from the JSON parser. Since
this function is recursive (for nested JSON objects/arrays), a
crafted JSON document with large string values can cause stack
exhaustion through unbounded alloca calls.

Add a size check capping the alloca to 8192 bytes, which is generous
for all legitimate PipeWire configuration values (type names, IDs,
property strings) while preventing stack overflow from malicious or
malformed JSON input.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-28 11:52:41 +02:00
Wim Taymans
026ae3af7a security: add bounds check for exec argv array in filter-graph
Memory Safety: Medium

The do_exec() function in the filter-graph builtin plugin parses a
JSON array of arguments into a fixed-size argv[512] stack buffer
without checking whether argc exceeds the array bounds. A crafted
filter-graph configuration with more than 511 arguments would cause
a stack buffer overflow.

Add a bounds check before each insertion to ensure argc stays within
the array limits, reserving space for the NULL terminator.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-28 10:41:34 +02:00
Wim Taymans
9f3d894c10 audiomixer: rate limit the "out of buffers" debug
See #5249
2026-04-28 10:34:39 +02:00
Wim Taymans
f00c84ccad security: replace strcpy with memcpy in alsa_id_decode
Memory Safety: Low

alsa_id_decode() uses strcpy() to copy into a caller-provided buffer
without knowing its size. Although all current callers allocate the
buffer correctly (via alloca(strlen(src) + 1) or with a pre-validated
fixed buffer), the function signature does not encode this requirement.
Replace strcpy with memcpy using the known source length to make the
bounded copy explicit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-27 16:15:10 +02:00
Wim Taymans
edb3c27aa4 channelmix: add SEE 7p1 to stereo downmix 2026-04-27 15:59:38 +02:00
Wim Taymans
daa66c0646 overflow: fix some more potential overflows 2026-04-27 12:29:31 +02:00
Wim Taymans
c525cfcced security: reject negative DBus array lengths in Bluetooth transport
Memory Safety: High

dbus_message_iter_get_fixed_array() returns the array length as a
signed int. A malformed DBus message could produce a negative length
value. In the Configuration property handler, the check 'if (!len)'
does not catch negative values, allowing negative lengths to be passed
to malloc() and memcpy() where sign extension to size_t creates
enormous values. The debug logging call spa_debug_log_mem() also
receives the negative length cast to size_t, causing an out-of-bounds
read.

In the Capabilities/Metadata handler, 'if (n)' is similarly true for
negative values, and the negative int assigned to the size_t *size
output parameter corrupts the stored length.

Fix by using 'len <= 0' and 'n > 0' checks respectively, and move
debug logging after validation. Explicitly zero the length on the
negative/zero path to prevent storing corrupted sizes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-27 11:04:52 +02:00
Wim Taymans
f3538dd7fe security: validate metadata length before subtraction in BIS config
Memory Safety: Critical

When a Bluetooth BIS metadata entry has length=0 (e.g. when the JSON
config contains a "type" key but no "value" key, leaving the
calloc-initialized length at zero), the expression
'metadata_entry->length - 1' underflows to SIZE_MAX because the int
value is implicitly converted to size_t in the memcpy call. This causes
memcpy to read far past the metadata_entry->value buffer, leading to a
heap buffer overflow and likely crash.

Add a check that metadata_entry->length >= 1 before the subtraction,
rejecting entries with invalid length.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-27 11:03:54 +02:00
Wim Taymans
4f9e59b87d security: fix missing null termination in Bluetooth broadcast code
Memory Safety: Medium

The broadcast_code field is a 16-byte array that can be filled with
exactly 16 bytes of data via memcpy without null termination when the
input string length equals BROADCAST_CODE_LEN. The field is then
logged with %s format, which reads past the buffer boundary into
adjacent struct fields, potentially disclosing sensitive data.

Fix by changing the boundary check from > to >= to ensure room for
the null terminator, and copy the terminator along with the data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-27 11:02:35 +02:00
Wim Taymans
ed2c0ad4ee spa: add spa_alloca that does overflow and limit checks
Make a function like alloca but with overflow checks and a max
allocation size.

Use this function where we can and also make sure that all alloca calls
are in some way limited.
2026-04-27 10:53:44 +02:00
Wim Taymans
0f8d5c6e57 spa: add and use spa_overflow macros 2026-04-24 15:55:35 +02:00
Wim Taymans
e3e1c4d214 security: fix integer overflow in Bluetooth codec codesize calculations
Memory Safety: High

Several Bluetooth audio codec implementations calculate codesize by
multiplying samples * channels * sizeof(sample_type) without overflow
checks. The parameters come from Bluetooth codec negotiation, which is
influenced by the remote peer. If the multiplication overflows, codesize
wraps to a small value, causing subsequent buffer size checks to pass
while the actual data processing operates on the full (larger) sample
count, leading to heap buffer overflows.

Affected codecs: LC3 (BAP), LC3plus (A2DP), Opus (A2DP), Opus-G (A2DP).

Add overflow checks before each codesize multiplication to ensure the
result fits in the target integer type, returning -EINVAL on overflow.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-24 15:55:35 +02:00
Wim Taymans
62e1da2ea3 security: fix unchecked allocation returns in filter-graph descriptor loading
Memory Safety: High

In descriptor_load(), the initial calloc for the descriptor struct, the
strdup for the label, and four calloc calls for port arrays (input,
output, control, notify) all lacked NULL checks. If any allocation fails
under memory pressure, the code proceeds to dereference NULL pointers
when populating the port arrays, causing a crash.

Add NULL checks after all allocation calls, using the existing
descriptor_unref cleanup path which already handles freeing partially
initialized descriptors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-24 15:55:35 +02:00
Wim Taymans
e75f72476b security: fix missing malloc NULL checks in pffft
Memory Safety: Medium

In new_setup_simd(), the return value of malloc() for the PFFFT_Setup
struct was not checked before dereferencing. Similarly,
pffft_aligned_malloc() for the data buffer was not checked. If either
allocation fails, the code dereferences NULL causing a crash.

Add NULL checks for both allocations, freeing previously allocated
memory on failure.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-23 16:59:17 +02:00
Wim Taymans
bb9d306399 audioconvert: also benchmark the inter versions 2026-04-23 09:38:01 +02:00
Wim Taymans
596047aaef resample: use some extra accumulators to improve pipelining 2026-04-23 09:32:31 +02:00
Wim Taymans
75e432a49a resample: use independent accumulators for SSE and SSSE3 2026-04-23 09:18:08 +02:00
Wim Taymans
37f9f7773c resample: implement inter for ssse3 2026-04-22 18:28:25 +02:00
Wim Taymans
dfeca5806f resample: don't use hadd, it is slow 2026-04-22 18:23:33 +02:00
Wim Taymans
a0518e28bb audioconvert: avoid some float/double/int conversions 2026-04-22 18:00:59 +02:00
Wim Taymans
9c9a5ac435 convolver: returned processed samples 2026-04-22 16:13:56 +02:00
Wim Taymans
495c1c9dd0 dsp: precalculate the scale 2026-04-22 16:13:56 +02:00
Wim Taymans
3c2552e671 dsp: add SSE and AVX2 mult and linear functions 2026-04-22 16:13:56 +02:00
Wim Taymans
3e7e61dcb7 convolver: small cleanups
Remove unused field.
We can also remove the ifft and reuse the fft.
2026-04-22 16:13:56 +02:00
Wim Taymans
aabcbf1261 dsp: move scaling out of complex multiply
do scaling as part of iFFT.
2026-04-22 16:13:56 +02:00
Wim Taymans
7fc020098c dsp: shuffle per implementation 2026-04-22 16:13:56 +02:00
Wim Taymans
46b8380490 dsp: store Real/Imag in blocks of 8
Shuffle FFT output into real/imag blocks so that they are easier to
handle in the complex multiply. Do the unshuffle again before doing the
inverse FFT.
2026-04-22 16:12:20 +02:00
Wang Yu
2953f48d9b vulkan: fix wrong descriptor image info index
When streams are skipped via continue in updateDescriptors(),
the loop index i and descriptorSetLen diverge. The image info
is written at descriptorSetLen but pImageInfo was referencing
index i, pointing to uninitialized memory and causing incorrect
Vulkan descriptor updates.

Fix by using descriptorSetLen consistently.

Signed-off-by: Wang Yu <wangyu@uniontech.com>
2026-04-21 15:13:03 +00:00
Wim Taymans
c6ae30593c filter-graph: use convolver2 for sofa
We don't need 2 convolvers anymore, we can use the same convolver with
2 outputs with the left and right ir.

Add latency option to the sofa plugin. I believe the latency of the
SOFA filters is by default 0, so use that.
2026-04-21 16:52:49 +02:00
Wim Taymans
9cae4ce7e7 filter-chain: add convolver2
Add support for multiple convolver outputs. This makes things more
efficient because we only need to do the input FFT once to produce the N
outputs.

Add convolver2 that can have multiple outputs.
2026-04-21 16:24:38 +02:00
Wim Taymans
2b96f694f7 convolver: rename some fields 2026-04-20 14:00:15 +02:00
Wim Taymans
d8db536d36 convolver: remove some useless loops 2026-04-20 14:00:04 +02:00
Wim Taymans
777851a7ec convolver: support more than 2 partitions
Currently wired up to only support 2 but it can be changed.
2026-04-20 13:59:08 +02:00