alsa-utils/alsactl
Masatake YAMATO ba2bc072dc alsactl: don't free a card pointing NULL
alsactl distributed as part of Fedora 40 got a SEGV:

    # journalctl
    ...
    May 17 00:55:58 dev64.localdomain kernel: alsactl[1923]: segfault at 28 ip 00005600705b3373 sp 00007ffd9712bef0 error 4 in alsactl[5600705af000+13000] likely on CPU 5 (core 8, socket 0)
    ...

As the following output of the debug session, card_free() tried a card
pointing NULL:

    $ sudo coredumpctl debug alsactl
	       PID: 1923 (alsactl)
	       UID: 0 (root)
	       GID: 0 (root)
	    Signal: 11 (SEGV)
	 Timestamp: Fri 2024-05-17 00:55:58 JST (3h 34min ago)
      Command Line: /usr/sbin/alsactl -s -n 19 -c -E ALSA_CONFIG_PATH=/etc/alsa/alsactl.conf --initfile=/lib/alsa/init/00main rdaemon
	Executable: /usr/sbin/alsactl
     Control Group: /system.slice/alsa-state.service
	      Unit: alsa-state.service
	     Slice: system.slice
	   Boot ID: 241b5a2ef86f4940bb3d340583c80d88
	Machine ID: 437365709a8c488c9481ee4b6651c2ec
	  Hostname: dev64.localdomain
	   Storage: /var/lib/systemd/coredump/core.alsactl.0.241b5a2ef86f4940bb3d340583c80d88.1923.1715874958000000.zst (present)
      Size on Disk: 81.7K
	   Package: alsa-utils/1.2.11-1.fc40
	  build-id: 3b6fec58b3566d666d6e9fd48e8fcf04f03f0152
	   Message: Process 1923 (alsactl) of user 0 dumped core.

		    Module libasound.so.2 from rpm alsa-lib-1.2.11-2.fc40.x86_64
		    Module alsactl from rpm alsa-utils-1.2.11-1.fc40.x86_64
		    Stack trace of thread 1923:
		    #0  0x00005600705b3373 card_free (alsactl + 0xa373)
		    #1  0x00005600705c0e54 state_daemon (alsactl + 0x17e54)
		    #2  0x00005600705b2339 main (alsactl + 0x9339)
		    #3  0x00007f4c0b9b7088 __libc_start_call_main (libc.so.6 + 0x2a088)
		    #4  0x00007f4c0b9b714b __libc_start_main_impl (libc.so.6 + 0x2a14b)
		    #5  0x00005600705b2df5 _start (alsactl + 0x9df5)
		    ELF object binary architecture: AMD x86-64

    GNU gdb (Fedora Linux) 14.2-1.fc40
    Copyright (C) 2023 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    Type "show copying" and "show warranty" for details.
    This GDB was configured as "x86_64-redhat-linux-gnu".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <https://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
	<http://www.gnu.org/software/gdb/documentation/>.

    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from /usr/sbin/alsactl...
    Reading symbols from /usr/lib/debug/usr/sbin/alsactl-1.2.11-1.fc40.x86_64.debug...
    [New LWP 1923]
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib64/libthread_db.so.1".
    Core was generated by `/usr/sbin/alsactl -s -n 19 -c -E ALSA_CONFIG_PATH=/etc/alsa/alsactl.conf --init'.
    Program terminated with signal SIGSEGV, Segmentation fault.
    #0  free_list (list=0x20) at /usr/src/debug/alsa-utils-1.2.11-1.fc40.x86_64/alsactl/daemon.c:73
    73		for (i = 0; i < list->size; i++)
    (gdb) where
    #0  free_list (list=0x20) at /usr/src/debug/alsa-utils-1.2.11-1.fc40.x86_64/alsactl/daemon.c:73
    #1  card_free (card=card@entry=0x5600707455f0) at /usr/src/debug/alsa-utils-1.2.11-1.fc40.x86_64/alsactl/daemon.c:82
    #2  0x00005600705c0e54 in state_daemon (file=file@entry=0x5600705c31a1 "/var/lib/alsa/asound.state", cardname=cardname@entry=0x0, period=period@entry=300,
	pidfile=pidfile@entry=0x5600705c3170 "/var/run/alsactl.pid") at /usr/src/debug/alsa-utils-1.2.11-1.fc40.x86_64/alsactl/daemon.c:455
    #3  0x00005600705b2339 in main (argc=<optimized out>, argv=<optimized out>) at /usr/src/debug/alsa-utils-1.2.11-1.fc40.x86_64/alsactl/alsactl.c:459
    (gdb) list
    68
    69	static void free_list(struct id_list *list)
    70	{
    71		int i;
    72
    73		for (i = 0; i < list->size; i++)
    74			free(list->list[i]);
    75		free(list->list);
    76	}
    77
    (gdb) up
    #1  card_free (card=card@entry=0x5600707455f0) at /usr/src/debug/alsa-utils-1.2.11-1.fc40.x86_64/alsactl/daemon.c:82
    82		free_list(&c->blacklist);
    (gdb) p c
    $1 = (struct card *) 0x0
    (gdb)

Closes: https://github.com/alsa-project/alsa-utils/pull/267
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2024-05-23 13:17:59 +02:00
..
init alsactl: fix typo in comment in 00main 2022-01-27 13:19:36 +01:00
.gitignore alsactl: systemd and udev hookup 2010-11-23 10:42:35 +01:00
90-alsa-restore.rules.in alsa-restore.rules: use devnode instead number atribute 2023-11-15 15:02:34 +01:00
alsa-restore.service.in alsactl: Remove asound.state file check from alsa-restore.service again 2020-12-11 23:55:34 +01:00
alsa-state.service.in alsactl: Move systemd unit start-up from basic.target to sound.target 2017-10-06 14:32:16 +02:00
alsactl.1 alsactl: implement 'info' command 2022-05-10 09:08:26 +02:00
alsactl.c alsactl: fix potential buffer overwrite 2023-12-08 19:56:45 +01:00
alsactl.h alsactl: implement 'info' command 2022-05-10 09:08:26 +02:00
alsactl_init.xml alsactl: Read only *.conf files when a directory is passed via INCLUDE 2012-06-14 16:06:42 +02:00
clean.c alsactl: snd_ctl_elem_id_compare was renamed to snd_ctl_elem_id_compare_set 2021-03-23 17:52:13 +01:00
daemon.c alsactl: don't free a card pointing NULL 2024-05-23 13:17:59 +02:00
info.c alsactl: fix the copy-n-paste typo (SND_RAWMIDI_STREAM_*) 2023-08-30 10:57:31 +02:00
init_parse.c alsactl: fix the verbose compilation warnings for latest gcc 2023-08-30 12:35:23 +02:00
init_sysdeps.c alsactl: add define to compile with glibc 2.38 2023-08-01 09:36:04 +02:00
init_sysfs.c alsactl: sysfs - add /sys/kernel/uevent_seqnum check to init 2019-11-25 18:01:32 +01:00
init_ucm.c alsactl: add dbg() prints to init_ucm() 2022-02-01 19:47:53 +01:00
init_utils_run.c Initial 'alsactl init' implementation 2008-07-31 15:45:08 +02:00
init_utils_string.c Fix misc compile warnings in alsactl 2009-02-18 15:34:57 +01:00
list.h Initial 'alsactl init' implementation 2008-07-31 15:45:08 +02:00
lock.c alsactl: fix the verbose compilation warnings for latest gcc 2023-08-30 12:35:23 +02:00
Makefile.am alsactl: fix compilation when building in a subdir 2023-08-30 18:56:41 +02:00
monitor.c alsactl: fix the verbose compilation warnings for latest gcc 2023-08-30 12:35:23 +02:00
state.c alsactl: fix the verbose compilation warnings for latest gcc 2023-08-30 12:35:23 +02:00
utils.c alsactl: add locking for per-card initialization 2022-02-02 15:34:40 +01:00