Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 468160 - Buffer overflow in alsactl from media-sound/alsa-utils-1.0.27
Summary: Buffer overflow in alsactl from media-sound/alsa-utils-1.0.27
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: Normal major (vote)
Assignee: Gentoo ALSA team
URL: http://git.alsa-project.org/?p=alsa-u...
Whiteboard:
Keywords:
: 468354 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-05-01 15:42 UTC by John
Modified: 2013-05-03 06:50 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Strace log of alsactl getting killed (alsactl_strace.txt,6.23 KB, text/plain)
2013-05-01 15:42 UTC, John
Details
Fix for buffer overflow crash by using snprintf() (0001-alsactl-sprintf-to-snprintf-prevent-buffer-overflow.patch,1.02 KB, patch)
2013-05-01 16:06 UTC, Doug Goldstein (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John 2013-05-01 15:42:43 UTC
Created attachment 347050 [details]
Strace log of alsactl getting killed

After an update of media-sound/alsa-utils to version 1.0.27 alsactl gets killed when trying to store/restore audio levels:

[john:~]$ sudo alsactl restore 
Password: 
*** buffer overflow detected ***: alsactl - terminated
alsactl: buffer overflow attack in function <unknown> - terminated
Report to http://bugs.gentoo.org/

The stable version of alsa-utils (1.0.26-r2) works fine.

My "emerge --info":

Portage 2.1.11.62 (hardened/linux/amd64, gcc-4.7.2, glibc-2.17, 3.8.10-grsec-bfq-gcc47 x86_64)
=================================================================
System uname: Linux-3.8.10-grsec-bfq-gcc47-x86_64-Intel-R-_Core-TM-_i7-2670QM_CPU_@_2.20GHz-with-gentoo-2.2
KiB Mem:     8151148 total,   5340148 free
KiB Swap:          0 total,         0 free
Timestamp of tree: Wed, 01 May 2013 15:00:01 +0000
ld GNU ld (GNU Binutils) 2.23.1
ccache version 3.1.9 [disabled]
app-shells/bash:          4.2_p45
dev-java/java-config:     2.2.0
dev-lang/python:          2.7.4, 3.2.4
dev-util/ccache:          3.1.9
dev-util/cmake:           2.8.10.2-r2
dev-util/pkgconfig:       0.28
sys-apps/baselayout:      2.2
sys-apps/openrc:          0.11.8::pentoo
sys-apps/sandbox:         2.6-r1
sys-devel/autoconf:       2.13, 2.69
sys-devel/automake:       1.9.6-r3, 1.11.6, 1.12.6, 1.13.1
sys-devel/binutils:       2.23.1
sys-devel/gcc:            4.5.3-r2, 4.6.3, 4.7.2-r1
sys-devel/gcc-config:     1.8
sys-devel/libtool:        2.4.2
sys-devel/make:           3.82-r4
sys-kernel/linux-headers: 3.8 (virtual/os-headers)
sys-libs/glibc:           2.17
Repositories: gentoo games java-overlay zugaina stuff gentoo-zh miramir mozilla x11 raw rion pentoo soehest init6 hardened-dev steam-overlay sabayon x-johnlay
ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="* -@EULA"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=native -O2 -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-march=native -O2 -pipe"
DISTDIR="/usr/portage/distfiles"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync news parallel-fetch protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch xattr"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="ftp://ftp.halifax.rwth-aachen.de/gentoo/ http://ftp.halifax.rwth-aachen.de/gentoo/ http://mirror.leaseweb.com/gentoo/ ftp://mirror.leaseweb.com/gentoo/ http://mirror.switch.ch/ftp/mirror/gentoo/ ftp://mirror.switch.ch/mirror/gentoo/ http://gentoo.kiev.ua/ftp/ ftp://gentoo.kiev.ua/ http://mirror.mcs.anl.gov/pub/gentoo/ ftp://mirror.mcs.anl.gov/pub/gentoo/"
LANG="en_US.UTF-8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j5"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/var/lib/layman/games /var/lib/layman/java-overlay /var/lib/layman/zugaina /var/lib/layman/stuff /var/lib/layman/gentoo-zh /var/lib/layman/miramir /var/lib/layman/mozilla /var/lib/layman/x11 /var/lib/layman/raw /var/lib/layman/rion /var/lib/layman/pentoo /var/lib/layman/soehest /var/lib/layman/init6 /var/lib/layman/hardened-development /var/lib/layman/steam /var/lib/layman/sabayon /home/john/johnlay"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="X a52 aac acl acpi alsa amd64 bash-completion berkdb bluetooth branding bzip2 cairo cdda cdr cli consolekit cracklib crypt cxx dbus djvu dri drm dts dvd dvdr emboss encode exif fam firefox flac ftp gallium gdbm geoip gif gpm gtk gzip hardened iconv ipv6 jack jpeg justify lcms ldap libav libnotify lzma lzo mad matroska mmx mng modules mp3 mp4 mpeg mudflap multilib ncurses nls nptl ogg opengl openmp oss pam pango pax_kernel pcre pdf png policykit ppds pppd qt3support qt4 readline sdl session spell sse sse2 ssl startup-notification svg tcpd tiff truetype udev udisks unicode upower urandom usb v4l vdpau vorbis wxwidgets x264 xcb xml xv xvid zlib" ABI_X86="64" ALSA_CARDS="hda-intel" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump author" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx" INPUT_DEVICES="evdev synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LINGUAS="en en_US en_GB" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-3" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python2_7 python3_2" RUBY_TARGETS="ruby18 ruby19" USERLAND="GNU" VIDEO_CARDS="nouveau" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, USE_PYTHON
Comment 1 Doug Goldstein (RETIRED) gentoo-dev 2013-05-01 15:53:25 UTC
(gdb) bt
#0  0x00007ffff726cfe5 in __GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x00007ffff726e45b in __GI_abort () at abort.c:90
#2  0x00007ffff72aecee in __libc_message (do_abort=2, fmt=0x7ffff73a2a1d "*** %s ***: %s terminated\n")
    at ../sysdeps/unix/sysv/linux/libc_fatal.c:196
#3  0x00007ffff733a197 in __GI___fortify_fail (msg=0x7ffff73a29b4 "buffer overflow detected") at fortify_fail.c:31
#4  0x00007ffff7337fa0 in __GI___chk_fail () at chk_fail.c:28
#5  0x00007ffff7337349 in _IO_str_chk_overflow (fp=<optimized out>, c=<optimized out>) at vsprintf_chk.c:33
#6  0x00007ffff72b2194 in __GI__IO_default_xsputn (f=0x7fffffffda90, data=<optimized out>, n=1) at genops.c:481
#7  0x00007ffff727f779 in _IO_vfprintf_internal (s=<optimized out>, format=<optimized out>, ap=<optimized out>)
    at vfprintf.c:1660
#8  0x00007ffff73373e7 in ___vsprintf_chk (s=0x7fffffffdd50 "      6207\377\377\377\177", flags=1, slen=11, 
    format=0x412982 "%10li\n", args=0x7fffffffdbb8) at vsprintf_chk.c:85
#9  0x00007ffff733732d in ___sprintf_chk (s=<optimized out>, flags=<optimized out>, slen=<optimized out>, 
    format=<optimized out>) at sprintf_chk.c:32
#10 0x000000000040a8f9 in sprintf (__fmt=0x412982 "%10li\n", __s=0x7fffffffdd50 "      6207\377\377\377\177")
    at /usr/include/bits/stdio2.h:33
#11 state_lock_ (timeout=10, lock=1, file=0x4116ba "/var/lib/alsa/asound.state") at lock.c:56
#12 state_lock (file=0x4116ba "/var/lib/alsa/asound.state", lock=1, timeout=10) at lock.c:118
#13 0x000000000040a38a in load_state (file=0x4116ba "/var/lib/alsa/asound.state", 
    initfile=0x41169e "/usr/share/alsa/init/00main", cardname=0x7fffffffe29d "0", do_init=1) at state.c:1660
#14 0x0000000000405ba0 in main (argc=<optimized out>, argv=0x7fffffffdf78) at alsactl.c:354


Looks like a bad sprintf() in state_lock_() in lock.c
Comment 2 Doug Goldstein (RETIRED) gentoo-dev 2013-05-01 16:06:18 UTC
Created attachment 347054 [details, diff]
Fix for buffer overflow crash by using snprintf()
Comment 3 Doug Goldstein (RETIRED) gentoo-dev 2013-05-01 16:07:03 UTC
Looks like upstream has a fix as well but its not optimal because it uses sprintf() still.

http://git.alsa-project.org/?p=alsa-utils.git;a=commit;h=95788fea25c1a59985828d4b91af0772d077600b
Comment 4 Samuli Suominen (RETIRED) gentoo-dev 2013-05-01 16:19:12 UTC
(In reply to comment #0)
> Created attachment 347050 [details]
> Strace log of alsactl getting killed

Fixed in tree with upstream patch. Same patch used both in Fedora, and ArchLinux too.

Imported bunch of other important upstream patches while at it.

(In reply to comment #3)
> Looks like upstream has a fix as well but its not optimal because it uses
> sprintf() still.
> 
> http://git.alsa-project.org/?p=alsa-utils.git;a=commit;
> h=95788fea25c1a59985828d4b91af0772d077600b

Sorry I didn't see this in time. Could you please post this to upstream directly?

+*alsa-utils-1.0.27-r1 (01 May 2013)
+
+  01 May 2013; Samuli Suominen <ssuominen@gentoo.org>
+  +alsa-utils-1.0.27-r1.ebuild, +files/alsa-utils-1.0.27-alsactl.patch,
+  +files/alsa-utils-1.0.27-arecord.patch,
+  +files/alsa-utils-1.0.27-service.patch:
+  Fix typing error in alsa-restore.service systemd file. Fix missing break to
+  the capture loop in arecord. Fix buffer overflow in alsactl wrt #468160 by
+  "John"
Comment 5 Samuli Suominen (RETIRED) gentoo-dev 2013-05-01 16:28:34 UTC
Or I don't mind if you want to add your version of patch to the tree as well after posting it to upstream as -r2. If you think that is necessary.
Comment 6 Doug Goldstein (RETIRED) gentoo-dev 2013-05-01 16:31:36 UTC
(In reply to comment #5)
> Or I don't mind if you want to add your version of patch to the tree as well
> after posting it to upstream as -r2. If you think that is necessary.

I submitted the patch stream. So if its accepted we'll get it in the next release. If this is fixed in the tree I'm happy.
Comment 7 Samuli Suominen (RETIRED) gentoo-dev 2013-05-03 06:50:30 UTC
*** Bug 468354 has been marked as a duplicate of this bug. ***