SysRq (Magic SysRq key)

@madaidan can you also exempt sysrq + f from being blocked?

This key is particularly useful when killing a hanging process considering swap is disabled on the host for Whonix live mode to be traceless.

Call oom_kill, which kills a process to alleviate an OOM condition f

2 Likes

I don’t see how this is any better than just using Ctrl + C or kill -9.

They likely won’t want to do that as the map files are good for debugging.

It would protect against malware attempting to check for local files instead of having to use another source.

1 Like

sysrq is immediately applied when the whole machine is stalled and you can’t really open a terminal and type anything. Also isn’t Ctrl + C just the copy command?

2 Likes

Ctrl + C seems fine for that then.

No, Ctrl + C sends the SIGINT command to kill a process. For example, run yes in a terminal and press Ctrl + C to kill it. Ctrl + D can also be used to kill an open terminal.

1 Like

madaidan via Whonix Forum:

Ctrl + C seems fine for that then.

When the whole machine appears frozen Ctrl + C won’t have any effect.
sysrq might work.

2 Likes

Of course, but we shouldn’t be too trusting of Copperhead.

If Ctrl + C doesn’t work, I doubt sysrq would.

sysrq is immediately enforced by a running kernel. That’s what makes these commands so special. If there isn’t a security argument against it, please add it to the mask.

1 Like

Can a user only kill it’s own processes with it or any process?

What if an unprivileged user kills a very important process that is usually only accessible by root?

1 Like

It seems that restricting sysrq was unnecessary as no non admin/root user is allowed to trigger it. A process with root privileges has many more options for killing a process or doing worse.

https://www.kernel.org/doc/html/v4.14/admin-guide/sysrq.html

Note that the value of /proc/sys/kernel/sysrq influences only the invocation via a keyboard. Invocation of any operation via /proc/sysrq-trigger is always allowed (by a user with admin privileges).

1 Like

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.

1 Like

Could any compromised non-root user generate the keyboard event for SysRq and thereby use SysRq?

1 Like

Yes, it shouldn’t be too hard to emulate the SysRq key the same way something like an on-screen keyboard works.

1 Like

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?

2 Likes

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, QA/Sysrq - Fedora Project Wiki says:

Sa 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 Full Disk Encryption (FDE) 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: Alt + PrintScreen + o (lower-case letter). On bare-metal linux systems, the FDE passphrase is prompted after rebooting.[21] [22] [23] The magic key feature does not work on Qubes hosts because the Xen hypervisor does not recognize these commands. [24]

Previously considered a security feature:

Looks more like we shouldn’t disable SysRq at all, rather make sure it is functional?

2 Likes

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.

Magic SysRq key - Wikipedia

The Xen hypervisor has functionality to send magic commands to hosted domains via its xm sysrq command.[11] Additionally, a SysRq command can be invoked from a Xen paravirtual console by sending a break sequence Ctrl+O followed by the desired key.

1 Like

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 Xwas interrupted.

2 Likes

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.

The 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.

2 Likes

The question would be who handles “alt + ctrl + F1”?

1 Like

getty does.

1 Like

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[1]: Started Getty on tty2.
Aug 22 18:30:48 dom0 audit[1]: 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.

1 Like