]> git.ipfire.org Git - thirdparty/libvirt.git/log
thirdparty/libvirt.git
9 years agolxc_container: remove extra bool from lxcBasicMounts initialization v1.2.9-maint
Yang hongyang [Sat, 25 Jun 2016 03:53:49 +0000 (11:53 +0800)] 
lxc_container: remove extra bool from lxcBasicMounts initialization

Seems a backport miss. An extra member is passed to struct
virLXCBasicMountInfo.

Signed-off-by: Yang hongyang <hongyang.yang@easystack.cn>
Commit bda5f2b (a backport of commit 2471041) listed one more value
than the virLXCBasicMountInfo has here, because v1.2.9-maint does
not have the skipNoNetns bool (introduced by commit ba9b725 released
in 1.2.11).

Signed-off-by: Ján Tomko <jtomko@redhat.com>
9 years agoqemu: Let empty default VNC password work as documented
Jiri Denemark [Tue, 28 Jun 2016 12:39:58 +0000 (14:39 +0200)] 
qemu: Let empty default VNC password work as documented

CVE-2016-5008

Setting an empty graphics password is documented as a way to disable
VNC/SPICE access, but QEMU does not always behaves like that. VNC would
happily accept the empty password. Let's enforce the behavior by setting
password expiration to "now".

https://bugzilla.redhat.com/show_bug.cgi?id=1180092

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
(cherry picked from commit bb848feec0f3f10e92dd8e5231ae7aa89b5598f3)

9 years agoCVE-2015-5313: storage: don't allow '/' in filesystem volume names
Eric Blake [Wed, 9 Dec 2015 00:46:31 +0000 (17:46 -0700)] 
CVE-2015-5313: storage: don't allow '/' in filesystem volume names

The libvirt file system storage driver determines what file to
act on by concatenating the pool location with the volume name.
If a user is able to pick names like "../../../etc/passwd", then
they can escape the bounds of the pool.  For that matter,
virStoragePoolListVolumes() doesn't descend into subdirectories,
so a user really shouldn't use a name with a slash.

Normally, only privileged users can coerce libvirt into creating
or opening existing files using the virStorageVol APIs; and such
users already have full privilege to create any domain XML (so it
is not an escalation of privilege).  But in the case of
fine-grained ACLs, it is feasible that a user can be granted
storage_vol:create but not domain:write, and it violates
assumptions if such a user can abuse libvirt to access files
outside of the storage pool.

Therefore, prevent all use of volume names that contain "/",
whether or not such a name is actually attempting to escape the
pool.

This changes things from:

$ virsh vol-create-as default ../../../../../../etc/haha --capacity 128
Vol ../../../../../../etc/haha created
$ rm /etc/haha

to:

$ virsh vol-create-as default ../../../../../../etc/haha --capacity 128
error: Failed to create vol ../../../../../../etc/haha
error: Requested operation is not valid: volume name '../../../../../../etc/haha' cannot contain '/'

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 034e47c338b13a95cf02106a3af912c1c5f818d7)

9 years agoremoteClientCloseFunc: Don't mangle connection object refcount
Michal Privoznik [Thu, 3 Sep 2015 10:11:53 +0000 (12:11 +0200)] 
remoteClientCloseFunc: Don't mangle connection object refcount

Well, in 8ad126e6 we tried to fix a memory corruption problem.
However, the fix was not as good as it could be. I mean, the
commit has one line more than it should. I've noticed this output
just recently:

  # ./run valgrind --leak-check=full --show-reachable=yes ./tools/virsh domblklist gentoo
  ==17019== Memcheck, a memory error detector
  ==17019== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
  ==17019== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
  ==17019== Command: /home/zippy/work/libvirt/libvirt.git/tools/.libs/virsh domblklist gentoo
  ==17019==
  Target     Source
  ------------------------------------------------
  fda        /var/lib/libvirt/images/fd.img
  vda        /var/lib/libvirt/images/gentoo.qcow2
  hdc        /home/zippy/tmp/install-amd64-minimal-20150402.iso

  ==17019== Thread 2:
  ==17019== Invalid read of size 4
  ==17019==    at 0x4EFF5B4: virObjectUnref (virobject.c:258)
  ==17019==    by 0x5038CFF: remoteClientCloseFunc (remote_driver.c:552)
  ==17019==    by 0x5069D57: virNetClientCloseLocked (virnetclient.c:685)
  ==17019==    by 0x506C848: virNetClientIncomingEvent (virnetclient.c:1852)
  ==17019==    by 0x5082136: virNetSocketEventHandle (virnetsocket.c:1913)
  ==17019==    by 0x4ECD64E: virEventPollDispatchHandles (vireventpoll.c:509)
  ==17019==    by 0x4ECDE02: virEventPollRunOnce (vireventpoll.c:658)
  ==17019==    by 0x4ECBF00: virEventRunDefaultImpl (virevent.c:308)
  ==17019==    by 0x130386: vshEventLoop (vsh.c:1864)
  ==17019==    by 0x4F1EB07: virThreadHelper (virthread.c:206)
  ==17019==    by 0xA8462D3: start_thread (in /lib64/libpthread-2.20.so)
  ==17019==    by 0xAB441FC: clone (in /lib64/libc-2.20.so)
  ==17019==  Address 0x139023f4 is 4 bytes inside a block of size 240 free'd
  ==17019==    at 0x4C2B1F0: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==17019==    by 0x4EA8949: virFree (viralloc.c:582)
  ==17019==    by 0x4EFF6D0: virObjectUnref (virobject.c:273)
  ==17019==    by 0x4FE74D6: virConnectClose (libvirt.c:1390)
  ==17019==    by 0x13342A: virshDeinit (virsh.c:406)
  ==17019==    by 0x134A37: main (virsh.c:950)

The problem is, when registering remoteClientCloseFunc(), it's
conn->closeCallback which is ref'd. But in the function itself
it's conn->closeCallback->conn what is unref'd. This is causing
imbalance in reference counting. Moreover, there's no need for
the remote driver to increase/decrease conn refcount since it's
not used anywhere. It's just merely passed to client registered
callback. And for that purpose it's correctly ref'd in
virConnectRegisterCloseCallback() and then unref'd in
virConnectUnregisterCloseCallback().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit e68930077034f786e219bdb015f8880dbc5a246f)
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
9 years agoRevert "LXC: show used memory as 0 when domain is not active"
Jim Fehlig [Mon, 10 Aug 2015 18:49:55 +0000 (12:49 -0600)] 
Revert "LXC: show used memory as 0 when domain is not active"

This reverts commit 1ce7c1d20cfd5afb26d2dbc88201085d52415d0e,
which introduced a significant semantic change to the
virDomainGetInfo() API. Additionally, the change was only
made to 2 of the 15 virt drivers.

Conflicts:
src/qemu/qemu_driver.c

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
(cherry picked from commit 60acb38abbee1636a9cddf8d296f700d115c8f77)

10 years agoTeach virt-aa-helper to use TEMPLATE.qemu if the domain is kvm or kqemu
Cédric Bosdonnat [Tue, 28 Oct 2014 20:42:34 +0000 (14:42 -0600)] 
Teach virt-aa-helper to use TEMPLATE.qemu if the domain is kvm or kqemu

(cherry picked from commit 16d2bc8b98563f801f111795250515fcbd39ab46)

10 years agolxc: set nosuid+nodev+noexec flags on /proc/sys mount
Eric W. Biederman [Tue, 16 Jun 2015 13:44:36 +0000 (14:44 +0100)] 
lxc: set nosuid+nodev+noexec flags on /proc/sys mount

Future kernels will mandate the use of nosuid+nodev+noexec
flags when mounting the /proc/sys filesystem. Unconditionally
add them now since they don't harm things regardless and could
mitigate future security attacks.

(cherry picked from commit 24710414d403f1040794299f5304fee160d0fc23)

Conflicts:
    src/lxc/lxc_container.c

10 years agoconf: fix issue on virCPUDefCopy
Thibaut Collet [Thu, 21 May 2015 13:55:40 +0000 (15:55 +0200)] 
conf: fix issue on virCPUDefCopy

The cpu xml copy is incorrect: the memAccess field is not copied.
The lack of copy of this memAccess field can cause unexpected behaviour for live
migration when vhost user is used.

For example if guest has the following configuration:
....
<cpu>
<model>Westmere</model>
<topology sockets="1" cores="4" threads="1"/>
<numa>
<cell id='0' cpus='0-3' memory='2097152' memAccess='shared'/>
</numa>
</cpu>
....

The used configuration on the remote host in case of live migration is:
....
  <cpu mode='custom' match='exact'>
    <model fallback='allow'>Westmere</model>
    <topology sockets='1' cores='4' threads='1'/>
    <numa>
      <cell id='0' cpus='0-3' memory='2097152' unit='KiB'/>
    </numa>
  </cpu>
....

On the remote host the lack of memAccess info can cause unexpected error on the
qemu backend vhost user driver.

Fixes: def6b3598 ("docs, conf, schema: add support for shared memory mapping")
This issue is present only for libvirt1.2.9 to libvirt1.2.12
With patch 181742d43 ("conf: Move all NUMA configuration to virDomainNuma")
present since libvirt1.2.13 the problem does not exist anymore as NUMA
information are no more in the CPU configuration.

Signed-off-by: Thibaut Collet <thibaut.collet@6wind.com>
10 years agoPrep for release 1.2.9.3 v1.2.9.3
Cole Robinson [Tue, 28 Apr 2015 14:52:50 +0000 (10:52 -0400)] 
Prep for release 1.2.9.3

10 years agostorage: fs: Ignore volumes that fail to open with EACCESS/EPERM
Cole Robinson [Mon, 27 Apr 2015 15:47:28 +0000 (11:47 -0400)] 
storage: fs: Ignore volumes that fail to open with EACCESS/EPERM

Trying to use qemu:///session to create a storage pool pointing at
/tmp will usually fail with something like:

$ virsh pool-start tmp
error: Failed to start pool tmp
error: cannot open volume '/tmp/systemd-private-c38cf0418d7a4734a66a8175996c384f-colord.service-kEyiTA': Permission denied

If any volume in an FS pool can't be opened by the daemon, the refresh
fails, and the pool can't be used.

This causes pain for virt-install/virt-manager though. Imaging a user
downloads a disk image to /tmp. virt-manager wants to import /tmp as
a storage pool, so we can detect what disk format it is, and set the
XML correctly. However this case will likely fail as explained above.

Change the logic here to skip volumes that fail to open. This could
conceivably cause user complaints along the lines of 'why doesn't
libvirt show $ROOT-OWNED-VOLUME-FOO', but figuring that currently
the pool won't even startup, I don't think there are any current
users that care about that case.

https://bugzilla.redhat.com/show_bug.cgi?id=1103308
(cherry picked from commit 56476f6a2d1564c040b749a385c3588a914921f0)

10 years agodomain: conf: Don't validate VM ostype/arch at daemon startup
Cole Robinson [Fri, 17 Apr 2015 20:37:57 +0000 (16:37 -0400)] 
domain: conf: Don't validate VM ostype/arch at daemon startup

When parsing XML, we validate the passed ostype + arch combo against
the detected hypervisor capabilities. This has led to the following
problem:

- Define x86 qemu guest
- qemu is inadvertently removed from the host
- libvirtd is restarted. fails to parse VM config since arch is removed
- 'virsh list --all' is now empty, user is wondering where their VMs went

Add a new internal flag VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS. Use
it when loading VM and snapshot configs from disk.

https://bugzilla.redhat.com/show_bug.cgi?id=1043572
(cherry picked from commit f1a89a8b6d1a1097e41a171a13b1984b06e8ab3e)

10 years agodomain: conf: Better errors on bad os <type> values
Cole Robinson [Thu, 16 Apr 2015 22:08:17 +0000 (18:08 -0400)] 
domain: conf: Better errors on bad os <type> values

If no <os><type> was specified:
  before: unknown OS type no OS type
  after : xml error: an os <type> must be specified

If an <os><type> is specified that's not in our capabiliities data:
  before: unknown OS type: $type
  after : unsupported configuration: no support found for os <type> '$type'

VIR_ERR_OS_TYPE is now unused (as it should be frankly) so drop its strings
as well to save our translators some effort.

(cherry picked from commit 3700c065cde30ff3f70cc3a029279c79c2337a54)

10 years agoReport original error when QMP probing fails with new QEMU
Daniel P. Berrange [Thu, 4 Dec 2014 15:26:41 +0000 (15:26 +0000)] 
Report original error when QMP probing fails with new QEMU

If probing capabilities via QMP fails, we now have a check
that prevents us falling back to -help parsing. Unfortunately
the error message

  "Failed to probe capabilities for /usr/bin/qemu-kvm:
   unsupported configuration: QEMU 2.1.2 is too new for help parsing"

is proving rather unhelpful to the user. We need to be telling
them why QMP failed (the root cause), rather than they can't
use -help (the side effect).

To do this we should capture stderr during QMP probing, and
if -help parsing then sees a new QEMU version, we know that
QMP should have worked, and so we can show the messages from
stderr. The message thus becomes

  "Failed to probe capabilities for /usr/bin/qemu-kvm:
   internal error: QEMU / QMP failed: Could not access
   KVM kernel module: No such file or directory
   failed to initialize KVM: No such file or directory"

(cherry picked from commit 25bf888a6653ecdeca58c597c296757f4cf8a229)

10 years agocpu: Add {Haswell,Broadwell}-noTSX CPU models
Jiri Denemark [Mon, 23 Mar 2015 16:19:28 +0000 (17:19 +0100)] 
cpu: Add {Haswell,Broadwell}-noTSX CPU models

QEMU 2.3 adds these new models to cover Haswell and Broadwell CPUs with
updated microcode. Luckily, they also reverted former the machine type
specific changes to existing models. And since these changes were never
released, we don't need to hack around them in libvirt.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
(cherry picked from commit c563b50605ae9895b981d198e11dbe9f6e18027b)

10 years agostorage: qemu: Fix security labelling of new image chain elements
Peter Krempa [Wed, 19 Nov 2014 17:54:43 +0000 (18:54 +0100)] 
storage: qemu: Fix security labelling of new image chain elements

When creating a disk image snapshot the libvirt code would blindly copy
the parents label to the newly created image. This runs into problems
when you start a VM from an image hosted on NFS (or other storage system
that doesn't support selinux labels) and the snapshot destination is on
a storage system that does support selinux labels. Libvirt's code in
that case generates a different security label for the image hosted on
NFS. This label is valid only for NFS images and doesn't allow access in
case of a locally stored image.

To fix this issue libvirt needs to refrain from copying security
information in cases where the default domain seclabel is a better
choice.

This patch repurposes the now unused @force argument of
virStorageSourceInitChainElement to denote whether a copy of the
security labelling stuff should be attempted or not. This allows to
fine-control the copy operation for cases where we need to keep the
label of the old disk vs. the cases where we need to keep the label
unset to use the default domain imagelabel.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1151718
(cherry picked from commit 7e130e8b3505ce0f821081dffde8c13a7ff921b3)

10 years agoIgnore CPU features without a model for host-passthrough
Ján Tomko [Fri, 5 Dec 2014 13:03:58 +0000 (14:03 +0100)] 
Ignore CPU features without a model for host-passthrough

This fixes reverting to snapshots created by older libvirt
and allows libvirt not to lose track of a domain that
has this in its live status XML (such as a domain
restored from managedsave)

https://bugzilla.redhat.com/show_bug.cgi?id=1030793
https://bugzilla.redhat.com/show_bug.cgi?id=1151885
(cherry picked from commit 15abebdecb35308ddd4d2967efa6dffa4842fac9)

10 years agoDo not format CPU features without a model
Ján Tomko [Fri, 5 Dec 2014 11:32:18 +0000 (12:32 +0100)] 
Do not format CPU features without a model

For host-passthrough CPU we don't honor the CPU
features specified in the XML, but we allow
outputting them via the UPDATE_CPU flag for dumpxml,
this gives user a rough idea of what features the CPU
might have.

After restoring a managedsave'd domain, the features
might end up in the live status XML (in /var/run) without
the model. This XML cannot be parsed by the daemon after
restart and the domain might disappear.

This fix skips formatting the features for HOST_PASSTHROUGH
when UPDATE_CPU is not specified, so the newly restored domains
and newly created snapshots won't be affected.

Note: this doesn't fix existing snapshots or already restored
running domains.

https://bugzilla.redhat.com/show_bug.cgi?id=1030793
https://bugzilla.redhat.com/show_bug.cgi?id=1151885
(cherry picked from commit dd324bb2703b9cf619c521b2a04f186cd9734f0a)

10 years agodomcaps: Check for architecture more wisely
Michal Privoznik [Wed, 8 Apr 2015 14:59:36 +0000 (16:59 +0200)] 
domcaps: Check for architecture more wisely

https://bugzilla.redhat.com/show_bug.cgi?id=1209948

So we have this bug. The virConnectGetDomainCapabilities() API
performs a couple of checks before it produces any result. One of
the checks is if the architecture requested by user can be run by
the binary (again user provided). However, the check is pretty
dumb. It merely compares if the default binary architecture
matches the one provided by user. However, a qemu binary can run
multiple architectures. For instance: qemu-system-ppc64 can run:
ppc, ppcle, ppc64, ppc64le and ppcemb. The default is ppc64, so
if user requested something else, like ppc64le, the check would
have failed without obvious reason.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit 0af9325e6a06fd4478d4eebfcd92dfe7e2ec570c)

10 years agodaemon: Clear fake domain def object that is used to check ACL prior to use
Peter Krempa [Wed, 25 Mar 2015 07:52:26 +0000 (08:52 +0100)] 
daemon: Clear fake domain def object that is used to check ACL prior to use

The fake object is used to pass the domain name and UUID to the ACL code
for events where we don't have the full domain def when dispatching
events. The rest of the entries would be left uninitialized. While this
is not a problem code-wise as the used fields are initialized it looks
ugly in the debugger.

(cherry picked from commit 6ca857c7c8a1f7b571132d6c7fff5a06301a5e9a)

10 years agoutil: identity: Harden virIdentitySetCurrent()
Peter Krempa [Wed, 25 Mar 2015 07:25:45 +0000 (08:25 +0100)] 
util: identity: Harden virIdentitySetCurrent()

Don't unref the old identity unless we set the new one correctly and
unref the new one on failure to set it so that we don't leak any
references or use invalid pointers.

(cherry picked from commit ad886fa6c8ebc321a0386a75c187d315111cf1f3)

10 years agoqemu: Build nvram directory at driver startup
Cole Robinson [Fri, 24 Apr 2015 00:01:05 +0000 (20:01 -0400)] 
qemu: Build nvram directory at driver startup

Similar to what was done for the channel socket in the previous commit.

(cherry picked from commit 19425d110b0ca2ea3588dbf880ce48d81edea89c)

10 years agoqemu: Build channel autosocket directory at driver startup
Cole Robinson [Thu, 23 Apr 2015 23:24:50 +0000 (19:24 -0400)] 
qemu: Build channel autosocket directory at driver startup

Rather than depend on the RPM to put it in place, since this doesn't
cover the qemu:///session case. Currently auto allocated socket path is
completely busted with qemu:///session

https://bugzilla.redhat.com/show_bug.cgi?id=1105274

And because we chown the directory at driver startup now, this also fixes
autosocket startup failures when using user/group=root

https://bugzilla.redhat.com/show_bug.cgi?id=1044561
https://bugzilla.redhat.com/show_bug.cgi?id=1146886
(cherry picked from commit e31ab02fd049aa72bea9cfabde15b2dd17e37f98)

10 years agoqemu: chown autoDumpPath on driver startup
Cole Robinson [Fri, 24 Apr 2015 00:21:21 +0000 (20:21 -0400)] 
qemu: chown autoDumpPath on driver startup

Not sure if this is required, but it makes things consistent with the
rest of the directories.

(cherry picked from commit db3ccd582c94f8c5a046f2f9be92a1ad95bc4753)

10 years agoqemu: conf: Clarify paths that are relative to libDir
Cole Robinson [Fri, 24 Apr 2015 00:16:30 +0000 (20:16 -0400)] 
qemu: conf: Clarify paths that are relative to libDir

Rather than duplicate libDir for each new path

(cherry picked from commit c19f43ae7e69103b9db59be1dcab6f8236fa1b24)

10 years agoavoid using deprecated udev logging functions
Daniel P. Berrange [Mon, 15 Dec 2014 15:32:13 +0000 (15:32 +0000)] 
avoid using deprecated udev logging functions

In systemd >= 218, the udev_set_log_fn method has been marked
deprecated and turned into a no-op. Nothing in the udev client
library will print to stderr by default anymore, so we can
just stop installing a logging hook for new enough udev.

(cherry picked from commit a93a3b975cd0bad37ccae508d9b7a69aa72b6181)

10 years agoqemu: Always refresh capabilities if no <guests> found
Cole Robinson [Thu, 16 Apr 2015 18:51:26 +0000 (14:51 -0400)] 
qemu: Always refresh capabilities if no <guests> found

- Remove all qemu emulators
- Restart libvirtd
- Install qemu emulators
- Call 'virsh version' -> errors

The only thing that will force the qemu driver to refresh it's cached
capablities info is an explict API call to GetCapabilities.

However in the case when the initial caps lookup at driver connect didn't
find a single qemu emulator to poll, the driver is effectively useless
and really can't do anything until it's populated some qemu capabilities
info.

With the above steps, the user would have to either know about the
magic refresh capabilities call, or restart libvirtd to pick up the
changes.

Instead, this patch changes things so that every time a part of th
driver requests access to capabilities info, check to see if
we've previously seen any emulators. If not, force a refresh.

In the case of 'still no emulators found', this is still very quick, so
I can't think of a downside.

https://bugzilla.redhat.com/show_bug.cgi?id=1000116
(cherry picked from commit 95546c43de51a3d54f9a7f65059a6492a64d4f69)

10 years agoqemu: move setting emulatorpin ahead of monitor showing up
Zhou yimin [Thu, 16 Oct 2014 14:18:48 +0000 (22:18 +0800)] 
qemu: move setting emulatorpin ahead of monitor showing up

If VM is configured with many devices(including passthrough devices)
and large memory, libvirtd will take seconds(in the worst case) to
wait for monitor. In this period the qemu process may run on any
PCPU though I intend to pin emulator to the specified PCPU in xml
configuration.

Actually qemu process takes high cpu usage during vm startup.
So this is not the strict CPU isolation in this case.

Signed-off-by: Zhou yimin <zhouyimin@huawei.com>
(cherry picked from commit 411cea638f6ec8503b7142a31e58b1cd85dbeaba)

10 years agorpc: Don't unref identity object while callbacks still can be executed
Peter Krempa [Wed, 25 Mar 2015 07:56:07 +0000 (08:56 +0100)] 
rpc: Don't unref identity object while callbacks still can be executed

While this thread is cleaning up the client and connection objects:
 #2  virFileReadAll (path=0x7f28780012b0 "/proc/1319/stat", maxlen=maxlen@entry=1024, buf=buf@entry=0x7f289c60fc40) at util/virfile.c:1287
 #3  0x00007f28adbb1539 in virProcessGetStartTime (pid=<optimized out>, timestamp=timestamp@entry=0x7f289c60fc98) at util/virprocess.c:838
 #4  0x00007f28adb91981 in virIdentityGetSystem () at util/viridentity.c:151
 #5  0x00007f28ae73f17c in remoteClientFreeFunc (data=<optimized out>) at remote.c:1131
 #6  0x00007f28adcb7f33 in virNetServerClientDispose (obj=0x7f28aecad180) at rpc/virnetserverclient.c:858
 #7  0x00007f28adba8eeb in virObjectUnref (anyobj=<optimized out>) at util/virobject.c:265
 #8  0x00007f28ae74ad05 in virNetServerHandleJob (jobOpaque=<optimized out>, opaque=0x7f28aec93ff0) at rpc/virnetserver.c:205
 #9  0x00007f28adbbef4e in virThreadPoolWorker (opaque=opaque@entry=0x7f28aec88030) at util/virthreadpool.c:145

In stack frame #6 the client->identity object got unref'd, but the code
that removes the event callbacks in frame #5 did not run yet as we are
trying to obtain the system identity (frames #4, #3, #2).

In other thead:
 #0  virObjectUnref (anyobj=anyobj@entry=0x7f288c162c60) at util/virobject.c:264
        klass = 0xdeadbeef
        obj = 0x7f288c162c60
 #1  0x00007f28ae71c709 in remoteRelayDomainEventCheckACL (client=<optimized out>, conn=<optimized out>, dom=dom@entry=0x7f28aecaafc0) at remote.c:164
 #2  0x00007f28ae71fc83 in remoteRelayDomainEventTrayChange (conn=<optimized out>, dom=0x7f28aecaafc0, ... ) at remote.c:717
 #3  0x00007f28adc04e53 in virDomainEventDispatchDefaultFunc (conn=0x7f287c0009a0, event=0x7f28aecab1a0, ...) at conf/domain_event.c:1455
 #4  0x00007f28adc03831 in virObjectEventStateDispatchCallbacks (callbacks=<optimized out>, ....) at conf/object_event.c:724
 #5  virObjectEventStateQueueDispatch (callbacks=0x7f288c083730, queue=0x7fff51f90030, state=0x7f288c18da20) at conf/object_event.c:738
 #6  virObjectEventStateFlush (state=0x7f288c18da20) at conf/object_event.c:816
 #7  virObjectEventTimer (timer=<optimized out>, opaque=0x7f288c18da20) at conf/object_event.c:562
 #8  0x00007f28adb859cd in virEventPollDispatchTimeouts () at util/vireventpoll.c:459

Frame #0 is unrefing an invalid identity object while frame #2 hints
that the client is still dispatching the event.

For untrimmed backtrace see the bugzilla attachment.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1203030
(cherry picked from commit a98129c0ee52b6a8fdd39988a6d090057f149ae9)

10 years agoconf: tests: fix virDomainNetDefFormat for vhost-user in client mode
Maxime Leroy [Fri, 17 Oct 2014 16:45:18 +0000 (18:45 +0200)] 
conf: tests: fix virDomainNetDefFormat for vhost-user in client mode

The mode attribute is required for the source element of vhost-user.
Thus virDomainNetDefFormat should always generate a xml with it and not
only when the mode is server.

The commit fixes the issue. And it adds a vhostuser interface in
'client' mode to qemuxml2argv-net-vhostuser.(args|xml) to test this
usecase.

Signed-off-by: Maxime Leroy <maxime.leroy@6wind.com>
(cherry picked from commit 302720742f6e159af45631475d720cf807e905b9)

10 years agoDocument that USB hostdevs do not need nodeDettach
Ján Tomko [Fri, 20 Mar 2015 09:25:13 +0000 (10:25 +0100)] 
Document that USB hostdevs do not need nodeDettach

The virNodeDeviceDettach API only works on PCI devices.

Originally added by commit 10d3272e, but the API never
supported USB devices.

Reported by: Martin Polednik <mpolednik@redhat.com>

(cherry picked from commit e600a37d276dddf6f5b674328b94b30e10716a99)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
10 years agoDocument behavior of compat when creating qcow2 volumes
Ján Tomko [Tue, 24 Mar 2015 16:13:24 +0000 (17:13 +0100)] 
Document behavior of compat when creating qcow2 volumes

Commit bab2eda changed the behavior for missing compat attribute,
but failed to update the documentation.

Before, the option was omitted from qemu-img command line and the
qemu-img default was used. Now we always specify the compat value
and the default is 0.10.

Reported by Christophe Fergeau
https://bugzilla.gnome.org/show_bug.cgi?id=746660#c4

(cherry picked from commit 7c8ae42d495d683f79ae4baf024f29f089eaa573)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
10 years agoClarify the meaning of version in redirdev filters
Ján Tomko [Thu, 12 Mar 2015 12:13:39 +0000 (13:13 +0100)] 
Clarify the meaning of version in redirdev filters

The version attribute in redirdev filters refers to the revision
of the device, not the version of the USB protocol.

Explicitly state that this is not the USB protocol and remove references
to those round version numbers that resemble USB protocol versions.

https://bugzilla.redhat.com/show_bug.cgi?id=1177237
(cherry picked from commit 76a2a5ce8ba319c63e5c5572d41d768a48d371b5)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
10 years agoStrip control codes in virBufferEscapeString
Ján Tomko [Mon, 30 Mar 2015 10:41:40 +0000 (12:41 +0200)] 
Strip control codes in virBufferEscapeString

These cannot be represented in XML.

We have been stripping them, but only if the string had
characters that needed escaping: <>"'&

Extend the strcspn check to include control codes, and strip
them even if we don't do any escaping.

https://bugzilla.redhat.com/show_bug.cgi?id=1184131
https://bugzilla.redhat.com/show_bug.cgi?id=1066564
(cherry picked from commit aeb5262e4397528d582682471cb8075141189465)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Conflict:
  missing struct testBufAddStrData

10 years agoIgnore storage volumes with control codes in their names
Ján Tomko [Tue, 14 Apr 2015 10:30:55 +0000 (12:30 +0200)] 
Ignore storage volumes with control codes in their names

To prevent generating invalid XML.

https://bugzilla.redhat.com/show_bug.cgi?id=1066564
(cherry picked from commit 60db2bc80fb5048b227c77c5138fe0e2c97e9c14)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
10 years agoStrip control characters from sysfs attributes
Ján Tomko [Tue, 14 Apr 2015 10:30:34 +0000 (12:30 +0200)] 
Strip control characters from sysfs attributes

Including them in the XML makes them unparsable.

https://bugzilla.redhat.com/show_bug.cgi?id=1184131
(cherry picked from commit 557107500b22d4a5ba7d1b09f5f516512dfca67b)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
10 years agoAdd functions dealing with control characters in strings
Ján Tomko [Tue, 14 Apr 2015 10:30:16 +0000 (12:30 +0200)] 
Add functions dealing with control characters in strings

Add virStringHasControlChars that checks if the string has
any control characters other than \t\r\n,
and virStringStripControlChars that removes them in-place.

(cherry picked from commit 2a530a3e50d9314950cff0a5790c81910b0750a9)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Conflicts:
src/libvirt_private.syms
src/util/virstring.c
src/util/virstring.h
tests/virstringtest.c
  virStringStripIPv6Brackets is not backported

10 years agovirNetworkDefUpdateIPDHCPHost: Don't crash when updating network
Michal Privoznik [Thu, 15 Jan 2015 14:42:04 +0000 (15:42 +0100)] 
virNetworkDefUpdateIPDHCPHost: Don't crash when updating network

https://bugzilla.redhat.com/show_bug.cgi?id=1182486

When updating a network and adding new ip-dhcp-host entry, the deamon
may crash. The problem is, we iterate over existing <host/> entries
trying to compare MAC addresses to see if there's already an existing
rule. However, not all entries are required to have MAC address. For
instance, the following is perfectly valid entry:

<host id='00:04:58:fd:e4:15:1b:09:4c:0e:09:af:e4:d3:8c:b8:ca:1e'
name='redhatipv6.redhat.com' ip='2001:db8:ca2:2::119'/>

When the checking loop iterates over this, the entry's MAC address is
accessed directly. Well, the fix is obvious - check if the address is
defined before trying to compare it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit 7d3ae359db604f6052247ad49d7fbce1db7ef99c)

10 years agodaemon: avoid memleak when ListAll returns nothing
Eric Blake [Fri, 13 Mar 2015 23:01:43 +0000 (17:01 -0600)] 
daemon: avoid memleak when ListAll returns nothing

Commit 4f25146 (v1.2.8) managed to silence Coverity, but at the
cost of a memory leak detected by valgrind:
==24129== 40 bytes in 5 blocks are definitely lost in loss record 355 of 637
==24129==    at 0x4A08B1C: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==24129==    by 0x5084B8E: virReallocN (viralloc.c:245)
==24129==    by 0x514D5AA: virDomainObjListExport (domain_conf.c:22200)
==24129==    by 0x201227DB: qemuConnectListAllDomains (qemu_driver.c:18042)
==24129==    by 0x51CC1B6: virConnectListAllDomains (libvirt-domain.c:6797)
==24129==    by 0x14173D: remoteDispatchConnectListAllDomains (remote.c:1580)
==24129==    by 0x121BE1: remoteDispatchConnectListAllDomainsHelper (remote_dispatch.h:1072)

In short, every time a client calls a ListAll variant and asks
for the resulting list, but there are 0 elements to return, we
end up leaking the 1-entry array that holds the NULL terminator.

What's worse, a read-only client can access these functions in a
tight loop to cause libvirtd to eventually run out of memory; and
this can be considered a denial of service attack against more
privileged clients.  Thankfully, the leak is so small (8 bytes per
call) that you would already have some other denial of service with
any guest calling the API that frequently, so an out-of-memory
crash is unlikely enough that this did not warrant a CVE.

* daemon/remote.c (remoteDispatchConnectListAllDomains)
(remoteDispatchDomainListAllSnapshots)
(remoteDispatchDomainSnapshotListAllChildren)
(remoteDispatchConnectListAllStoragePools)
(remoteDispatchStoragePoolListAllVolumes)
(remoteDispatchConnectListAllNetworks)
(remoteDispatchConnectListAllInterfaces)
(remoteDispatchConnectListAllNodeDevices)
(remoteDispatchConnectListAllNWFilters)
(remoteDispatchConnectListAllSecrets)
(remoteDispatchNetworkGetDHCPLeases): Plug leak.

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 3c2ff5029b83c9b33be0f1607a3c61f4f5850612)
Signed-off-by: Eric Blake <eblake@redhat.com>
Conflicts:
daemon/remote.c - context with older cleanup styles

10 years agoconf: error out on missing dhcp host attributes
Ján Tomko [Thu, 26 Feb 2015 08:03:09 +0000 (09:03 +0100)] 
conf: error out on missing dhcp host attributes

In virNetworkDHCPHostDefParseXML an error is reported
when partialOkay == true, and none of ip, mac, name
were supplied.

Add the missing goto and error out in this case.

(cherry picked from commit b15b21f3a52945644c7ccbbe1dd51b86d36ca777)

10 years agoconf: error out on invalid host id
Luyao Huang [Thu, 26 Feb 2015 06:14:20 +0000 (14:14 +0800)] 
conf: error out on invalid host id

https://bugzilla.redhat.com/show_bug.cgi?id=1196503

We already check whether the host id is valid or not, add a jump
to forbid invalid host id.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit 719cd2182bf06196b26204a8cf88d28001b1d79b)

10 years agoconf: Don't format actual network definition in migratable XML
Luyao Huang [Thu, 25 Dec 2014 03:38:00 +0000 (11:38 +0800)] 
conf: Don't format actual network definition in migratable XML

https://bugzilla.redhat.com/show_bug.cgi?id=1177194

When migrate a vm, we will generate a xml via qemuDomainDefFormatLive and
pass this xml to target libvirtd. Libvirt will use the current network
state in def->data.network.actual to generate the xml, this will make
migrate failed when we set a network type guest interface use a macvtap
network as a source in a vm then migrate vm to another host(which has the
different macvtap network settings: different interface name, bridge name...)

Add a flag check in virDomainNetDefFormat, if we set a VIR_DOMAIN_XML_MIGRATABLE
flag when call virDomainNetDefFormat, we won't get the current vm interface
state.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
10 years agoconf: Fix libvirtd crash and memory leak caused by virDomainVcpuPinDel()
Zhang Bo [Wed, 11 Feb 2015 08:48:24 +0000 (16:48 +0800)] 
conf: Fix libvirtd crash and memory leak caused by virDomainVcpuPinDel()

The function virDomainVcpuPinDel() used vcpupin_list to stand for
def->cputune.vcpupin, which made the codes more readable.
However, in this function, it will realloc vcpupin_list later.
As the definition of realloc(), it may free vcpupin_list and then
points it to a new-realloced address, but def->cputune.vcpupin doesn't
point to the new address(it's freed however).
Thus,
1) When we refer to the def->cputune.vcpupin afterwards, which was freed
by realloc(), an INVALID READ occurs, and libvirtd may crash.
2) As no one will use vcpupin_list any more, and no one frees it(it's just
alloced by realloc()), memory leak occurs.

Part of the valgrind logs are shown as below:
==1837== Thread 15:
==1837== Invalid read of size 8
==1837==    at 0x5367337: virDomainDefFormatInternal (domain_conf.c:18392)
        which is : virBufferAsprintf(buf, "<vcpupin vcpu='%u' ",
                          def->cputune.vcpupin[i]->vcpuid);
==1837==    by 0x536966C: virDomainObjFormat (domain_conf.c:18970)
==1837==    by 0x5369743: virDomainSaveStatus (domain_conf.c:19166)
==1837==    by 0x117B26DC: qemuDomainPinVcpuFlags (qemu_driver.c:4586)
==1837==    by 0x53EA313: virDomainPinVcpuFlags (libvirt.c:9803)
==1837==    by 0x14CB7D: remoteDispatchDomainPinVcpuFlags (remote_dispatch.h:6762)
==1837==    by 0x14CC81: remoteDispatchDomainPinVcpuFlagsHelper (remote_dispatch.h:6740)
==1837==    by 0x5464C30: virNetServerProgramDispatchCall (virnetserverprogram.c:437)
==1837==    by 0x546507A: virNetServerProgramDispatch (virnetserverprogram.c:307)
==1837==    by 0x171B83: virNetServerProcessMsg (virnetserver.c:172)
==1837==    by 0x171E6E: virNetServerHandleJob (virnetserver.c:193)
==1837==    by 0x5318E78: virThreadPoolWorker (virthreadpool.c:145)
==1837==  Address 0x12ea2870 is 0 bytes inside a block of size 16 free'd
==1837==    at 0x4C291AC: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==1837==    by 0x52A3D14: virReallocN (viralloc.c:245)
==1837==    by 0x52A3DFB: virShrinkN (viralloc.c:372)
==1837==    by 0x52A3F57: virDeleteElementsN (viralloc.c:503)
==1837==    by 0x533939E: virDomainVcpuPinDel (domain_conf.c:15405)  //doReset为true时才会进到。
==1837==    by 0x117B2642: qemuDomainPinVcpuFlags (qemu_driver.c:4573)
==1837==    by 0x53EA313: virDomainPinVcpuFlags (libvirt.c:9803)
==1837==    by 0x14CB7D: remoteDispatchDomainPinVcpuFlags (remote_dispatch.h:6762)
==1837==    by 0x14CC81: remoteDispatchDomainPinVcpuFlagsHelper (remote_dispatch.h:6740)
==1837==    by 0x5464C30: virNetServerProgramDispatchCall (virnetserverprogram.c:437)
==1837==    by 0x546507A: virNetServerProgramDispatch (virnetserverprogram.c:307)
==1837==    by 0x171B83: virNetServerProcessMsg (virnetserver.c:172)

Steps to reproduce the problem:
1) use virDomainPinVcpuFlags() to pin a guest's vcpu to all the pcpus
of the host.

This patch uses def->cputune.vcpupin instead of vcpupin_list to do the
realloc() job, to avoid invalid read or memory leaking.

Signed-off-by: Zhang Bo <oscar.zhangbo@huawei.com>
Signed-off-by: Yue Wenyuan <yuewenyuan@huawei.com@huawei.com>
(cherry picked from commit 2d27dcb0e968ab10af53568e3cb78ce0614a09b3)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
10 years agoPrep for release 1.2.9.2 v1.2.9.2
Cole Robinson [Sun, 8 Feb 2015 02:36:05 +0000 (21:36 -0500)] 
Prep for release 1.2.9.2

10 years agoutil: storage: Fix parsing of nbd:// URI without path
Peter Krempa [Tue, 3 Feb 2015 17:03:41 +0000 (18:03 +0100)] 
util: storage: Fix parsing of nbd:// URI without path

If a storage file would be backed with a NBD device without path
(nbd://localhost) libvirt would crash when parsing the backing path for
the disk as the URI structure's path element is NULL in such case but
the NBD parser would access it shamelessly.

(cherry picked from commit fdb80ed4f6563928b9942a0d1450e0c725aa6c06)

10 years agoqemu: fix domain startup failing with 'strict' mode in numatune
Wang Rui [Mon, 10 Nov 2014 13:53:19 +0000 (21:53 +0800)] 
qemu: fix domain startup failing with 'strict' mode in numatune

If the memory mode is specified as 'strict' and with one node, we
get the following error when starting domain.

error: Unable to write to '$cgroup_path/cpuset.mems': Device or resource busy

XML is configured with numatune as follows:
  <numatune>
    <memory mode='strict' nodeset='0'/>
  </numatune>

It's broken by Commit 411cea638f6ec8503b7142a31e58b1cd85dbeaba
which moved qemuSetupCgroupForEmulator() before setting cpuset.mems
in qemuSetupCgroupPostInit.

Directory '$cgroup_path/emulator/' is created in qemuSetupCgroupForEmulator.
But '$cgroup_path/emulator/cpuset.mems' it not set and has a default value
(all nodes, such as 0-1). Then we setup '$cgroup_path/cpuset.mems' to the
nodemask (in this case it's '0') in qemuSetupCgroupPostInit. It must fail.

This patch makes '$cgroup_path/emulator/cpuset.mems' is set before
'$cgroup_path/cpuset.mems'. The action is similar with that in
qemuDomainSetNumaParamsLive.

Signed-off-by: Wang Rui <moon.wangrui@huawei.com>
(cherry picked from commit c6e90248676126c209b3b6017ad27cf6c6a0ab8f)

10 years agostorage: Need to clear pool prior to refreshPool during Autostart
John Ferlan [Fri, 30 Jan 2015 18:21:49 +0000 (13:21 -0500)] 
storage: Need to clear pool prior to refreshPool during Autostart

https://bugzilla.redhat.com/show_bug.cgi?id=1176510

When storageDriverAutostart is called path virStateReload via a 'service
libvirtd reload', then because the volume list in the pool wasn't cleared
prior to the call, each volume would be listed multiple times (as many
times as we reload). I believe the issue would be introduced by commit
id '9e093f0b' at least for the libvirtd reload path, although I suppose
the introduction of virStateReload (commit id '70da0494') could be a
different cause.

Thus like other places prior to calling refreshPool, we need to call
virStoragePoolObjClearVols

(cherry picked from commit 1d2e4d8ca2ae84b5ac5bc63c36d3f75afaac136d)

10 years agoxend: Don't crash in virDomainXMLDevID
Michal Privoznik [Fri, 30 Jan 2015 09:37:10 +0000 (10:37 +0100)] 
xend: Don't crash in virDomainXMLDevID

The function is called from all {Attach,Update,Detach}Device APIs to
create config strings that are later passed to the xend to perform the
desired action. The function is intended to handle all supported
devices. However, as of 5b05358abacb1029fa0d61f72decacf0d4fd8ffb we
are trying to get disk driver of the device without checking if the
device really is a disk. This leads to an segmentation fault:

  #0 0x00007ffff7571815 in virDomainDiskGetDriver () from /usr/lib/libvirt.so.0
  #1 0x00007fffeb9ad471 in ?? () from /usr/lib/libvirt/connection-driver/libvirt_driver_xen.so
  #2 0x00007fffeb9b1062 in xenDaemonAttachDeviceFlags () from /usr/lib/libvirt/connection-driver/libvirt_driver_xen.so
  #3 0x00007fffeb9a8a86 in ?? () from /usr/lib/libvirt/connection-driver/libvirt_driver_xen.so
  #4 0x00007ffff7609266 in virDomainAttachDevice () from /usr/lib/libvirt.so.0
  #5 0x0000555555593c9d in ?? ()
  #6 0x00007ffff76743c9 in virNetServerProgramDispatch () from /usr/lib/libvirt.so.0
  #7 0x00005555555a678d in ?? ()
  #8 0x00007ffff755460e in ?? () from /usr/lib/libvirt.so.0
  #9 0x00007ffff7553b06 in ?? () from /usr/lib/libvirt.so.0
  #10 0x00007ffff4998b50 in start_thread () from /lib/x86_64-linux-gnu/libpthread.so.0
  #11 0x00007ffff46e30ed in clone () from /lib/x86_64-linux-gnu/libc.so.6
  #12 0x0000000000000000 in ?? ()

Reported-by: Xiaolin Su <linxxnil@126.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit cd7702d4561bc100f291be7a1f6fa8f358440558)

10 years agoCVE-2015-0236: qemu: Check ACLs when dumping security info from snapshots
Peter Krempa [Tue, 20 Jan 2015 16:01:01 +0000 (17:01 +0100)] 
CVE-2015-0236: qemu: Check ACLs when dumping security info from snapshots

The ACL check didn't check the VIR_DOMAIN_XML_SECURE flag and the
appropriate permission for it. Found via code inspection while fixing
permissions for save images.

(cherry picked from commit b347c0c2a321ec5c20aae214927949832a288c5a)

10 years agoCVE-2015-0236: qemu: Check ACLs when dumping security info from save image
Peter Krempa [Tue, 20 Jan 2015 16:01:01 +0000 (17:01 +0100)] 
CVE-2015-0236: qemu: Check ACLs when dumping security info from save image

The ACL check didn't check the VIR_DOMAIN_XML_SECURE flag and the
appropriate permission for it.

(cherry picked from commit 03c3c0c874c84dfa51ef17556062b095c6e1c0a3)

10 years agoconf: goto error when value of max_sectors is too large
Luyao Huang [Fri, 12 Dec 2014 02:32:54 +0000 (10:32 +0800)] 
conf: goto error when value of max_sectors is too large

Output error when we try to set a too large max_sectors.
Just like queues and cmd_per_lun here.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
(cherry picked from commit ce1d2f63152290098450fa2beecdee79cf929456)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
10 years agoFix hotplugging of block device-backed usb disks
Ján Tomko [Thu, 18 Dec 2014 11:50:18 +0000 (12:50 +0100)] 
Fix hotplugging of block device-backed usb disks

Commit ca91ba7 moved qemuSetupDiskCgroup into the qemuDomainPrepareDisk
helper, but failed to call it for usb disks.

https://bugzilla.redhat.com/show_bug.cgi?id=1175668`
(cherry picked from commit 1cddf0001f5f1af10791181229148f36fd6d94c5)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
10 years agoconf: fix crash when hotplug a channel chr device with no target
Luyao Huang [Tue, 13 Jan 2015 08:41:05 +0000 (16:41 +0800)] 
conf: fix crash when hotplug a channel chr device with no target

https://bugzilla.redhat.com/show_bug.cgi?id=1181408

When we try to hotplug a channel chr device with no target, we
will get success (which should fail) in virDomainChrDefParseXML,
because we use goto cleanup this place and return an incomplete
definition (with no target). In qemuDomainAttachChrDevice,
we add it to the domain definition, but fail to remove it from
there when chardev-add fails, because virDomainChrRemove
matches chardevices according to the target name.
The device definition is then freed in qemuDomainAttachDeviceFlags,
leaving a stale pointer in the domain definition.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit fba7173f7236c705344aa84bf9715074abdc6ea7)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
10 years agoqemu: migration: Unlock vm on failed ACL check in protocol v2 APIs
Peter Krempa [Mon, 8 Dec 2014 18:25:21 +0000 (19:25 +0100)] 
qemu: migration: Unlock vm on failed ACL check in protocol v2 APIs

Avoid leaving the domain locked on a failed ACL check in
qemuDomainMigratePerform() and qemuDomainMigrateFinish2().

Introduced in commit abf75aea247e (Add ACL checks into the QEMU driver).

(cherry picked from commit 2bdcd29c713dfedd813c89f56ae98f6f3898313d)

10 years agostorage: fix crash caused by no check return before set close
Luyao Huang [Wed, 3 Dec 2014 15:01:32 +0000 (23:01 +0800)] 
storage: fix crash caused by no check return before set close

https://bugzilla.redhat.com/show_bug.cgi?id=1087104#c5

When trying to use an invalid offset to virStorageVolUpload(), libvirt
fails in virFDStreamOpenFileInternal(), although it seems libvirt does
not check the return in storageVolUpload(), and calls
virFDStreamSetInternalCloseCb() right after.  But stream doesn't have a
privateData (is NULL) yet, and the daemon crashes then.

0  0x00007f09429a9c10 in pthread_mutex_lock () from /lib64/libpthread.so.0
1  0x00007f094514dbf5 in virMutexLock (m=<optimized out>) at util/virthread.c:88
2  0x00007f09451cb211 in virFDStreamSetInternalCloseCb at fdstream.c:795
3  0x00007f092ff2c9eb in storageVolUpload at storage/storage_driver.c:2098
4  0x00007f09451f46e0 in virStorageVolUpload at libvirt.c:14000
5  0x00007f0945c78fa1 in remoteDispatchStorageVolUpload at remote_dispatch.h:14339
6  remoteDispatchStorageVolUploadHelper at remote_dispatch.h:14309
7  0x00007f094524a192 in virNetServerProgramDispatchCall at rpc/virnetserverprogram.c:437

Signed-off-by: Luyao Huang <lhuang@redhat.com>
(cherry picked from commit 87b9437f8951f9d24f9a85c6bbfff0e54df8c984)

10 years agoqemu: bulk stats: Fix logic in monitor handling
Francesco Romani [Thu, 11 Dec 2014 07:44:09 +0000 (08:44 +0100)] 
qemu: bulk stats: Fix logic in monitor handling

A logic bug in qemuConnectGetAllDomainStats makes the code mark the
monitor as available when qemuDomainObjBeginJob fails, instead of when
it succeeds, as the correct flow requires.

This patch fixes the check and updates the code documentation
accordingly.

Broken by commit 57023c0a3af4af1c547189c1f6712ed5edeb0c0b.

Signed-off-by: Francesco Romani <fromani@redhat.com>
(cherry picked from commit cb104ef734dfea12cb8826dba7e2c98912c4b7e1)
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
10 years agoCVE-2014-8131: Fix possible deadlock and segfault in qemuConnectGetAllDomainStats()
Martin Kletzander [Thu, 27 Nov 2014 14:47:52 +0000 (15:47 +0100)] 
CVE-2014-8131: Fix possible deadlock and segfault in qemuConnectGetAllDomainStats()

When user doesn't have read access on one of the domains he requested,
the for loop could exit abruptly or continue and override pointer which
pointed to locked object.

This patch fixed two issues at once.  One is that domflags might have
had QEMU_DOMAIN_STATS_HAVE_JOB even when there was no job started (this
is fixed by doing domflags |= QEMU_DOMAIN_STATS_HAVE_JOB only when the
job was acquired and cleaning domflags on every start of the loop.
Second one is that the domain is kept locked when
virConnectGetAllDomainStatsCheckACL() fails and continues the loop when
it didn't end.  Adding a simple virObjectUnlock() and clearing the
pointer ought to do.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
(cherry picked from commit 57023c0a3af4af1c547189c1f6712ed5edeb0c0b)
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
10 years agoqemu: Drop OVMF whitelist
Michal Privoznik [Wed, 19 Nov 2014 17:16:12 +0000 (18:16 +0100)] 
qemu: Drop OVMF whitelist

As discussed on the upstream list, it's better not to make this
kind of predictions in libvirt. It may happen that qemu learns
how to enable OVMF on other architectures too and we shouldn't
try to chase that.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit 36148120c1c1e6ad7f4eb6f0995eb7b18ba95922)

10 years agoqemu: Support OVMF on armv7l aarch64 guests
Michal Privoznik [Wed, 19 Nov 2014 15:25:56 +0000 (16:25 +0100)] 
qemu: Support OVMF on armv7l aarch64 guests

Currently, we are whitelisting architectures, that we know how to run
OVMF on. So far, only x86_64 was enabled. However, looking at qemu
code, the same commandline can be used to enable OVMF for armv7l and
aarch64.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit 6d8054b68407a3385b33c867a425ad8278b0b8f0)

10 years agoPrep for release 1.2.9.1 v1.2.9.1
Cole Robinson [Sat, 15 Nov 2014 23:44:37 +0000 (18:44 -0500)] 
Prep for release 1.2.9.1

10 years agoqemu: Don't try to parse -help for new QEMU
Jiri Denemark [Wed, 12 Nov 2014 15:49:59 +0000 (16:49 +0100)] 
qemu: Don't try to parse -help for new QEMU

Since QEMU 1.2.0, we switched to QMP probing instead of parsing -help
(and other commands, such as -cpu ?) output. However, if QMP probing
failed, we still tried starting QEMU with various options and parsing
the output, which was guaranteed to fail because the output changed.
Let's just refuse parsing -help for QEMU >= 1.2.0.

https://bugzilla.redhat.com/show_bug.cgi?id=1160318
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
(cherry picked from commit ae3e29e6e7a9a208732f22721e735d238b2aa8cb)

Conflicts:
tests/qemuhelptest.c

10 years agoqemu: Always set migration capabilities
Jiri Denemark [Mon, 10 Nov 2014 13:46:26 +0000 (14:46 +0100)] 
qemu: Always set migration capabilities

We used to set migration capabilities only when a user asked for them in
flags. This is fine when migration succeeds since the QEMU process is
killed in the end but in case migration fails or if it's cancelled, some
capabilities may remain turned on with no way to turn them off. To fix
that, migration capabilities have to be turned on if requested but
explicitly turned off in case they were not requested but QEMU supports
them.

https://bugzilla.redhat.com/show_bug.cgi?id=1163953
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
(cherry picked from commit ab393383c84eb049fc2d75c3e79249ca58062887)

10 years agonwfilter: fix deadlock caused updating network device and nwfilter
Pavel Hrdina [Wed, 5 Nov 2014 13:28:57 +0000 (14:28 +0100)] 
nwfilter: fix deadlock caused updating network device and nwfilter

Commit 6e5c79a1 tried to fix deadlock between nwfilter{Define,Undefine}
and starting of guest, but this same deadlock exists for
updating/attaching network device to domain.

The deadlock was introduced by removing global QEMU driver lock because
nwfilter was counting on this lock and ensure that all driver locks are
locked inside of nwfilter{Define,Undefine}.

This patch extends usage of virNWFilterReadLockFilterUpdates to prevent
the deadlock for all possible paths in QEMU driver. LXC and UML drivers
still have global lock.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1143780

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 41127244fb90f08cf5032a5d7553f5f0390d925e)

10 years agoqemuPrepareNVRAM: Save domain conf only if domain's persistent
Michal Privoznik [Wed, 12 Nov 2014 17:09:46 +0000 (18:09 +0100)] 
qemuPrepareNVRAM: Save domain conf only if domain's persistent

In one of my previous patches (3a3c3780b) I've tried to fix the
problem of nvram path disappearing on a domain that's been
started and shut down again. I fixed this by explicitly saving
domain's config file.  However, I did a bit of clumsy without
realizing we have a transient domains for which we don't save the
config file. Hence, any domain using UEFI became persistent.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit 54ddc08ddb3d86e90b48b655a51577761e20ac34)

10 years agoDo not crash on gluster snapshots with no host name
Ján Tomko [Wed, 12 Nov 2014 08:34:28 +0000 (09:34 +0100)] 
Do not crash on gluster snapshots with no host name

virStorageFileBackendGlusterInit did not check nhosts.

https://bugzilla.redhat.com/show_bug.cgi?id=1162974
(cherry picked from commit b66288faaba68e22a2876029872ddadf1794bda8)

10 years agoDisplay nicer error message for unsupported chardev hotplug
Ján Tomko [Mon, 10 Nov 2014 15:52:49 +0000 (16:52 +0100)] 
Display nicer error message for unsupported chardev hotplug

Use the device type name if we know it instead of its number,
even if we can't hotplug it:
qemuMonitorJSONAttachCharDevCommand:6094 : operation failed: Unsupported
char device type '10'

(cherry picked from commit cce8e5f7395fef5fa782910bc4a6fc8a786f8bc2)

10 years agoFix virDomainChrEquals for spicevmc
Ján Tomko [Mon, 10 Nov 2014 15:40:49 +0000 (16:40 +0100)] 
Fix virDomainChrEquals for spicevmc

virDomainChrSourceDefIsEqual should return 'true' for
identical SPICEVMC chardevs, and those that have no source
specification.

After this change, a failed hotplug no longer leaves a stale
pointer in the domain definition.

https://bugzilla.redhat.com/show_bug.cgi?id=1162097
(cherry picked from commit b987684ff63a20ab1301c48ca4842930be044f6d)

10 years agoqemu: Update fsfreeze status on domain state transitions
Michal Privoznik [Mon, 3 Nov 2014 11:57:44 +0000 (12:57 +0100)] 
qemu: Update fsfreeze status on domain state transitions

https://bugzilla.redhat.com/show_bug.cgi?id=1160084

As of b6d4dad1 (1.2.5) libvirt keeps track if domain disks have been
frozen. However, this falls into that set of information which don't
survive domain restart. Therefore, we need to clear the flag upon some
state transitions. Moreover, once we clear the flag we must update the
status file too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit 6ea54769ba1816b382698c4311588d7d1a9cd095)

10 years agonetwork: fix call virNetworkEventLifecycleNew when networkStartNetwork fail
Luyao Huang [Sat, 1 Nov 2014 10:03:23 +0000 (18:03 +0800)] 
network: fix call virNetworkEventLifecycleNew when networkStartNetwork fail

When start a network fail, libvirt still call virNetworkEventLifecycleNew
to send a event.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
(cherry picked from commit 45d9ea5cddad5ed151db15362a881b730b8c88f1)

10 years agoRequire at least one console for LXC domain
Ján Tomko [Fri, 31 Oct 2014 08:51:23 +0000 (09:51 +0100)] 
Require at least one console for LXC domain

A domain without a console quietly dies soon after start,
because we try to set /dev/null as a controlling TTY
2014-10-30 15:10:59.705+0000: 1: error : lxcContainerSetupFDs:283 :
ioctl(TIOCSCTTY) failed: Inappropriate ioctl for device

Report an error early instead of trying to start it.

https://bugzilla.redhat.com/show_bug.cgi?id=1155410
(cherry picked from commit 44686f6523cb30a174c052a242fa15f6a2b364e5)

10 years agoDo not probe for power mgmt capabilities in lxc emulator
Ján Tomko [Fri, 31 Oct 2014 09:02:22 +0000 (10:02 +0100)] 
Do not probe for power mgmt capabilities in lxc emulator

It fails after 30 seconds with this error:
error : virDBusCall:1429 : error from service: CanSuspend:
Did not receive a reply. Possible causes include: the remote
application did not send a reply, the message bus security
policy blocked the reply, the reply timeout expired, or the
network connection was broken.

Only probe for the power mgmt capabilities when driver is non-NULL.
This speeds up domain startup by 30 seconds.

https://bugzilla.redhat.com/show_bug.cgi?id=1159227
(cherry picked from commit 7ead1a5d91a93b5614deeef7b0227bffcea9740d)

10 years agoutil: fix releasing pidfile in cleanup
Martin Kletzander [Tue, 4 Nov 2014 09:46:41 +0000 (10:46 +0100)] 
util: fix releasing pidfile in cleanup

Coverity found out the very obvious problem in the code.  That is that
virPidFileReleasePath() was called only if
virPidFileAcquirePath() returned 0.  But virPidFileAcquirePath() doesn't
return only 0 on success, but the FD that needs to be closed.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
(cherry picked from commit 3f43bb832646588f57303f09fe5c7ac8ba7602d8)

10 years agoqemu: stop NBD server after successful migration
Weiwei Li [Tue, 4 Nov 2014 09:52:10 +0000 (10:52 +0100)] 
qemu: stop NBD server after successful migration

In qemuMigrationFinish mig->nbd can not be initialized by
qemuMigrationEatCookie without the QEMU_MIGRATION_COOKIE_NBD flag.
That causes qemuMigrationStopNBDServer to return early without
stopping the NBD server properly.

Signed-off-by: Weiwei Li <nuonuoli@tencent.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit c3012a023f2ae5763027cafc1cf2881a3c7c4b45)

10 years agoqemu: make sure capability probing process can start
Martin Kletzander [Thu, 9 Oct 2014 06:18:33 +0000 (08:18 +0200)] 
qemu: make sure capability probing process can start

When daemon is killed right in the middle of probing a qemu binary for
its capabilities, the qemu process is left running.  Next time the
daemon is starting, it cannot start the probing qemu process because the
one that's already running does have the pidfile flock()'d.

Reported-by: Wang Yufei <james.wangyufei@huawei.com>
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
(cherry picked from commit 0ed1b55b20300e0ea53925349d918935c2114bf2)

10 years agoutil: Introduce virPidFileForceCleanupPath
Martin Kletzander [Sun, 12 Oct 2014 11:40:36 +0000 (13:40 +0200)] 
util: Introduce virPidFileForceCleanupPath

This function is used to cleanup a pidfile doing whatever it takes, even
killing the owning process.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
(cherry picked from commit d1fd086eb41d5505b7dc595abbf6027b9428071b)

10 years agoqemu: make advice from numad available when building commandline
Martin Kletzander [Thu, 30 Oct 2014 06:34:30 +0000 (07:34 +0100)] 
qemu: make advice from numad available when building commandline

Particularly in qemuBuildNumaArgStr(), there was a need for the advice
due to memory backing, which needs to know the nodeset it will be pinned
to.  With newer qemu this caused the following error when starting
domain:

  error: internal error: Advice from numad is needed in case of
  automatic numa placement

even when starting perfectly valid domain, e.g.:

  ...
  <vcpu placement='auto'>4</vcpu>
  <numatune>
    <memory mode='strict' placement='auto'/>
  </numatune>
  <cpu>
    <numa>
      <cell id='0' cpus='0' memory='524288'/>
      <cell id='1' cpus='1' memory='524288'/>
    </numa>
  </cpu>
  ...

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1138545

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
(cherry picked from commit 11a48758a7d6c946062c130b6186ae3eadd58e39)

10 years agoqemu: Release nbd port from migrationPorts instead of remotePorts
weiwei li [Fri, 31 Oct 2014 08:16:22 +0000 (16:16 +0800)] 
qemu: Release nbd port from migrationPorts instead of remotePorts

commit 3e1e16aa8d4238241a1806cb9bdb3b9ad60db777 (Use a port from the
migration range for NBD as well) changed ndb port allocation from
remotePorts to migrationPorts, but did not change the port releasing
process, which makes an error when migrating several times (above 64):
error: internal error: Unable to find an unused port in range
'migration' (49152-49215)

https://bugzilla.redhat.com/show_bug.cgi?id=1159245

Signed-off-by: Weiwei Li <nuonuoli@tencent.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit be598c5ff84656d3498b950d473fafe5b86f87b4)

10 years agoqemu: better error message when block job can't succeed
Eric Blake [Fri, 24 Oct 2014 20:49:13 +0000 (14:49 -0600)] 
qemu: better error message when block job can't succeed

https://bugzilla.redhat.com/show_bug.cgi?id=1140981 reports that
the qemu-kvm shipped as part of RHEL 7.0 intentionally[1] cripples
block jobs by removing the 'block-stream' QMP command, while still
leaving 'block-job-cancel' as an unusable no-op.  Meanwhile, we
already had existing code that checked whether block jobs were
completely missing (such as qemu 0.15), old style (cancel is
synchronous, and all commands spelled with '_'), or new style
(cancel is asynchronous, and all commands spelled with '-'), and
used that three-way probe to give decent error messages.  At the
time that code was added, all existing qemu versions fell in one
of three buckets, and the code was using the presence of
'block-job-cancel' as the witness of which of the three buckets.
But now that RHEL qemu has shipped with intentionally crippled
'block-stream', we have a fourth bucket, which results in ugly
error messages when trying 'virsh blockpull':

 error: Requested operation is not valid: Command 'block-stream' is not found

In reality, the fourth bucket should be treated the same as the
first bucket (no block job support); we can do that by realizing
that no existing build of qemu has working block-stream while
lacking block-job-cancel, so it is easiest to change our witness
to the command that starts a job rather than ends one.  We still
act correctly regarding command spelling and whether cancel is
asynchronous.  And on crippled RHEL builds, we now get the desired:

 error: unsupported configuration: block jobs not supported with this qemu binary

[1] The intentional cripple is limited to qemu-kvm of RHEL; when using
qemu-kvm-rhev of RHEV, block job functionality is supported.  Don't ask
me to explain the "why" behind it all - I'm just dealing with fallout
from someone else's decision.

* src/qemu/qemu_capabilities.h (QEMU_CAPS_BLOCKJOB_SYNC): Tweak comment.
* src/qemu/qemu_capabilities.c (virQEMUCapsCommands): Look for stream
rather than cancel when determining the flavor of block jobs supported.

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 00331bfbc9626ee9e94352453087b521943236ca)

10 years agotest: Add test to verify helpers used for backing file name parsing
Peter Krempa [Wed, 29 Oct 2014 10:01:48 +0000 (11:01 +0100)] 
test: Add test to verify helpers used for backing file name parsing

Add two test cases to verify that the helpers split and parse the
backing store components properly.

(cherry picked from commit 95a56835926e138c9da5584478f947f7816b54fe)

10 years agostorage: Fix crash when parsing backing store URI with schema
Peter Krempa [Wed, 29 Oct 2014 09:55:23 +0000 (10:55 +0100)] 
storage: Fix crash when parsing backing store URI with schema

The code that parses the schema from the URI touches the "hosts[0]"
member of the storage file source structure in case the URI contains a
schema. The hosts array was not yet allocated at the point in the code
where the transport protocol was parsed and set. This lead to a crash of
libvirtd.

Fix the code by allocating the "hosts" array upfront and add a test case
to verify this scenario. (Unfortunately this requires shuffling the test
case numbers too).

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1156288
(cherry picked from commit 98784369fd52ed6aa9bab2a9a9d213c52019e6ee)

10 years agoremote: fix jump depends on uninitialised value
Jincheng Miao [Fri, 24 Oct 2014 04:03:13 +0000 (12:03 +0800)] 
remote: fix jump depends on uninitialised value

Currently remote driver only initializes partial fields of
remote_connect_get_all_domain_stats_args. But xdr_array()
will check the uninitialised field 'doms_val'.
For safty reason, memset all fields of args is better.

Fix the following error from valgrind, like:
==30515== 1 errors in context 1 of 3:
==30515== Conditional jump or move depends on uninitialised value(s)
==30515==    at 0x85E9402: xdr_array (xdr_array.c:88)
==30515==    by 0x4FD8FC9: xdr_remote_connect_get_all_domain_stats_args (remote_protocol.c:6473)
==30515==    by 0x4FE72F2: virNetMessageEncodePayload (virnetmessage.c:350)
==30515==    by 0x4FDD21C: virNetClientProgramCall (virnetclientprogram.c:326)
==30515==    by 0x4FB4D01: callFull.isra.2 (remote_driver.c:6667)
==30515==    by 0x4FCBD45: call (remote_driver.c:6689)
==30515==    by 0x4FCBD45: remoteConnectGetAllDomainStats (remote_driver.c:7793)
==30515==    by 0x4FA0E75: virConnectGetAllDomainStats (libvirt.c:21678)
==30515==    by 0x147FD1: cmdDomstats (virsh-domain-monitor.c:2148)
==30515==    by 0x13006B: vshCommandRun (virsh.c:1915)
==30515==    by 0x12A9E1: main (virsh.c:3699)

Signed-off-by: Jincheng Miao <jmiao@redhat.com>
(cherry picked from commit 28b7601dc7acf99d06277267afb63fff4167b755)

10 years agoqemu_agent: Produce more readable error messages
Michal Privoznik [Tue, 28 Oct 2014 02:41:27 +0000 (03:41 +0100)] 
qemu_agent: Produce more readable error messages

Not every error message from qemu-ga has to have the 'class' field
filled out. For instance, I've seen this error message lately:

  qemuAgentCheckError:1047 : unable to execute QEMU agent command \
  {"execute":"guest-set-time"}: \
  {"error":{"desc":"Invalid parameter type, expected: integer"}}

However, this got translated into rather generic error message:

  internal error: unable to execute QEMU agent command
  'guest-set-time': unknown QEMU command error

So we've dropped better error message in favor of a generic one.
This is due to our code which expects 'class' which is not
present here.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit b7fe5a6555a3c23205794b59a6736c6eb7c9464b)

10 years agoqemu: forbid snapshot-delete --children-only on external snapshot
Eric Blake [Mon, 27 Oct 2014 11:37:34 +0000 (05:37 -0600)] 
qemu: forbid snapshot-delete --children-only on external snapshot

https://bugzilla.redhat.com/show_bug.cgi?id=956506 documents that
given a domain where an internal snapshot parent has an external
snapshot child, we lacked a safety check when trying to use the
--children-only option to snapshot-delete:

$ virsh start dom
$ virsh snapshot-create-as dom internal
$ virsh snapshot-create-as dom external --disk-only
$ virsh snapshot-delete dom external
error: Failed to delete snapshot external
error: unsupported configuration: deletion of 1 external disk snapshots not supported yet
$ virsh snapshot-delete dom internal --children
error: Failed to delete snapshot internal
error: unsupported configuration: deletion of 1 external disk snapshots not supported yet
$ virsh snapshot-delete dom internal --children-only
Domain snapshot internal children deleted

While I'd still like to see patches that actually do proper external
snapshot deletion, we should at least fix the inconsistency in the
meantime.  With this patch:

$ virsh snapshot-delete dom internal --children-only
error: Failed to delete snapshot internal
error: unsupported configuration: deletion of 1 external disk snapshots not supported yet

* src/qemu/qemu_driver.c (qemuDomainSnapshotDelete): Fix condition.

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 2086a9905aac877d1618f96c7eea8e3d6a01fd9a)

10 years agotests: Add SELINUX_LIBS to fix viridentitytest linker bug
Julio Faracco [Fri, 24 Oct 2014 12:33:52 +0000 (10:33 -0200)] 
tests: Add SELINUX_LIBS to fix viridentitytest linker bug

In a clean build system (Ubuntu 14.04), the viridentitytest failed to compile.
Even if all the SELINUX libraries and depedencies are installed. See the error
message below:

[...]
  CC       viridentitytest.o
  CCLD     viridentitytest
/usr/bin/ld: viridentitytest.o: undefined reference to symbol
                                                       'security_disable'
//lib/x86_64-linux-gnu/libselinux.so.1: error adding symbols: DSO missing
                                                           from command line
collect2: error: ld returned 1 exit status
make: *** [viridentitytest] Error 1

Simply adding the variable SELINUX_LIBS in viridentitytest rules of
Makefile.am to include SELINUX libraries into viridentitytest solved that
compilation issue.

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit f2a2d0e9ab89a50d9552d2c70de0301ad2b83224)

10 years agoqemu: migration: Make check for empty hook XML robust
Peter Krempa [Wed, 22 Oct 2014 09:27:36 +0000 (11:27 +0200)] 
qemu: migration: Make check for empty hook XML robust

Also consider whitespace only strings returned from the hook as empty
result.

(cherry picked from commit 19b1ee42b49b2764f7df23787f4b6022886a612c)

10 years agoqemu: restore: Fix restoring of VM when the restore hook returns empty XML
Peter Krempa [Wed, 22 Oct 2014 09:22:08 +0000 (11:22 +0200)] 
qemu: restore: Fix restoring of VM when the restore hook returns empty XML

The documentation for the restore hook states that returning an empty
XML is equivalent with copying the input. There was a bug in the code
checking the returned string by checking the string instead of the
contents. Use the new helper to check if the string is empty.

(cherry picked from commit e38677993734e9af3dbd0589e1cecd0b75f7e757)

10 years agoutil: string: Add helper to check whether string is empty
Peter Krempa [Wed, 22 Oct 2014 08:26:42 +0000 (10:26 +0200)] 
util: string: Add helper to check whether string is empty

The helper checks whether a string contains only whitespace or is NULL.
This will be helpful to skip cases where a user string is optional, but
may be provided empty with the same meaning.

(cherry picked from commit 0eeafeedebe4469fce33d7942551957853856619)

10 years agovirsh: domain: Use global constant for XML file size limit
Peter Krempa [Tue, 14 Oct 2014 08:04:31 +0000 (10:04 +0200)] 
virsh: domain: Use global constant for XML file size limit

Few places still used hardcoded limit for maximum XML size for commands
that accept XML files. The hardcoded limits ranged from 8k to 1M. Use
VSH_MAX_XML_FILE to express this limit in a unified way. This will bump
the limit for the commands that used hardcoded string lengths to 10M.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1152427
(cherry picked from commit 4d1852c48541a29e3c47caf0f2b801dfcb6579db)

10 years agoqemu: Fix hot unplug of SCSI_HOST device
John Ferlan [Tue, 23 Sep 2014 22:53:25 +0000 (18:53 -0400)] 
qemu: Fix hot unplug of SCSI_HOST device

https://bugzilla.redhat.com/show_bug.cgi?id=1141732

Introduced by commit id '8f76ad99' the logic to detach a scsi_host
device (SCSI or iSCSI) fails when attempting to remove the 'drive'
because as I found in my investigation - the DelDevice takes care of
that for us.

The investigation turned up commits to adjust the logic for the
qemuMonitorDelDevice and qemuMonitorDriveDel processing for interfaces
(commit id '81f76598'), disk bus=VIRTIO,SCSI,USB (commit id '0635785b'),
and chr devices (commit id '55b21f9b'), but nothing with the host devices.

This commit uses the model for the previous set of changes and applies
it to the hostdev path. The call to qemuDomainDetachHostSCSIDevice will
return to qemuDomainDetachThisHostDevice handling either the audit of
the failure or the wait for the removal and then call into
qemuDomainRemoveHostDevice for the event, removal from the domain hostdev
list, and audit of the removal similar to other paths.

NOTE: For now the 'conn' param to +qemuDomainDetachHostSCSIDevice is left
as ATTRIBUTE_UNUSED.  Removing requires a cascade of other changes to be
left for a future patch.

(cherry picked from commit d2774e54cde2377c78a7572eb3fec0a663e5017f)

10 years agoqemu: unref cfg after TerminateMachine has been called
Martin Kletzander [Tue, 21 Oct 2014 09:44:13 +0000 (11:44 +0200)] 
qemu: unref cfg after TerminateMachine has been called

Commit 4882618ed13b469d92fa8b2b4a158fdb17dbe9f1 added the code that
requests driver cfg, but forgot to unref it.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
(cherry picked from commit 9661ac2f46eeb4690a25dfc48bdf9dc9a4dfe822)

10 years agoAdd virCgroupTerminateMachine stub
Ján Tomko [Thu, 2 Oct 2014 09:05:50 +0000 (11:05 +0200)] 
Add virCgroupTerminateMachine stub

Fix the build on FreeBSD, broken by commit 4882618.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit 99b2b4571d385eeffdc0ccbac426c66562e78933)

10 years agoqemu: use systemd's TerminateMachine to kill all processes
Guido Günther [Thu, 25 Sep 2014 11:32:58 +0000 (13:32 +0200)] 
qemu: use systemd's TerminateMachine to kill all processes

If we don't properly clean up all processes in the
machine-<vmname>.scope systemd won't remove the cgroup and subsequent vm
starts fail with

  'CreateMachine: File exists'

Additional processes can e.g. be added via

  echo $PID > /sys/fs/cgroup/systemd/machine.slice/machine-${VMNAME}.scope/tasks

but there are other cases like

  http://bugs.debian.org/761521

Invoke TerminateMachine to be on the safe side since systemd tracks the
cgroup anyway. This is a noop if all processes have terminated already.

(cherry picked from commit 4882618ed13b469d92fa8b2b4a158fdb17dbe9f1)

10 years agoutil: Prepare URI formatting for libxml2 >= 2.9.2
Martin Kletzander [Fri, 3 Oct 2014 16:27:01 +0000 (18:27 +0200)] 
util: Prepare URI formatting for libxml2 >= 2.9.2

Since commit 8eb55d782a2b9afacc7938694891cc6fad7b42a5 libxml2 removes
two slashes from the URI when there is no server part.  This is fixed
with beb7281055dbf0ed4d041022a67c6c5cfd126f25, but only if the calling
application calls xmlSaveUri() on URI that xmlURIParse() parsed.  And
that is not the case in virURIFormat().  virURIFormat() accepts
virURIPtr that can be created without parsing it and we do that when we
format network storage paths for gluster for example.  Even though
virStorageSourceParseBackingURI() uses virURIParse(), it throws that data
structure right away.

Since we want to format URIs as URIs and not absolute URIs or opaque
URIs (see RFC 3986), we can specify that with a special hack thanks to
commit beb7281055dbf0ed4d041022a67c6c5cfd126f25, by setting port to -1.

This fixes qemuxml2argvtest test where the disk-drive-network-gluster
case was failing.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
(cherry picked from commit 8f17d0eaae7ee2fa3e214b79b188fc14ed5aa1eb)

10 years agosecurity_selinux: Don't relabel /dev/net/tun
Michal Privoznik [Tue, 7 Oct 2014 14:22:17 +0000 (16:22 +0200)] 
security_selinux: Don't relabel /dev/net/tun

https://bugzilla.redhat.com/show_bug.cgi?id=1147057

The code for relabelling the TAP FD is there due to a race. When
libvirt creates a /dev/tapN device it's labeled as
'system_u:object_r:device_t:s0' by default. Later, when
udev/systemd reacts to this device, it's relabelled to the
expected label 'system_u:object_r:tun_tap_device_t:s0'. Hence, we
have a code that relabels the device, to cut the race down. For
more info see ae368ebfcc4.

But the problem is, the relabel function is called on all TUN/TAP
devices. Yes, on /dev/net/tun too. This is however a special kind
of device - other processes uses it too. We shouldn't touch it's
label then.

Ideally, there would an API in SELinux that would label just the
passed FD and not the underlying path. That way, we wouldn't need
to care as we would be not labeling /dev/net/tun but the FD
passed to the domain. Unfortunately, there's no such API so we
have to workaround until then.

Tested-by: Richard W.M. Jones <rjones@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit ebc05263960f41065fa7d882959ea754b9281ab1)

10 years agoutil: eliminate "use after free" in callers of virNetDevLinkDump
Laine Stump [Wed, 15 Oct 2014 22:49:01 +0000 (00:49 +0200)] 
util: eliminate "use after free" in callers of virNetDevLinkDump

virNetDevLinkDump() gets a message from netlink into "resp", then
calls nlmsg_parse() to fill the table "tb" with pointers into resp. It
then returns tb to its caller, but not before freeing the buffer at
resp. That means that all the callers of virNetDevLinkDump() are
examining memory that has already been freed. This can be verified by
filling the buffer at resp with garbage prior to freeing it (or, I
suppose, just running libvirtd under valgrind) then performing some
operation that calls virNetDevLinkDump().

The upstream commit log incorrectly states that the code has been like
this ever since virNetDevLinkDump() was written. In reality, the
problem was introduced with commit e95de74d, first in libvirt-1.0.5,
which was attempting to eliminate a typecast that caused compiler
warnings. It has only been pure luck (or maybe a lack of heavy load,
and/or maybe an allocation algorithm in malloc() that delays re-use of
just-freed memory) that has kept this from causing errors, for example
when configuring a PCI passthrough or macvtap passthrough network
interface.

The solution taken in this patch is the simplest - just return resp to
the caller along with tb, then have the caller free it after they are
finished using the data (pointers) in tb. I alternately could have
made a cleaner interface by creating a new struct that put tb and resp
together along with a vir*Free() function for it, but this function is
only used in a couple places, and I'm not sure there will be
additional new uses of virNetDevLinkDump(), so the value of adding a
new type, extra APIs, etc. is dubious.

(cherry picked from commit f9f9699f40729556238b905f67a7d6f68c084f6a)

10 years agoCVE-2014-7823: dumpxml: security hole with migratable flag
Eric Blake [Thu, 6 Nov 2014 08:42:24 +0000 (09:42 +0100)] 
CVE-2014-7823: dumpxml: security hole with migratable flag

Commit 28f8dfd (v1.0.0) introduced a security hole: in at least
the qemu implementation of virDomainGetXMLDesc, the use of the
flag VIR_DOMAIN_XML_MIGRATABLE (which is usable from a read-only
connection) triggers the implicit use of VIR_DOMAIN_XML_SECURE
prior to calling qemuDomainFormatXML.  However, the use of
VIR_DOMAIN_XML_SECURE is supposed to be restricted to read-write
clients only.  This patch treats the migratable flag as requiring
the same permissions, rather than analyzing what might break if
migratable xml no longer includes secret information.

Fortunately, the information leak is low-risk: all that is gated
by the VIR_DOMAIN_XML_SECURE flag is the VNC connection password;
but VNC passwords are already weak (FIPS forbids their use, and
on a non-FIPS machine, anyone stupid enough to trust a max-8-byte
password sent in plaintext over the network deserves what they
get).  SPICE offers better security than VNC, and all other
secrets are properly protected by use of virSecret associations
rather than direct output in domain XML.

* src/remote/remote_protocol.x (REMOTE_PROC_DOMAIN_GET_XML_DESC):
Tighten rules on use of migratable flag.
* src/libvirt-domain.c (virDomainGetXMLDesc): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit b1674ad5a97441b7e1bd5f5ebaff498ef2fbb11b)

Conflicts:
src/libvirt-domain.c - file split from older src/libvirt.c
Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoqemu: x86_64 is good enough for i686
Lubomir Rintel [Thu, 16 Oct 2014 19:28:00 +0000 (21:28 +0200)] 
qemu: x86_64 is good enough for i686

virt-manager on Fedora sets up i686 hosts with "/usr/bin/qemu-kvm" emulator,
which in turn unconditionally execs qemu-system-x86_64 querying capabilities
then fails:

Error launching details: invalid argument: architecture from emulator 'x86_64' doesn't match given architecture 'i686'

Traceback (most recent call last):
  File "/usr/share/virt-manager/virtManager/engine.py", line 748, in _show_vm_helper
    details = self._get_details_dialog(uri, vm.get_connkey())
  File "/usr/share/virt-manager/virtManager/engine.py", line 726, in _get_details_dialog
    obj = vmmDetails(conn.get_vm(connkey))
  File "/usr/share/virt-manager/virtManager/details.py", line 399, in __init__
    self.init_details()
  File "/usr/share/virt-manager/virtManager/details.py", line 784, in init_details
    domcaps = self.vm.get_domain_capabilities()
  File "/usr/share/virt-manager/virtManager/domain.py", line 518, in get_domain_capabilities
    self.get_xmlobj().os.machine, self.get_xmlobj().type)
  File "/usr/lib/python2.7/site-packages/libvirt.py", line 3492, in getDomainCapabilities
    if ret is None: raise libvirtError ('virConnectGetDomainCapabilities() failed', conn=self)
libvirtError: invalid argument: architecture from emulator 'x86_64' doesn't match given architecture 'i686'

Journal:

Oct 16 21:08:26 goatlord.localdomain libvirtd[1530]: invalid argument: architecture from emulator 'x86_64' doesn't match given architecture 'i686'

(cherry picked from commit afe8f4200f6e80d2510731165dd2cdae741bd9fb)

10 years agoqemu: Don't compare CPU against host for TCG
Cole Robinson [Tue, 23 Sep 2014 17:07:09 +0000 (13:07 -0400)] 
qemu: Don't compare CPU against host for TCG

Right now when building the qemu command line, we try to do various
unconditional validations of the guest CPU against the host CPU. However
this checks are overly applied. The only time we should use the checks
are:

- The user requests host-model/host-passthrough, or

- When KVM is requsted. CPU features requested in TCG mode are always
  emulated by qemu and are independent of the host CPU, so no host CPU
  checks should be performed.

Right now if trying to specify a CPU for arm on an x86 host, it attempts
to do non-sensical validation and falls over.

Switch all the test cases that were intending to test CPU validation to
use KVM, so they continue to test the intended code.

Amend some aarch64 XML tests with a CPU model, to ensure things work
correctly.

(cherry picked from commit cf7fce8f2fd1c930f357fd4ff93ac35f38eb30c6)

10 years agoqemu_command: Split qemuBuildCpuArgStr
Cole Robinson [Tue, 23 Sep 2014 15:35:57 +0000 (11:35 -0400)] 
qemu_command: Split qemuBuildCpuArgStr

Move the CPU mode/model handling to its own function. This is just
code movement and re-indentation.

(cherry picked from commit e1d872dc77c80d43036f928f83f560f2e9286148)

10 years agoRelease of libvirt-1.2.9 v1.2.9
Daniel Veillard [Wed, 1 Oct 2014 08:45:32 +0000 (16:45 +0800)] 
Release of libvirt-1.2.9

* docs/news.html.in libvirt.spec.in: update for release
* po/*.po*: updated localizations and regenerated

10 years agodomain_conf: fix domain deadlock CVE-2014-3657
Pavel Hrdina [Mon, 22 Sep 2014 16:19:07 +0000 (18:19 +0200)] 
domain_conf: fix domain deadlock

If you use public api virConnectListAllDomains() with second parameter
set to NULL to get only the number of domains you will lock out all
other operations with domains.

Introduced by commit 2c680804.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>