7 ms·
Beep security update
- Y_Y 9y agoCan't one just sudo echo -e "\7” anyway? Or if you're trying to do something fancier there is snd-pcsp which lets use use the piezo as a normal ALSA device (quality may vary). Not that many modern machines even include such a useful device.
- dblotsky 9y agoNitpick: on my machine, that's: sudo echo -e "\07"
- FreeFull 9y agoSimply displaying a character doesn't need sudo at all anyway, so just echo -e "\07"
- laumars 9y ago`sudo` isn't there for displaying the character, it's there for ioctl to have permissions to play the beep on remote terminals[1]. I think some terminal emulators (eg Konsole) will just read char 7 and play a system defined WAV or other workaround but your more classic terminals (eg xterm) would potentially have difficulties calling the system bell. [1] for reference: Xorg terminals are also classed as remote terminals (eg check the TTY column in `w` to see how Linux assigns pseudo-tty's to terminal emulators inside X).
- FreeFull 9y agoEven in that case, you'd have to run the terminal as root. Running echo as root won't do anything. X11 also has beep functionality built in, which is what I'd expect xterm to use.
- laumars 9y ago> Even in that case, you'd have to run the terminal as root. Running echo as root won't do anything. To be honest that was my assumption as well but I didn't test that theory so was only reporting on the rationale of the GPs post > X11 also has beep functionality built in, which is what I'd expect xterm to use X11 runs as root though (that said Xorg may not anymore now as there were talks about patching Linux so it didn't have to be) so Xorg could easily still use the standard ioctl bell (that's possibly all Xorg is doing behind the scenes in fact?) But as I said earlier, some GUI terminal emulators avoid ioctl entirely and play a WAV tone instead.
- jwilk 9y ago"echo -e" is not portable, and neither are any escape sequences for echo. The portable way to print ASCII BEL is: printf '\a'
- Retr0spectrum 9y agoWhy would that need root? Is it not up to your terminal emulator to interpret the \7 and trigger the actual beep?
- rnhmjoj 9y agoSee the "A note about ioctl" section of the README: https://github.com/johnath/beep https://github.com/johnath/beep
- DCoder 9y agoThat section says: > there's only one file opening, and while there is a potential race condition there, it's with /dev/console. If someone can exploit this race by replacing /dev/console, you've got bigger problems. :) However, by reading the source one can see that you can now tell beep where it should direct its output (-e, which is not documented anywhere), so the note above is no longer accurate. I would guess that this is the crux of the problem – the patch that fixes the security issue basically changes "open the output device once for each beep" to "open the output device on startup", greatly reducing the number of races. (It also zeroes out the buffer that's being written to certain output devices, but I have no idea if that is also to patch this security hole or to proactively prevent uninitialized bytes from leaking.)
- jwilk 9y agoBut echo doesn't do any ioctls. The only thing it does is writing bytes on stdout.
- scbrg 9y agoI guess the whole point of setuid is that no, you can't always "just sudo" :-)
- gall0ws 9y agoYes, it tries to do fancy things with ioctl().
- DCoder 9y agoIf you're connected to a remote server, `echo` will annoy you and your cat, but `beep` will annoy the server administrator :)
- exikyut 9y agoI have long wished servers had functioning speakers. And that virtio-beep existed. I wonder what would happen if I pushed to get the support into KVM and the kernel. Best case scenario, the videos accompanying the too-bemused-to-really-be-angry bug reports would be legendary.
- ape4 9y agoor #include <curses.h> main() { beep(); } In fairness, the beep command does more https://linux.die.net/man/1/beep https://linux.die.net/man/1/beep
- nxtafan 9y agohttps://github.com/johnath/beep/issues/11#issuecomment-378383752 https://github.com/johnath/beep/issues/11#issuecomment-37838...
- jwilk 9y agoThe Debian patch with diff highlighting: https://gist.github.com/jwilk/561ae35894756aae1e31503d0c52db7e https://gist.github.com/jwilk/561ae35894756aae1e31503d0c52db... AFAICS, it does this: 1) Fixes use of uninitialized memory. 2) Fixes double-free in the signal handler. 3) Makes sure that the device is opened only once. I still don't understand what exactly the bug is supposed to be. I also don't understand what is the purpose of 3). With this fix applied, it's still possible for a user to open arbitrary file for writing with root privileges, which is bad.
- GrayShade 9y agoHow did you find the Debian patch? http://git.deb.at/w/pkg/beep.git http://git.deb.at/w/pkg/beep.git doesn't seem to have any changes.
- lathiat 9y agoProbably not in that repo as the upload was done by the security team. Best way to get the source is to run “apt-get source beep” on a Debian system.
- jwilk 9y agoOr if you don't have a Debian stable system at hand: Go to https://packages.debian.org/stable/beep https://packages.debian.org/stable/beep and download files from the "Download Source Package" section. If you're only interested in the patch, get this one: http://security.debian.org/debian-security/pool/updates/main/b/beep/beep_1.3-4+deb9u1.debian.tar.xz http://security.debian.org/debian-security/pool/updates/main...
- avian 9y ago
- alex_duf 9y agoThat's hilarious
- akrasuski1 9y agoAlso see https://holeybeep.ninja/ https://holeybeep.ninja/
- voltagex_ 9y agoI've got a couple of problems with that page: * curl | sudo bash for two lines of script * said script just checks if you have beep installed, not if you're vulnerable
- peoplewindow 9y agoGiven the sardonic and amusing way the rest of the page is written, my guess is that's a part of the joke.
- simias 9y agoNot sure if you're aware of that but it's a joke page made as a parody of the recent "branded vulnerability" craze. I would definitely advise against running random scripts from joke pages, especially through sudo. In that regard notice the "TODO" line from the script: #!/bin/sh # TODO: Backdoor this machine? modprobe pcspkr beep -l 1000 -r 3 -f 44000
- jstarks 9y agoJust recently the script said this instead: #!/bin/sh curl https://l0.re/hb | bash modprobe pcspkr beep -l 1000 -r 3 -f 44000 And then that embedded URL says: echo ohai But only after a long delay -- perhaps it is using one of the previously documented techniques to determine whether it's being piped to bash and behaving differently. And now that I try the original curl again, that first line is gone completely: #!/bin/sh modprobe pcspkr beep -l 1000 -r 3 -f 44000 Strange.
- DCoder 9y ago> Is this an OpenSSL bug? > No. > How do I uninstall Linux? > Please follow instructions. Shirley it's not meant as a serious resource.
- garethrees 9y agoThe author of beep needs to read the POSIX specification on async-signal-safety [1]. In particular, it is not safe to call exit, free, ioctl, putchar, or perror from a signal handler. [1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2...
- madez 9y ago> In particular, it is not safe to call exit, free, ioctl, putchar, or perror from a signal handler. Why is it accepted by the compiler, then?
- alexbakker 9y agoWhy wouldn't it be? Why would a compiler know what a signal handler is?
- mikeash 9y agoBecause signals and signal handlers are part of the language spec.
- LukeShu 9y agoI was going to disagree and say that they are part of POSIX, not part of C99; but they are indeed part of C99, section 7.14.1 specifically.
- mikeash 9y agoYeah, it’s a little surprising which parts are where sometimes, and if you spent most of your time on a POSIX system you can easily end up with the wrong assumptions.
- saagarjha 9y agoHow would the compiler know that a function was a signal handler?
- peoplewindow 9y agoFrom the beep readme: By default beep is not installed with the suid bit set, because that would just be zany. On the other hand, if you do make it suid root, all your problems with beep bailing on ioctl calls will magically vanish, which is pleasant, and the only reason not to is that any suid program is a potential security hole. Conveniently, beep is very short, so auditing it is pretty straightforward. https://github.com/johnath/beep https://github.com/johnath/beep
- exikyut 9y agoAnd all this time I've read that and thought "well at least you're putting it out there, just in case - almost for the sake of it" Heh
- jfindley 9y agoI'd love to hear the backstory. Who on _earth_ goes looking for vulnerabilities in beep?!
- netsec_burn 9y agoI was looking into this the other day. It was the original developer of the tool who found the vulnerability in it.
- alxlaz 9y agoIf I had to guess, I'd say they were doing it because it is often installed with suid root. Edit: also, there's a challenge about this in the program's README :-) "Decide for yourself, of course, but it looks safe to me - there's only one buffer and fgets doesn't let it overflow, there's only one file opening, and while there is a potential race condition there, it's with /dev/console. If someone can exploit this race by replacing /dev/console, you've got bigger problems. :)"
- DCoder 9y agoIt should be pointed out that the README is wrong about the race condition – it is not limited to /dev/console, you can use the -e option to point it to a different output device.
- jwilk 9y agoIt doesn't open /dev/console by default either (the default device is /dev/tty0). I don't see where the race condition is, though.
- jwilk 9y agoI wouldn't assume that someone was actively looking for vulnerabilities there. Perhaps a user got curious how is this implemented, looked at the source, and was horrified with what they saw.
- baybal2 9y agoNext, somebody will find a security hole in True (1)
- oh5nxo 9y agoThere's the common minor error with perror(). Intervening printf("\a"); can foul the errno and you get the beep: open: not a typewriter
- tejasmanohar 9y agoIs it worrisome that the Debian distribution comes with a package with this note in the README Decide for yourself, of course, but it looks safe to me - there's only one buffer and fgets doesn't let it overflow, there's only one file opening, and while there is a potential race condition there, it's with /dev/console. If someone can exploit this race by replacing /dev/console, you've got bigger problems. :) It also appears /dev/console is overridable, https://github.com/johnath/beep/blob/master/beep.c#L149 https://github.com/johnath/beep/blob/master/beep.c#L149.
- master-litty 9y agoIt illustrates the author's attention to safety and security. Opposite of worrisome, even if it turned out exploitable. True but same idea applies. If your end device is maliciously replaceable you've got bigger problems.
- jesboat 9y agoFWIW, that comment was written before the option to control the path beep uses was added. Without the option to control the path, the potential race is only exploitable by somebody who can write to /dev, in which case that person is already root.
- 0x0 9y agoDoes GPL say anything about distributing source via git repositories? I mean, it talks about "preferred form of the work for making modifications". But when I click through to the Debian PTS page for Beep at https://tracker.debian.org/pkg/beep https://tracker.debian.org/pkg/beep it shows a git link to http://git.deb.at/w/pkg/beep.git http://git.deb.at/w/pkg/beep.git which was last modified 23 months ago, so obviously does not contain this security fix. How is the GPL upheld if security fixes aren't available together with the main git repository? I don't mean to cause drama, because I think the Debian security team does an awesome job of keeping an eye on patching everything in the distribution. But I'm really curious about how one would go about with further development on a package like this when the git commits aren't available? There's probably a source tarball for the .debs in the apt repos (hard to tell from a mobile web browser) but is that good enough if it doesn't contain git commits? Also I really just wanted to read this security patch source diff on the go :)
- kelnos 9y agoFrom https://packages.debian.org/source/stable/beep https://packages.debian.org/source/stable/beep you can download the tarball of the original sources, as well as the debian patch on top of it.
- lwf 9y ago(N.B.: I'm on the Debian ftpmaster team, which reviews all new software in Debian to ensure it matches our policies and commitments) > Does GPL say anything about distributing source via git repositories? Nope. > I mean, it talks about "preferred form of the work for making modifications". This is generally interpreted as a fancy way of saying "source code" — e.g. a minified JavaScript program or something that could be decompiled isn't the "preferred form… for making modifications". Source for all Debian packages can be retrieved via `apt-get source PACKAGE`, and via sources.debian.org[3]. Historically, the only hard requirement was that all patches be made available as a `.diff.gz` applied against the upstream, although for many years packages have since standardised on using `quilt`[2]. Some maintainers may also use git (and wrappers around it) to make things easier to manage, but quilt is sufficiently straightforward to work with that it's acceptable for most purposes. The VCS page on the BTS points to the repository for the package. It contains an unreleased version (1.3.3-5), the security update only is a patch on the previous version released in Debian. The last upstream release was 1.3 (2010), available on GitHub[1]. This is a Debian-specific patch against beep. We'd like all patches to make it upstream, and ensure maximum clarity, but we have limited time, and our first priority is the users of Debian. Sometimes, upstreams lose time, or there are coordination issues that prevent it. (not saying that's the case here) [1]: http://github.com/johnath/beep/ http://github.com/johnath/beep/ [2]: https://wiki.debian.org/UsingQuilt https://wiki.debian.org/UsingQuilt [3]: https://sources.debian.org/src/beep/unstable/ https://sources.debian.org/src/beep/unstable/