]> xenbits.xensource.com Git - libvirt.git/commit
virdevmapper: Don't use libdevmapper to obtain dependencies
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 23 Jul 2020 14:02:00 +0000 (16:02 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Sat, 25 Jul 2020 09:14:39 +0000 (11:14 +0200)
commit22494556542c676d1b9e7f1c1f2ea13ac17e1e3e
treed48094eb12c56de216e7b6ed65df1ca9cb4aa031
parentb8ebbe05451fde7ce541564f73437a29ffd5db0d
virdevmapper: Don't use libdevmapper to obtain dependencies

CVE-2020-14339

When building domain's private /dev in a namespace, libdevmapper
is consulted for getting full dependency tree of domain's disks.
The reason is that for a multipath devices all dependent devices
must be created in the namespace and allowed in CGroups.

However, this approach is very fragile as building of namespace
happens in the forked off child process, after mass close of FDs
and just before dropping privileges and execing QEMU. And it so
happens that when calling libdevmapper APIs, one of them opens
/dev/mapper/control and saves the FD into a global variable. The
FD is kept open until the lib is unlinked or dm_lib_release() is
called explicitly. We are doing neither.

However, the virDevMapperGetTargets() function is called also
from libvirtd (when setting up CGroups) and thus has to be thread
safe. Unfortunately, libdevmapper APIs are not thread safe (nor
async signal safe) and thus we can't use them. Reimplement what
libdevmapper would do using plain C (ioctl()-s, /proc/devices
parsing, /dev/mapper dirwalking, and so on).

Fixes: a30078cb832646177defd256e77c632905f1e6d0
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1858260

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
po/POTFILES.in
src/util/virdevmapper.c