]> git.alsa-project.org Git - alsa-lib.git/commit
ucm: fix TOCTOU race in sysfs value substitution
authorJaroslav Kysela <perex@perex.cz>
Mon, 30 Nov 2026 13:53:15 +0000 (14:53 +0100)
committerJaroslav Kysela <perex@perex.cz>
Mon, 30 Nov 2026 14:01:19 +0000 (15:01 +0100)
commit6633fb0779fb0e6f2968d81e669d0be3578f993c
tree2960ccccf98ec4c3bb6e8a6af786684106ba23f4
parentbfb27a70a8e1a105779b40625f11d05bb1727c6b
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>
src/ucm/ucm_subs.c