Jin Li [Tue, 15 Sep 2026 11:42:05 +0000 (11:42 +0000)]
async: fix snd_async_del_handler for TIMER type
snd_async_del_handler() has two switch statements that handle
PCM and CTL handler types, but not TIMER. When a TIMER type
handler is deleted, both switches fall through to default and
trigger assert(0), crashing any program that uses
snd_async_add_timer_handler().
Add the missing SND_ASYNC_HANDLER_TIMER cases to both switches,
and include timer_local.h to access struct _snd_timer.
Closes: https://github.com/alsa-project/alsa-lib/pull/525 Signed-off-by: Jin Li <jinli@lanxincomputing.com> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Reuben Grinberg [Sun, 1 Nov 2026 18:49:36 +0000 (12:49 -0600)]
ucm: avoid relinking cached controls when adding an alias
uc_mgr_open_ctl() calls uc_mgr_ctl_add() with an existing entry when
another device name resolves to the same control card. Adding that
entry to ctl_list again corrupts the list and can double-free the
control handle during failed UCM import cleanup.
Only link entries allocated by this invocation. Existing entries keep
their original list membership while their device aliases are added.
Closes: https://github.com/alsa-project/alsa-lib/pull/539 Signed-off-by: Reuben Grinberg <reuben.grinberg@aya.yale.edu> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Yegor Yefremov [Fri, 23 Oct 2026 23:18:15 +0000 (01:18 +0200)]
pcm: dmix: i386: keep the size operand in memory
The i386 mix_areas_*() assembly clobbers esi, edi, edx, ecx, eax and
(since gcc 5, even in PIC mode) ebx. When gcc also needs ebp as frame
pointer, which it does at -Os, no general purpose register is left.
Commit abc9f32cf45c ("pcm: dmix: assembly: give more freedom over the
constraints") relaxed the size operand from "+m" to "+&rm". With
AVX512BW enabled (e.g. -march=skylake-avx512, cannonlake, icelake or
x86-64-v4) and -Os or -Oz, gcc 15 and gcc 16 then fail to pick the
memory alternative and abort:
pcm_dmix_i386.h:52:9: error: 'asm' operand has impossible constraints or there are not enough registers
As the asm already uses all registers, restore the "+m" constraint for
size, as used before that commit. The loop decrementing it in memory
also does read-modify-write operations on dst and sum, so the extra
memory access has a negligible cost.
Closes: https://github.com/alsa-project/alsa-lib/pull/537 Fixes: abc9f32cf45c ("pcm: dmix: assembly: give more freedom over the constraints") Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Jaroslav Kysela [Mon, 30 Nov 2026 13:53:15 +0000 (14:53 +0100)]
ucm: fix TOCTOU race in sysfs value substitution
Separately checking a file's state (lstat64) before opening it lets the
final path component be replaced in between, so the subsequent open() may
operate on a different object than was checked.
Probe and operate on the same object instead: read the link first and, if
the path is not a symlink, open it with O_NOFOLLOW and run the type and
permission checks on the opened descriptor via fstat64(). O_NOFOLLOW only
constrains the final component, so the symbolic links that sysfs uses for
the intermediate components are still resolved as before. Also tighten the
accepted value source to regular files only.
Based on a patch by Mingjie Shen.
Closes: https://github.com/alsa-project/alsa-lib/pull/367 Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Jaroslav Kysela [Mon, 30 Nov 2026 13:40:24 +0000 (14:40 +0100)]
topology: ctl: fix potential endless loop in tplg_decode_control_enum
The enum decode loop computed size2 = ec->size + ec->priv.size and only
rejected it for being too large (size2 > size). When both ec->size and
ec->priv.size are zero, size2 is zero, which passes that check, and the
loop advances bin/size/pos by zero and loops forever.
Unlike tplg_decode_control_mixer1() and tplg_decode_control_bytes1(),
tplg_decode_control_enum1() never received the computed size and had no
lower-bound size validation. Make it consistent with the mixer/bytes
helpers: pass (bin, size) and reject size < sizeof(*ec). Since the
structure size is non-zero, any accepted element guarantees forward
progress, which eliminates the endless loop.
Closes: https://github.com/alsa-project/alsa-lib/issues/535 Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Jaroslav Kysela [Mon, 30 Nov 2026 13:34:52 +0000 (14:34 +0100)]
pcm: multi: guard chmap handlers against unmapped channels
snd_pcm_multi_query_chmaps(), snd_pcm_multi_get_chmap() and
snd_pcm_multi_set_chmap() index multi->slaves[] / slave_maps[] with
bind->slave_idx without checking for the slave_idx < 0 sentinel used for
unmapped channels in sparse binding maps. For such channels this reads or
writes array index -1 (out of bounds).
Skip unmapped channels: report SND_CHMAP_UNKNOWN for the query/get paths
and leave them untouched on set. This matches the existing slave_idx < 0
handling elsewhere in the plugin (channel info, mmap commit, dump).
Jaroslav Kysela [Mon, 30 Nov 2026 13:29:36 +0000 (14:29 +0100)]
pcm: multi: allow sparse binding maps and fix error-path leak
Commit 81c4a89eb445 replaced the binding asserts in snd_pcm_multi_open()
with -EINVAL checks, but it rejected sidxs[i] < 0. Sparse binding maps
legitimately leave sidxs[i] == -1 for gap (unmapped) channels:
_snd_pcm_multi_open() initializes channels_sidx[] to -1 and fills in only
the channels that have a bindings entry. Rejecting negative indices broke
valid configurations, and the trailing "if (sidxs[i] < 0) continue;"
became unreachable dead code.
Handle the unmapped case first by storing the slave_idx < 0 sentinel
(which the rest of the plugin already treats as "not bound") and skipping
the channel. The bounds checks then run only for sidxs[i] >= 0, so the
out-of-range read schannels_count[-1] can no longer happen.
The early "return -EINVAL" also leaked multi, multi->slaves and
multi->channels. Route the binding errors through the existing cleanup
block via goto so all allocations are freed.
Fixes: 81c4a89eb445 ("pcm: replace multi plugin binding asserts with -EINVAL checks") Closes: https://github.com/alsa-project/alsa-lib/issues/536 Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Jaroslav Kysela [Tue, 24 Nov 2026 17:47:54 +0000 (18:47 +0100)]
control: remap: forward non-remapped controls (-ENOENT) to child
Initialize *_rid in remap_id_to_child() and tolerate -ENOENT from it in
the elem info/read/write/lock/unlock paths, so controls that are not in
the remap table are forwarded to the child ctl instead of failing.
Jaroslav Kysela [Tue, 24 Nov 2026 15:35:33 +0000 (16:35 +0100)]
ucm: do not share the ctl cache handle for different device names
uc_mgr_open_ctl() merged any two devices resolving to the same card id
into a single cached ctl_list sharing one snd_ctl_t handle. This is wrong
when the device names differ: hw:1 and default:1 reference the same card
but are distinct control interfaces and must not share a handle.
Match the device name (the part before ':', ignoring the arguments) in
addition to the card id when reusing a cached handle.
Jaroslav Kysela [Tue, 24 Nov 2026 15:35:12 +0000 (16:35 +0100)]
ucm: do not register hw: aliases for non-hw control devices
uc_mgr_ctl_add() unconditionally registered the synthetic hw:<card> and
hw:<id> aliases into the dev_list of every opened control device. These
aliases identify the hw control interface of a card, so adding them to a
different interface (e.g. default:X) makes that handle wrongly claim the
hw name. Two cached entries then reference the same hw:<id> string and a
later hw:X request may be served by (or merged into) the default handle.
Register the hw:<card> / hw:<id> aliases only when the opened device is
actually a hw device, keeping each cache entry tied to a single control
interface.
Jaroslav Kysela [Mon, 23 Nov 2026 14:43:14 +0000 (15:43 +0100)]
ucm: drop self-references in SupportedDevice/ConflictingDevice lists
When a device lists its own name in its SupportedDevice or
ConflictingDevice list, the relationship is ambiguous: a device cannot
meaningfully support or conflict with itself. Drop such self-references
in verb_resolve_optional_devices(), after optional references have been
resolved and before the bidirectional relationships are built, so they
do not propagate to other devices.
Jaroslav Kysela [Mon, 23 Nov 2026 14:18:12 +0000 (15:18 +0100)]
ucm: support optional ('-' prefixed) device references in Syntax 10
A device name in a SupportedDevice or ConflictingDevice list may be
prefixed with '-' to mark the reference as optional. A '-' prefixed name
that matches no device is silently dropped instead of aborting parsing;
when the device exists, the prefix is stripped and it behaves like a
normal reference. This lets shared configuration snippets reference
devices that may or may not be present without conditional blocks.
ucm: confine sysw and cfg-save paths with realpath()
1: execute_sysw() concatenated the sysfs root with a caller path via
snprintf() with no traversal check. Use realpath() and reject paths
that escape the sysfs root.
2: execute_cfgsave() opened a caller-supplied filename with no
restriction. Confine writes to XDG_RUNTIME_DIR (or /tmp) via
realpath().
[ rewritten with check_realpath() helper function -- tiwai ]
pcm: replace multi plugin binding asserts with -EINVAL checks
Sparse binding maps leave sidxs[i] == -1 for gap indices. The previous
assert() calls caused SIGABRT in debug builds and OOB reads under NDEBUG.
Return -EINVAL with explicit bounds and sign checks instead.
pcm: cap route plugin ttable channel dimensions at 1024
csize/ssize grew from config-supplied channel indices with no upper
bound before malloc(csize * ssize * sizeof(entry)). Cap both at 1024,
consistent with other PCM plugins.
topology: fix uint32_t overflow in control decoder size checks
size2 = x->size + x->priv.size was computed in 32-bit arithmetic and could
wrap on a 64-bit host, bypassing the subsequent bounds check. Pre-check
for overflow then cast to size_t. Affects tplg_decode_control_mixer,
tplg_decode_control_enum, and tplg_decode_control_bytes.
conf: reject absolute include paths containing /../
input_stdio_open() previously opened any absolute path without checking
for path traversal. Reject paths that contain "/../" so a planted config
cannot read arbitrary files.
Jaroslav Kysela [Wed, 29 Jul 2026 09:19:01 +0000 (11:19 +0200)]
aserver: add 'gid' config item to set IPC SHM group ID
The default permissions 0666 are too open. Change default permissions
to 0660 and allow specifying a GID in the server configuration.
The group can be specified as a numeric GID or a group name via a
'gid' item in the server's config block, falling back to the 'audio'
group when not specified.
snd_func_iops() initialized result to 0 for both iadd and imul. For
imul this made every multiplication step multiply by 0, so
snd_func_imul() returned 0 for every input since it was added in aa7a0dd7 (2006-10-11). The doxygen example for imul therefore did not
match observed behavior.
Initialize the accumulator to 1 for imul and keep the empty integers
list result as 0. Add table-driven config tests covering iadd and imul
single, multi, zero, negative, empty, and out-of-order integer lists.
Fixes: https://github.com/alsa-project/alsa-lib/issues/456 Closes: https://github.com/alsa-project/alsa-lib/pull/511 Signed-off-by: Bojan Janjatovic <bojan.janjatovic@mamut-studio.com> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Dirk Müller [Tue, 2 Jun 2026 09:17:31 +0000 (11:17 +0200)]
Fix theoretical one-byte buffer overrun
If 64 (sizeof(buf))= or more characters were provided in the input string,
this unconditionally writes a null byte to `buf[64]`, which is one byte
past the end of the array.
Closes: https://github.com/alsa-project/alsa-lib/pull/509 Signed-off-by: Dirk Müller <dirk@dmllr.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Rudi Heitbaum [Fri, 20 Feb 2026 11:31:02 +0000 (11:31 +0000)]
conf, seq, ucm: fix discards const from pointer target
Since glibc-2.43:
For ISO C23, the functions bsearch, memchr, strchr, strpbrk, strrchr,
strstr, wcschr, wcspbrk, wcsrchr, wcsstr and wmemchr that return pointers
into their input arrays now have definitions as macros that return a
pointer to a const-qualified type when the input argument is a pointer
to a const-qualified type.
Seppo Ingalsuo [Wed, 4 Mar 2026 11:10:09 +0000 (13:10 +0200)]
Topology: Add high and extended rates from Linux 6.12
This patch adds to topologies build support for the very high
sample rates 352.8 kHz, 384 kHz, 705,6 kHz, and 768 kHz. The added
extended rates those were introduced in Linux kernel version 6.12
are 12 kHz, 24 kHz, and 128 kHz.
Closes: https://github.com/alsa-project/alsa-lib/pull/497 Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Kai Vehmanen [Mon, 23 Mar 2026 15:10:33 +0000 (17:10 +0200)]
topology: decoder: fix wrong sizeof for enum control allocation in dapm
The tplg_calloc() call for enum control in the dapm widget kcontrol
decode loop used sizeof(*mt) (mixer template) instead of sizeof(*et)
(enum template). On 64-bit systems, snd_tplg_mixer_template is 72 bytes
while snd_tplg_enum_template is 80 bytes, causing an 8-byte heap buffer
overflow when the enum fields (texts, values pointers) were written past
the allocated block. This resulted in heap corruption and e.g. glibc
malloc hit an assert.
Closes: https://github.com/alsa-project/alsa-lib/pull/501 Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Extend DefineRegex to support two matching schemes:
- "first" (default): matches pattern once, extracts capture groups
- "all": matches pattern multiple times, extracts all matches
The "all" scheme creates variables with naming pattern nameN for Nth
match and nameN_M for Nth match's Mth capture group, enabling
extraction of repeating patterns from strings.
Updated documentation with detailed examples and comprehensive
description of regex flags, schemes, and variable naming conventions.
Jaroslav Kysela [Wed, 18 Feb 2026 12:23:26 +0000 (13:23 +0100)]
ucm: add show_err parameter to uc_mgr_get_variable
Add bool show_err parameter to uc_mgr_get_variable() to control whether
an error message is displayed when a variable is not defined. This
centralizes error reporting and eliminates redundant error messages
in callers.
Jaroslav Kysela [Wed, 18 Feb 2026 11:13:15 +0000 (12:13 +0100)]
ucm: find-card,find-device - add UCM variable support for arguments (Syntax 9)
Add variable support for all lookup arguments in find-card and find-device
substitutions. Variables are identified by $ prefix and only enabled for
Syntax 9+ to maintain backward compatibility.
Example usage:
${find-card:field=$FieldName,regex=$Pattern,return=number}
${find-device:type=$DevType,stream=$StreamType,field=$FieldName,regex=$Pattern}
Jaroslav Kysela [Mon, 9 Feb 2026 15:02:01 +0000 (16:02 +0100)]
ucm: add info-card substitution (Syntax 9)
Implement ${info-card:} substitution to retrieve specific fields from
a card's information structure by card number or ID. Unlike ${find-card:}
which searches through cards using regex, ${info-card:} directly queries
a specific card.
Arguments:
card=<STR> card number or card ID (string identifier)
field=<STR> number, id, driver, name, longname, mixername, components
Allow card and field parameters to reference UCM variables by prefixing
with $ character. When the first character is $, the value is resolved
using uc_mgr_get_variable().
Example usage:
${info-card:card=$MyCard,field=$MyField}
Jaroslav Kysela [Fri, 6 Feb 2026 17:41:30 +0000 (18:41 +0100)]
ucm: allow string with substitution for If.Condition block (Syntax 9)
When If.Condition is a string type instead of compound, parse it using
snd_config_load_string with variable substitution support for syntax v9+.
This allows more flexible condition definitions using variable references.
Jaroslav Kysela [Fri, 6 Feb 2026 17:25:01 +0000 (18:25 +0100)]
ucm: optimize if_eval_string with common comparison helper
Refactor if_eval_string() to eliminate code duplication by introducing
a compare_strings() helper function that handles the common pattern of
retrieving, substituting, and comparing string pairs.
Implements Repeat blocks for generating repetitive configuration patterns
with variable substitution. This feature allows applying a configuration
block multiple times with different variable values, significantly reducing
duplication in UCM configuration files.
iterator abstraction allows easy extension for future pattern types.
Example:
Repeat.VolumeInit {
Pattern {
Variable 'ch'
Type Integer
First 0
Last 7
Step 1
}
Apply {
cset "name='PCM Channel ${var:ch} Volume' 100%"
}
}
Jaroslav Kysela [Fri, 6 Feb 2026 11:57:02 +0000 (12:57 +0100)]
ucm: add integer comparison condition (Syntax 9)
Adds support for integer comparison operations in If.Condition blocks.
Supports operators: ==, !=, <, >, <=, >= for comparing integer values.
Both values are substituted and converted from strings to 64-bit integers.
Hexadecimal (C like) strings are also accepted (like 0x1234).
Example usage:
If.check_channels {
Condition {
Type Integer
Operation ">"
Value1 "${var:channels}"
Value2 "2"
}
True { ... }
}
Jaroslav Kysela [Mon, 26 Jan 2026 14:08:54 +0000 (15:08 +0100)]
ucm: libconfig parser - fix pathname for substituted file
The path name substituted file contents and normal file contents
should be handled similary. Use correct function determining
the right base directory name.
Fixes: 8f5779eb ("ucm: add LibraryConfig support") Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Jaroslav Kysela [Tue, 13 Jan 2026 07:09:47 +0000 (08:09 +0100)]
seq: return back old snd_seq_drain_output behaviour for -EAGAIN
It seems that many applications did not follow the documentation
including pyalsa sequencer module, thus return the previous
behaviour and correct documentation.
Closes: https://github.com/alsa-project/alsa-lib/issues/493 Fixes: b97a11ec ("seq: fix snd_seq_drain_output return value for partial drain") Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Jaroslav Kysela [Wed, 7 Jan 2026 16:41:03 +0000 (17:41 +0100)]
error: return old snd_lib_error_set_handler() behaviour
Unfortunately, the case when the old application sets
own error callback using the old method, was not handled
properly in snd_lib_vlog_default() function.
Make sure that only error messages are passed to this
old callback and silent other log priorities.
Jaroslav Kysela [Wed, 10 Dec 2025 15:44:12 +0000 (16:44 +0100)]
conf: cards: unify whitespace - use tabs and remove trailing spaces
Convert leading spaces to tabs for consistent indentation,
remove trailing whitespace from all lines, and normalize
file endings across all card configuration files.