]> git.baikalelectronics.ru Git - kernel.git/commit
tools/kvm_stat: fix incorrect detection of debugfs
authorMatthias Gerstner <matthias.gerstner@suse.de>
Thu, 3 Nov 2022 13:59:27 +0000 (14:59 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 9 Nov 2022 17:26:52 +0000 (12:26 -0500)
commit49040276d90047c9b7becdf4a06d2810a2e9cf32
tree0507875646052ab015abe6302a06d22de8042af4
parentc4dff25f13300c17bf775990dbe0cf29767bd0a6
tools/kvm_stat: fix incorrect detection of debugfs

The first field in /proc/mounts can be influenced by unprivileged users
through the widespread `fusermount` setuid-root program. Example:

```
user$ mkdir ~/mydebugfs
user$ export _FUSE_COMMFD=0
user$ fusermount ~/mydebugfs -ononempty,fsname=debugfs
user$ grep debugfs /proc/mounts
debugfs /home/user/mydebugfs fuse rw,nosuid,nodev,relatime,user_id=1000,group_id=100 0 0
```

If there is no debugfs already mounted in the system then this can be
used by unprivileged users to trick kvm_stat into using a user
controlled file system location for obtaining KVM statistics.
Even though the root user is not allowed to access non-root FUSE mounts
for security reasons, the unprivileged user can unmount the FUSE mount
before kvm_stat uses the mounted path.  If it wins the race, kvm_stat
will read from the location where the FUSE mount resided.

Note that the files in debugfs are only opened for reading, so the
attacker can cause very large data to be read in by kvm_stat, or fake
data to be processed, but there should be no viable way to turn this
into a privilege escalation.

The fix is simply to use the file system type field instead. Whitespace
in the mount path is escaped in /proc/mounts thus no further safety
measures in the parsing should be necessary to make this correct.

Message-Id: <20221103135927.13656-1-matthias.gerstner@suse.de>
Signed-off-by: Matthias Gerstner <matthias.gerstner@suse.de>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/kvm/kvm_stat/kvm_stat