1. 16 2月, 2013 2 次提交
    • E
      build: fix vircommand build on mingw · ec2cc0f8
      Eric Blake 提交于
        CC       libvirt_util_la-vircommand.lo
      ../../src/util/vircommand.c:2358:1: error: 'virCommandHandshakeChild' defined but not used [-Werror=unused-function]
      
      The function is only implemented inside #ifndef WIN32.
      
      * src/util/vircommand.c (virCommandHandshakeChild): Hoist earlier,
      so that win32 build doesn't hit an unused forward declaration.
      ec2cc0f8
    • E
      regex: gnulib guarantees that we have regex support · ec8a2d03
      Eric Blake 提交于
      No need to use HAVE_REGEX_H - our use of gnulib guarantees that
      the header exists and works, regardless of platform.  Similarly,
      we can unconditionally assume a compiling <sys/wait.h> (although
      the mingw version of this header is not full-featured).
      
      * src/storage/storage_backend.c: Drop useless conditional.
      * tests/testutils.c: Likewise.
      ec8a2d03
  2. 14 2月, 2013 15 次提交
    • J
      2e5d7798
    • L
      util: maintain caps when running command with uid != 0 · 7a2e845a
      Laine Stump 提交于
      virCommand was previously calling virSetUIDGID() to change the uid and
      gid of the child process, then separately calling
      virSetCapabilities(). This did not work if the desired uid was != 0,
      since a setuid to anything other than 0 normally clears all
      capabilities bits.
      
      The solution is to use the new virSetUIDGIDWithCaps(), sending it the
      uid, gid, and capabilities bits. This will get the new process setup
      properly.
      
      Since the static functions virSetCapabilities() and
      virClearCapabilities are no longer called, they have been removed.
      
      NOTE: When combined with "filecap $path-to-qemu sys_rawio", this patch
      will make CAP_SYS_RAWIO (which is required for passthrough of generic
      scsi commands to a guest - see commits e8daeeb1, 177db087, 397e6a70, and
      74e03496) be retained by qemu when necessary. Apparently that
      capability has been broken for non-root qemu ever since it was
      originally added.
      7a2e845a
    • L
      util: virSetUIDGIDWithCaps - change uid while keeping caps · e11451f4
      Laine Stump 提交于
      Normally when a process' uid is changed to non-0, all the capabilities
      bits are cleared, even those explicitly set with calls to
      capng_update()/capng_apply() made immediately before setuid. And
      *after* the process' uid has been changed, it no longer has the
      necessary privileges to add capabilities back to the process.
      
      In order to set a non-0 uid while still maintaining any capabilities
      bits, it is necessary to either call capng_change_id() (which
      unfortunately doesn't currently call initgroups to setup auxiliary
      group membership), or to perform the small amount of calisthenics
      contained in the new utility function virSetUIDGIDWithCaps().
      
      Another very important difference between the capabilities
      setting/clearing in virSetUIDGIDWithCaps() and virCommand's
      virSetCapabilities() (which it will replace in the next patch) is that
      the new function properly clears the capabilities bounding set, so it
      will not be possible for a child process to set any new
      capabilities.
      
      A short description of what is done by virSetUIDGIDWithCaps():
      
      1) clear all capabilities then set all those desired by the caller (in
      capBits) plus CAP_SETGID, CAP_SETUID, and CAP_SETPCAP (which is needed
      to change the capabilities bounding set).
      
      2) call prctl(), telling it that we want to maintain current
      capabilities across an upcoming setuid().
      
      3) switch to the new uid/gid
      
      4) again call prctl(), telling it we will no longer want capabilities
      maintained if this process does another setuid().
      
      5) clear the capabilities that we added to allow us to
      setuid/setgid/change the bounding set (unless they were also requested
      by the caller via the virCommand API).
      
      Because the modification/maintaining of capabilities is intermingled
      with setting the uid, this is necessarily done in a single function,
      rather than having two independent functions.
      
      Note that, due to the way that effective capabilities are computed (at
      time of execve) for a process that has uid != 0, the *file*
      capabilities of the binary being executed must also have the desired
      capabilities bit(s) set (see "man 7 capabilities"). This can be done
      with the "filecap" command. (e.g. "filecap /usr/bin/qemu-kvm sys_rawio").
      e11451f4
    • L
      util: drop capabilities immediately after changing uid/gid of child · c0e3e685
      Laine Stump 提交于
      This is an interim measure to make sure everything still works in this
      order. The next step will be to perform capabilities drop and
      setuid/gid as a single operation (which is the only way to keep any
      capabilities when switching to a non-root uid).
      c0e3e685
    • L
      qemu: let virCommand set child process security labels/uid/gid · 0345c728
      Laine Stump 提交于
      The qemu driver had been calling virSecurityManagerSetProcessLabel()
      from a "pre-exec hook" function that is run after the child is forked,
      but before exec'ing qemu. This is problematic because the uid and gid
      of the child are set by the security driver, but capabilities are
      dropped by virCommand - such separation doesn't work; the two
      operations must be done together or the capabilities do not transfer
      properly to the child process.
      
      This patch switches to using virSecurityManagerSetChildProcessLabel(),
      which is called prior to virCommandRun() (rather than being called
      *during* virCommandrun() by the hook function), and doesn't set the
      UID/GID/security label directly, but instead merely informs virCommand
      what it should set them all to when the time is appropriate.
      
      This lets virCommand choose to do the uid/gid and caps dropping all at
      the same time if it wants (it does *want* to, but isn't doing so yet;
      that's for an upcoming patch).
      0345c728
    • L
      security: add new virSecurityManagerSetChildProcessLabel API · 7bf1aa0b
      Laine Stump 提交于
      The existing virSecurityManagerSetProcessLabel() API is designed so
      that it must be called after forking the child process, but before
      exec'ing the child. Due to the way the virCommand API works, that
      means it needs to be put in a "hook" function that virCommand is told
      to call out to at that time.
      
      Setting the child process label is a basic enough need when executing
      any process that virCommand should have a method of doing that. But
      virCommand must be told what label to set, and only the security
      driver knows the answer to that question.
      
      The new virSecurityManagerSet*Child*ProcessLabel() API is the way to
      transfer the knowledge about what label to set from the security
      driver to the virCommand object. It is given a virCommandPtr, and each
      security driver calls the appropriate virCommand* API to tell
      virCommand what to do between fork and exec.
      
      1) in the case of the DAC security driver, it calls
      virCommandSetUID/GID() to set a uid and gid that must be set for the
      child process.
      
      2) for the SELinux security driver, it calls
      virCommandSetSELinuxLabel() to save a copy of the char* that will be
      sent to setexeccon_raw() *after forking the child process*.
      
      3) for the AppArmor security drivers, it calls
      virCommandSetAppArmorProfile() to save a copy of the char* that will
      be sent to aa_change_profile() *after forking the child process*.
      
      With this new API in place, we will be able to remove
      virSecurityManagerSetProcessLabel() from any virCommand pre-exec
      hooks.
      
      (Unfortunately, the LXC driver uses clone() rather than virCommand, so
      it can't take advantage of this new security driver API, meaning that
      we need to keep around the older virSecurityManagerSetProcessLabel(),
      at least for now.)
      7bf1aa0b
    • L
      util: add security label setting to virCommand · 6c3f3d0d
      Laine Stump 提交于
      virCommand gets two new APIs: virCommandSetSELinuxLabel() and
      virCommandSetAppArmorProfile(), which both save a copy of a
      null-terminated string in the virCommand. During virCommandRun, if the
      string is non-NULL and we've been compiled with AppArmor and/or
      SELinux security driver support, the appropriate security library
      function is called for the child process, using the string that was
      previously set. In the case of SELinux, setexeccon_raw() is called,
      and for AppArmor, aa_change_profile() is called.
      
      This functionality has been added so that users of virCommand can use
      the upcoming virSecurityManagerSetChildProcessLabel() prior to running
      a child process, rather than needing to setup a hook function to be
      called (and in turn call virSecurityManagerSetProcessLabel()) *during*
      the setup of the child process.
      6c3f3d0d
    • L
      build: define SECDRIVER_LIBS in Makefile.am · 4a56e80f
      Laine Stump 提交于
      This makes it simpler to include the necessary system security driver
      libraries for a particular system. For this patch, several existing
      conditional sections from the Makfile were replaced; I'll later be
      adding SECDRIVER_LIBS to libvirt_util_la_LIBADD, because vircommand.c
      will be calling a function from $securitylib.
      4a56e80f
    • L
    • L
      qemu: replace exec hook with virCommandSetUID/GID in qemuCaps* · 6a8ecc37
      Laine Stump 提交于
      Setting the uid/gid of the child process was the only thing done by
      the hook function in this case, and that can now be done more simply
      with virCommandSetUID/GID.
      6a8ecc37
    • L
      util: make virSetUIDGID a NOP only when uid or gid is -1 · f506a4c1
      Laine Stump 提交于
      Rather than treating uid:gid of 0:0 as a NOP, we blindly pass that
      through to the lower layers. However, we *do* check for a requested
      value of "-1" to mean "don't change this setting". setregid() and
      setreuid() already interpret -1 as a NOP, so this is just an
      optimization, but we are also calling getpwuid_r and initgroups, and
      it's unclear what the former would do with a uid of -1.
      f506a4c1
    • L
      util: add virCommandSetUID and virCommandSetGID · 417182b0
      Laine Stump 提交于
      If a uid and/or gid is specified for a command, it will be set just
      after the user-supplied post-fork "hook" function is called.
      
      The intent is that this can replace user hook functions that set
      uid/gid. This moves the setting of uid/gid and dropping of
      capabilities closer to each other, which is important since the two
      should really be done at the same time (libcapng provides a single
      function that does both, which we will be unable to use, but want to
      mimic as closely as possible).
      417182b0
    • L
    • L
      util: eliminate extra args from virExec · 5f2ce539
      Laine Stump 提交于
      All args except "cmd" in the call to virExec are now redundant, since
      they can all be found in cmd, so remove the args and reference the
      data directly in cmd. One exception to this is that "infd" was being
      modified within virExec, and modifying the original in cmd caused make
      check failures, so cmd->infd is copied to a local, and the local is
      used during virExec().
      5f2ce539
    • L
      util: eliminate generic hook from virExecWithHook · b6decc57
      Laine Stump 提交于
      virExecWithHook is only called from one place, so it always has the
      same "hook" function (virHookCommand), and the data sent to that
      function is always a virCommandPtr, so eliminate the function and
      generic data from the arglist, and replace it with "virCommandPtr
      cmd". The call to (hook)(data) is replaced with
      "virHookCommand(cmd)". Finally, virExecWithHook is renamed to virExec.
      
      Indentation has been updated only for code that will remain after the
      next patch, which will remove all other args to virExec (since they
      are now redundant, as they're all members of virCommandPtr).
      b6decc57
  3. 13 2月, 2013 18 次提交
  4. 12 2月, 2013 5 次提交
    • D
      Release VM lock before acquiring virDomainObjListPtr lock · d1c7b00b
      Daniel P. Berrange 提交于
      When removing a VM from the virDomainObjListPtr, we must not
      be holding the VM lock while acquiring the list lock. Re-order
      code to ensure that we can release the VM lock early.
      d1c7b00b
    • D
      Fix potential deadlock across fork() in QEMU driver · 61b52d2e
      Daniel P. Berrange 提交于
      The hook scripts used by virCommand must be careful wrt
      accessing any mutexes that may have been held by other
      threads in the parent process. With the recent refactoring
      there are 2 potential flaws lurking, which will become real
      deadlock bugs once the global QEMU driver lock is removed.
      
      Remove use of the QEMU driver lock from the hook function
      by passing in the 'virQEMUDriverConfigPtr' instance directly.
      
      Add functions to the virSecurityManager to be invoked before
      and after fork, to ensure the mutex is held by the current
      thread. This allows it to be safely used in the hook script
      in the child process.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      61b52d2e
    • E
      build: fix compilation of selinux on RHEL 5 · 736a87b9
      Eric Blake 提交于
      On RHEL 5, I got:
      
      security/security_selinux.c: In function 'getContext':
      security/security_selinux.c:971: warning: unused parameter 'mgr' [-Wunused-parameter]
      
      * src/security/security_selinux.c (getContext): Mark potentially
      unused parameter.
      736a87b9
    • V
      S390: domain_conf support for CCW · 0bbbd42c
      Viktor Mihajlovski 提交于
      Add necessary handling code for the new s390 CCW address type to
      virDomainDeviceInfo. Further, introduce  memory management, XML
      parsing, output formatting and range validation for the new
      virDomainDeviceCCWAddress type.
      Signed-off-by: NViktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
      0bbbd42c
    • V
      S390: Documentation for CCW address type · 24aa7f8d
      Viktor Mihajlovski 提交于
      The native bus for s390 I/O is called CCW (channel command word).
      As QEMU has added basic support for the CCW bus, i.e. the
      ability to assign CCW devnos (bus addresses) to devices.
      Domains with the new machine type s390-ccw-virtio can use the
      CCW bus. Currently QEMU will only allow to define virtio
      devices on the CCW bus.
      Here we add the new machine type and the new device address to the
      schema definition and add a new paragraph to the domain XML
      documentation.
      Signed-off-by: NViktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
      24aa7f8d