Commit graph

4678 commits

Author SHA1 Message Date
佳和 刘
b24917b719 Merge branch 'add-lineout' into 'master'
spa: add "Line Out" element to headphones and lineout profiles

See merge request pipewire/pipewire!2713
2026-05-01 18:48:29 +00:00
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
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
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
Jiahe Liu
b6caac401c spa: add "Line Out" element to headphones and lineout profiles
Some audio hardware reports output jacks as "Line Out" rather than
"Headphone" or generic analog outputs. Without an explicit "Line Out"
element in the SPA configuration, these ports may be ignored or
misidentified, leading to missing output options in desktop settings.

This change adds "Line Out" as a recognized element in both the
headphones and lineout SPA configuration files, improving compatibility
with a wider range of audio devices.
2026-04-16 12:38:43 +00:00
Masum Reza
f76327e076 alsa: acp: don’t override user-selected port on availability changes
ACP was re-selecting the “best” port on every port availability event,
even when a port was already explicitly selected by the user. This
differs from PulseAudio’s behavior, where port switching decisions are
left to higher-level policy.

This caused issues on devices where Line Out (speakers) and Headphones
share the same analog interface: when headphones are plugged in, ACP
would immediately switch away from the user-selected Line Out, or end up
in a state where no sound is produced despite selecting speakers explicitly from
clients like pwvucontrol.

Fix this by only re-evaluating and switching ports when:
  - no active port is currently selected, or
  - the active port has become unavailable

This preserves manual user choices and prevents ACP from fighting client
port selections during route activation.

Additionally, adjust ALSA mixer paths to better separate Line Out and
Headphones behavior:
  - Disable Line Out controls in the headphones path
  - Add explicit Line Out and Auto-Mute Mode handling in the lineout path

Together, these changes align PipeWire’s behavior more closely with
PulseAudio and fix cases where selecting speakers while headphones are
plugged results in no audio output.

Signed-off-by: John Titor <masumrezarock100@gmail.com>
2026-04-16 10:45:01 +00:00
Wim Taymans
adad89dc0e add spa_memcpy to more places
Use spa_memcpy yo where we memcpy data so that when the debug option is
enabled we can see more.
2026-04-16 12:16:06 +02:00
Wim Taymans
35cbd2e56a audioconvert: don't setup again in suspend
Remove the fallthrough in suspend, we don't want to do the setup that we
do in the paused mode, just reset the node and unset the started state.
2026-04-16 10:12:09 +02:00
Wim Taymans
03fd89abea alsa-seq: add : between client and port name
The separator is important for applications to find the client name and
group ports.

Fixes #5229
2026-04-15 11:20:18 +02:00
zuozhiwei
3277f3acfb alsa: fix inverted port validity check in port_reuse_buffer
The CHECK_PORT condition in impl_node_port_reuse_buffer was inverted with a negation operator, causing the function to reject valid output ports and accept invalid ones.

Fixes the logic so that valid ports proceed to buffer recycling and invalid ports are properly rejected.
2026-04-15 09:17:49 +00:00
Wim Taymans
ae723a69f6 filter-graph: allow negative Gain in mixer
To allow for polarity changes.

Fixes #5228
2026-04-15 09:41:55 +02:00
Wim Taymans
823dcd8843 scheduler: make nodes move to IDLE when inactive
When a node is inactive but linked to a driver, the only reason it is
not being scheduled is because it is inactive.

We already set up the links and negotiate the format and buffers to
prepare going to RUNNING. This patch now also make the node go to IDLE,
which makes the adapter negotiate a forma and buffers with the internal
node.

This makes things more symetrical, when linking a node, it becomes IDLE,
when activating it becomes RUNNABLE, when inactive it goes back to IDLE.
The switch to RUNNING will also be faster when things are already set up
in the IDLE state.

The main advantage is that it allows us to implement the startup of
corked streams in pulseaudio better. Before this patch we had to set the
stream to active to make it go through the Format and buffer negotiation
and then quickly set it back to inactive, hopefully without skipping a
cycle. After this patch, the corked stream goes all the way to IDLE,
where it then waits to become active.

See #4991
2026-04-14 14:28:29 +02:00
Wim Taymans
474253719f alsa-seq: remove port from mix_list on destroy
When the port is destroyed we need to remove it from the mix_list or
else the process function will keep trying to use the invalid memory.

This is because the port logic does not want to call any functions on
the port (like clearing the IO or Format) after it emitted the destroy
signal and we need to clean up ourselves.

Fixes #5221
2026-04-14 11:09:29 +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