Repository navigation
alsa-lib: security hardening — UCM, conf parser, topology, PCM plugins (6 findings) - #527
Open
HarshRajSinghania wants to merge 5 commits into
Open
HarshRajSinghania wants to merge 5 commits into
HarshRajSinghania wants to merge 5 commits into
Conversation
This was referenced Sep 24, 2026
Contributor
|
Like your another PR, all issues look independent, so could you rather split the changes to individual commits instead of squashing into one? |
HarshRajSinghania
force-pushed
the
alsa-security-hardening-2026-09
branch
from
September 30, 2026 18:57
ece3e32 to
f84cd4c
Compare
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 (CWE-22). Signed-off-by: Harsh Raj Singhania <raj.harshraut@gmail.com>
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 (CWE-190). Signed-off-by: Harsh Raj Singhania <raj.harshraut@gmail.com>
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 (CWE-770). Signed-off-by: Harsh Raj Singhania <raj.harshraut@gmail.com>
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 (CWE-617). Signed-off-by: Harsh Raj Singhania <raj.harshraut@gmail.com>
A1 (sysw): 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 (CWE-22). A2 (cfg-save): execute_cfgsave() opened a caller-supplied filename with no restriction. Confine writes to XDG_RUNTIME_DIR (or /tmp) via realpath() (CWE-73). Signed-off-by: Harsh Raj Singhania <raj.harshraut@gmail.com>
Contributor
Author
|
Thanks @tiwai — done. The changes are now split into individual commits instead of one squashed commit:
Please take another look when you have a moment. |
2 of 7 tasks
Member
|
There is issue with the last commit, the XDG_RUNTIME_DIR assumption is wrong: |
Member
|
Also, I find realpath() checks too expensive, perhaps '/../' check would be okay like in f5377bb . |
Contributor
|
OK, then let's scratch the last one. Others can remain, right? |
jollaitbot
pushed a commit
to sailfishos-mirror/alsa-lib
that referenced
this pull request
Oct 16, 2026
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. Closes: alsa-project/alsa-lib#527 Signed-off-by: Harsh Raj Singhania <raj.harshraut@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
jollaitbot
pushed a commit
to sailfishos-mirror/alsa-lib
that referenced
this pull request
Oct 16, 2026
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. [ fixed coding style -- tiwai ] Closes: alsa-project/alsa-lib#527 Signed-off-by: Harsh Raj Singhania <raj.harshraut@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
jollaitbot
pushed a commit
to sailfishos-mirror/alsa-lib
that referenced
this pull request
Oct 16, 2026
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. [ fixed coding style -- tiwai ] Closes: alsa-project/alsa-lib#527 Signed-off-by: Harsh Raj Singhania <raj.harshraut@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
jollaitbot
pushed a commit
to sailfishos-mirror/alsa-lib
that referenced
this pull request
Oct 16, 2026
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 ] Closes: alsa-project/alsa-lib#527 Signed-off-by: Harsh Raj Singhania <raj.harshraut@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses six independently-triggered security hardening issues found during a source audit of commit
f84cd4c, all verified with proof-of-concept programs.A3 (
shell/system()) and A6 (PCM filepopen) are intentional features and are not patched here — hardening suggestions noted inline for maintainer consideration.A1 — UCM
syswpath traversal (CWE-22) ·src/ucm/main.cexecute_sysw()concatenates the sysfs root with a caller-supplied string viasnprintf()with no..rejection orrealpath()confinement. A UCM path like../../etc/cron.d/x:valuewrites to an arbitrary filesystem location. Fix:realpath()confinement — reject if resolved path does not remain within the sysfs root.A2 — UCM
cfg-saveunrestricted path (CWE-73) ·src/ucm/main.cexecute_cfgsave()callssnd_output_stdio_open(&out, file, "w+")with a raw caller-suppliedfileand no restriction. Any writable path (e.g.~/.ssh/authorized_keys) is reachable. Fix:realpath()check — confine toXDG_RUNTIME_DIR(fallback/tmp).A4 — Config parser absolute include traversal (CWE-22) ·
src/conf.cinput_stdio_open()immediately opens any absolute path (file[0]=='/') without checking for..components. A planted config with</../../etc/shadow>can read arbitrary files. Fix: reject paths containing/../.A5 — Topology control
uint32_tinteger overflow (CWE-190) ·src/topology/ctl.csize2 = x->size + x->priv.sizeis computed in 32-bit unsigned arithmetic before being widened tosize_t. On a 64-bit host,0xFFFFFFF0 + 0x20 = 0x10(wraps), bypassing the subsequentsize2 > sizeguard. Three sites:tplg_decode_control_mixer,tplg_decode_control_enum,tplg_decode_control_bytes(distinct from CVE-2026-25068 which wastplg_decode_control_mixer1). Fix: pre-check for overflow, then(size_t)x->size + (size_t)x->priv.size.A7 — PCM
routeplugin unboundedttableallocation (CWE-770) ·src/pcm/pcm_route.ccsize/ssizegrow from config-supplied channel indices with no upper bound beforemalloc(csize * ssize * sizeof(entry)). Index1073741823→malloc(8 GB). Fix: cap both at 1024 (consistent withdmix,softvol, other PCM plugins).A8 — PCM
multisparse bindings OOB assert (CWE-617) ·src/pcm/pcm_multi.cSparse binding maps leave
sidxs[i] == -1for gap indices.assert(schannels[i] < schannels_count[sidxs[i]])then dereferencesschannels_count[-1]→ SIGABRT (debug) / OOB read (NDEBUG). Fix: replace bothassert()s with explicit-EINVALreturns with bounds and sign checks.Verified: all six PoC programs confirmed on
libasound2 1.2.14/gcc 14.2, commitf84cd4c.Signed-off-by: Harsh Raj Singhania raj.harshraut@gmail.com