No, it says only root can trigger it via /proc/sysrq-trigger. Any user can trigger it with the actual SysRq key on the keyboard.
Could any compromised non-root user generate the keyboard event for SysRq and thereby use SysRq?
Yes, it shouldn’t be too hard to emulate the SysRq key the same way something like an on-screen keyboard works.
Could you test please? We need to know this for sure.
If any non-root user can use SysRq via emulated keyboard event, then this changes security considerations.
Maybe a real keyboard (perhaps PS/2 only) can generate an event (hardware interrupt) that cannot be generated by a non-root user?
What specifically does not look good?
SysRq is also dubbed
Secure Access Key.
I haven’t seen any linux security guides recommending disabling SysRq. Perhaps in context of physical access and/or servers. But physical access is game over anyhow independent from SysRq key.
On the other hand, https://fedoraproject.org/wiki/QA/Sysrq says:
k(Secure Access Key) is useful when you want to be sure there is no trojan program running at console which could grab your password when you would try to login.
SysRq might be a good addition for Prevent Malware from Sniffing the Root Password?
On https://www.whonix.org/wiki/Full_Disk_Encryption we write
In an emergency, Non-Qubes-Whonix ™ is capable of powering-off the computer immediately via the Magic SysRq key feature. This is invoked by pressing the key combination:
o(lower-case letter). On bare-metal linux systems, the FDE passphrase is prompted after rebooting.   The magic key feature does not work on Qubes hosts because the Xen hypervisor does not recognize these commands. 
Previously considered a security feature:
Looks more like we shouldn’t disable SysRq at all, rather make sure it is functional?
Being able to run a bunch of commands that would normally require root (such as killing every process, remounting all filesystems read-only etc.) as an unprivileged user doesn’t look very good. Sounds like a possible privilege escalation hole and/or a feature that can easily be abused.
That’s only the
k option of SysRq, not the whole thing.
How would the trojan be started at the login prompt anyway? That doesn’t really make sense.
We allow powering off with SysRq but disable everything else.
Also, it seems like Xen does support SysRq.
Right. Needs to be confirmed since no one outside of our forums claimed and/or demonstrated that this is possible yet as far as I know.
Speculation: I guess the theory goes if you press “alt + ctrl + F1” to switch to a virtual console that a compromised X server could draw a login console prompt which in fact is not one. While SysRq would be privileged and allow another non-root user (different from
X user) to use
login while making sure that
I’ve looked into this and it doesn’t seem possible.
Things such as
xdotool won’t work as the SysRq key isn’t handled by Xorg and things like /dev/uinput or /proc/sysrq-trigger requires root access already.
It seems like SysRq requires a local keyboard to be connected.
k command only kills programs on the current virtual console so it wouldn’t be able to kill X as it’s not running on the one you switched to.
I don’t think X can mess with other virtual consoles anyway.
The question would be who handles “alt + ctrl + F1”?
Likely not the case.
Well, ultimately all handling of all devices including keyboard and all keys is handled by the kernel but that answers very little without knowing how the kernel handles and/or forwards these tasks.
/lib/systemd/system/console-getty.service uses agetty, not getty. May or may not be an irrelevant detail, didn’t research the difference.
If you are in X, run
sudo journalctl -f and press ctrl + alt + F2 and switch back to X, you will see the following in the log:
Aug 22 18:30:48 dom0 systemd: Started Getty on tty2. Aug 22 18:30:48 dom0 audit: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=getty@tty2 comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success' Aug 22 18:30:48 dom0 kernel: audit: type=1130 audit(1566513048.972:200): pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=getty@tty2 comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
This means as long as no virtual console is being switched to, no getty is ruining. This can be confirmed using
sudo ps aux too. Nowadays there are no needless processes running all the time. Therefore it cannot be getty or agetty listening for ctrl + alt + F1. systemd starts agetty (probably, even though log says getty), looks like.
It might be systemd that intercepts ctrl + alt + F1. Or it could be the kernel which then notifies systemd. But we still don’t know if X could hook/intercept ctrl + alt + F1 since obviously X also knows what’s happening on the keyboard.
Not on SysRq but on “alt + ctrl + F1”
Why “I” can do it but user “man” cannot? What makes “me” and user “man” different?
On non-Qubes Debian I am always wondering if I can switch a virtual console using ctrl + alt + F1, why can user “man” not? And how’s that different in Qubes?
This is about where the process is started and what has connected as controlling terminal. It isn’t anything Qubes specific. A non-privileged process cannot inject characters into a separate session (lets forget about X11 breaking all this assumptions, as we are talking about non-X11 session), especially if it’s of a different user, similarly as it cannot write to files it doesn’t have write permission. to. You can think of it as a write access to /dev/tty* (or /dev/hvc0 in this case). When you login on /dev/hvc0, login process (running as root) will setup permission to
/dev/hvc0and also pass an open FD to it to your shell. Then, you (
user, and that shell) will be able to interact with
/dev/hvc0and specifically run commands connected to it. If you don’t login there, login process will not set the permissions, so you won’t have access.
This does assume kernel enforced permissions are effective, but as we are talking here about in-VM account isolation only, it’s a reasonable assumption.
The Debian devs think the sysrq key should be disabled for security
You should disable this functionality ifaccess to the console is not restricted to authorised users: the console is connected to a modem line, there is easy physical access to the system or it is running in a virtualised environment and other users access the console.
They link to http://tldp.org/HOWTO/Remote-Serial-Console-HOWTO/security-sysrq.html which says
For computers that are not used for kernel software development the magic SysRq key makes an ideal denial of service device. A few unauthenticated keystrokes and the computer is dead in the water. The console, serial or otherwise, must be in an area with access limited to trusted people.
Good finds. Now it’s important to construe what the authors wanted to say.
You should disable this functionality ifaccess to the console is not restricted to authorised users:
Console is restricted to authorised users. Physically nearby adversaries are out of scope.
the console is connected to a modem line,
Not the case. Sounds like legacy. Who’s doing that nowadays still.
there is easy physical access to the system
Physically nearby adversaries are out of scope.
or it is running in a virtualised environment and other users access the console.
Virtualized environment yes but no other user access to console.
For computers that are not used for kernel software development the magic SysRq key makes an ideal denial of service device. A few unauthenticated keystrokes and the computer is dead in the water.
Keystrokes -> sounds physical. -> Physically nearby adversaries are out of scope.
The console, serial or otherwise, must be in an area with access limited to trusted people.
This is the case. Physically nearby adversaries are out of scope.
In my interpretations, none of these authors speak about malware running on the system abusing SysRq as far as I understand.
I don’t see why nearby adversaries should be out of scope. It could be the user themselves making a mistake or some random person pressing buttons. It doesn’t necessarily have to be an advanced adversary.
Debian disables coredumps by default and we disable coredumps in security-misc for other distros.
https://github.com/Whonix/security-misc/blob/master/etc/security/limits.d/disable-coredumps.conf (there are a few other ways we disable them too)
They have so many options to infect and sabotage security that its hopeless to try and stop them. Meanwhile disabling sysrq completely will prevent system admins/owners from doing some useful stuff. I advocate for a whitelist of functions instead of killing off one of the great features Linux supports.
Hence why I said, “It could be the user themselves making a mistake or some random person pressing buttons. It doesn’t necessarily have to be an advanced adversary.”.
That’s basically what we’re doing. We need to make sure the functions we whitelist aren’t too dangerous and have a clear usecase.
Created a separate forum thread for Should (lesser) Adversaries with Physical Access be part of the Threat Model of Whonix / Whonix-Host / Kicksecure?
Why bother with a whitelist if “They have so many options to infect and sabotage security that its hopeless to try and stop them.”? What enhancement would the whitelist give under that assumption?
What’s the threat model? What kind of lesser adversary knows about SysRq? Which SysRq commands would a lesser adversary use?
Generally, I would also suggest to suggest such security enhancements such as related to SysRq or Blacklist more kernel modules to reduce attack surface or others also to other security/privacy focused projects, such as:
- Hardened Gentoo
- https://en.wikipedia.org/wiki/Security-focused_operating_system others?
The purpose of this is to increase the security of the whole ecosystem. Would good would we be off if security of Whonix / Kicksecure would be “perfect” but at the same time:
- Debian package build servers compromised
- Debian maintainers compromised
- Tor relays compromised
- more brain power reviewing suggestions and perhaps being inspired to make further suggestions
- wider testing
- wider use (bugs more easily caught)
- more easily convinced doing the same by Whonix default if others are doing the same
I’d imagine many Linux users would know how to use the SysRq key but aren’t advanced enough to reflash the firmware with malware or other advanced attacks.