1. 25 3月, 2014 3 次提交
    • J
      9e7ecabf
    • E
      conf: prepare to track multiple host source files per <disk> · 4f202266
      Eric Blake 提交于
      It's finally time to start tracking disk backing chains in
      <domain> XML.  The first step is to start refactoring code
      so that we have an object more convenient for representing
      each host source resource in the context of a single guest
      <disk>.  Ultimately, I plan to move the new type into src/util
      where it can be reused by virStorageFile, but to make the
      transition easier to review, this patch just creates the
      new type then fixes everything until it compiles again.
      
      * src/conf/domain_conf.h (_virDomainDiskDef): Split...
      (_virDomainDiskSourceDef): ...to new struct.
      (virDomainDiskAuthClear): Use new type.
      * src/conf/domain_conf.c (virDomainDiskDefFree): Split...
      (virDomainDiskSourceDefClear): ...to new function.
      (virDomainDiskGetType, virDomainDiskSetType)
      (virDomainDiskGetSource, virDomainDiskSetSource)
      (virDomainDiskGetDriver, virDomainDiskSetDriver)
      (virDomainDiskGetFormat, virDomainDiskSetFormat)
      (virDomainDiskAuthClear, virDomainDiskGetActualType)
      (virDomainDiskDefParseXML, virDomainDiskSourceDefFormat)
      (virDomainDiskDefFormat, virDomainDiskDefForeachPath)
      (virDomainDiskDefGetSecurityLabelDef)
      (virDomainDiskSourceIsBlockType): Adjust all users.
      * src/lxc/lxc_controller.c (virLXCControllerSetupDisk):
      Likewise.
      * src/lxc/lxc_driver.c (lxcDomainAttachDeviceMknodHelper):
      Likewise.
      * src/qemu/qemu_command.c (qemuAddRBDHost, qemuParseRBDString)
      (qemuParseDriveURIString, qemuParseGlusterString)
      (qemuParseISCSIString, qemuParseNBDString)
      (qemuDomainDiskGetSourceString, qemuBuildDriveStr)
      (qemuBuildCommandLine, qemuParseCommandLineDisk)
      (qemuParseCommandLine): Likewise.
      * src/qemu/qemu_conf.c (qemuCheckSharedDevice)
      (qemuAddISCSIPoolSourceHost, qemuTranslateDiskSourcePool):
      Likewise.
      * src/qemu/qemu_driver.c (qemuDomainUpdateDeviceConfig)
      (qemuDomainPrepareDiskChainElement)
      (qemuDomainSnapshotCreateInactiveExternal)
      (qemuDomainSnapshotPrepareDiskExternalBackingInactive)
      (qemuDomainSnapshotPrepareDiskInternal)
      (qemuDomainSnapshotPrepare)
      (qemuDomainSnapshotCreateSingleDiskActive)
      (qemuDomainSnapshotUndoSingleDiskActive)
      (qemuDomainBlockPivot, qemuDomainBlockJobImpl)
      (qemuDomainBlockCopy, qemuDomainBlockCommit): Likewise.
      * src/qemu/qemu_migration.c (qemuMigrationIsSafe): Likewise.
      * src/qemu/qemu_process.c (qemuProcessGetVolumeQcowPassphrase)
      (qemuProcessInitPasswords): Likewise.
      * src/security/security_selinux.c
      (virSecuritySELinuxSetSecurityFileLabel): Likewise.
      * src/storage/storage_driver.c (virStorageFileInitFromDiskDef):
      Likewise.
      * tests/securityselinuxlabeltest.c (testSELinuxLoadDef):
      Likewise.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      4f202266
    • E
      conf: use disk source accessors in security/ · 2aad0ebe
      Eric Blake 提交于
      Part of a series of cleanups to use new accessor methods.
      
      * src/security/security_dac.c (virSecurityDACSetSecurityImageLabel)
      (virSecurityDACRestoreSecurityImageLabelInt)
      (virSecurityDACSetSecurityAllLabel): Use accessors.
      * src/security/security_selinux.c
      (virSecuritySELinuxRestoreSecurityImageLabelInt)
      (virSecuritySELinuxSetSecurityImageLabel)
      (virSecuritySELinuxSetSecurityAllLabel): Likewise.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      2aad0ebe
  2. 20 3月, 2014 1 次提交
    • S
      is_selinux_enabled() returns -1 on error, account for this. · 0099a4ae
      Scott Sullivan 提交于
      Per the documentation, is_selinux_enabled() returns -1 on error.
      Account for this. Previously when -1 was being returned the condition
      would still be true. I was noticing this because on my system that has
      selinux disabled I was getting this in the libvirt.log every 5
      seconds:
      
      error : virIdentityGetSystem:173 : Unable to lookup SELinux process context: Invalid argument
      
      With this patch applied, I no longer get these messages every 5
      seconds. I am submitting this in case its deemed useful for inclusion.
      Anyone have any comments on this change? This is a patch off current
      master.
      Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
      0099a4ae
  3. 18 3月, 2014 1 次提交
  4. 06 2月, 2014 1 次提交
    • J
      Generate a valid imagelabel even for type 'none' · 0db9b088
      Ján Tomko 提交于
      Commit 2ce63c16 added imagelabel generation when relabeling is turned
      off. But we weren't filling out the sensitivity for type 'none' labels,
      resulting in an invalid label:
      
      $ virsh managedsave domain
      error: unable to set security context 'system_u:object_r:svirt_image_t'
      on fd 28: Invalid argument
      0db9b088
  5. 30 1月, 2014 1 次提交
    • O
      util: Add one argument for several scsi utils · 10c9ceff
      Osier Yang 提交于
      To support passing the path of the test data to the utils, one
      more argument is added to virSCSIDeviceGetSgName,
      virSCSIDeviceGetDevName, and virSCSIDeviceNew, and the related
      code is changed accordingly.
      
      Later tests for the scsi utils will be based on this patch.
      Signed-off-by: NOsier Yang <jyang@redhat.com>
      10c9ceff
  6. 23 1月, 2014 1 次提交
    • O
      util: Add "shareable" field for virSCSIDevice struct · 2b66504d
      Osier Yang 提交于
      Unlike the host devices of other types, SCSI host device XML supports
      "shareable" tag. This patch introduces it for the virSCSIDevice struct
      for a later patch use (to detect if the SCSI device is shareable when
      preparing the SCSI host device in QEMU driver).
      2b66504d
  7. 17 1月, 2014 1 次提交
    • M
      virSecuritySELinuxSetFileconHelper: Don't fail on read-only NFS · d1fdecb6
      Michal Privoznik 提交于
      https://bugzilla.redhat.com/show_bug.cgi?id=996543
      
      When starting up a domain, the SELinux labeling is done depending on
      current configuration. If the labeling fails we check for possible
      causes, as not all labeling failures are fatal. For example, if the
      labeled file is on NFS which lacks SELinux support, the file can still
      be readable to qemu process. These cases are distinguished by the errno
      code: NFS without SELinux support returns EOPNOTSUPP. However, we were
      missing one scenario. In case there's a read-only disk on a read-only
      NFS (and possibly any FS) and the labeling is just optional (not
      explicitly requested in the XML) there's no need to make the labeling
      error fatal. In other words, read-only file on read-only NFS can fail to
      be labeled, but be readable at the same time.
      Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
      d1fdecb6
  8. 04 12月, 2013 1 次提交
  9. 20 11月, 2013 1 次提交
    • D
      Fix off-by-1 in default SELinux MCS range · 2b510e49
      Daniel P. Berrange 提交于
      For a while we're have random failures of 'securityselinuxtest'
      which were not at all reproducible. Fortunately we finally
      caught a failure with VIR_TEST_DEBUG=1 enabled. This revealed
      
      TEST: securityselinuxtest
       1) GenLabel "dynamic unconfined, s0, c0.c1023"                       ... OK
       2) GenLabel "dynamic unconfined, s0, c0.c1023"                       ... OK
       3) GenLabel "dynamic unconfined, s0, c0.c1023"                       ... OK
       4) GenLabel "dynamic virtd, s0, c0.c1023"                            ... OK
       5) GenLabel "dynamic virtd, s0, c0.c10"                              ... OK
       6) GenLabel "dynamic virtd, s2-s3, c0.c1023"                         ... OK
       7) GenLabel "dynamic virtd, missing range"                           ... Category two 1024 is out of range 0-1023
      FAILED
      FAIL: securityselinuxtest
      
      And sure enough we had an off-by-1 in the MCS range code when
      the current process has no range set. The test suite randomly
      allocates 2 categories from 0->1024 so the chances of hitting
      this in the test suite were slim indeed :-)
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      2b510e49
  10. 29 10月, 2013 1 次提交
  11. 15 10月, 2013 1 次提交
    • E
      maint: avoid 'const fooPtr' in security · 84e80917
      Eric Blake 提交于
      'const fooPtr' is the same as 'foo * const' (the pointer won't
      change, but it's contents can).  But in general, if an interface
      is trying to be const-correct, it should be using 'const foo *'
      (the pointer is to data that can't be changed).
      
      Fix up offenders in src/security.
      
      * src/security/security_apparmor.c (reload_profile)
      (AppArmorSetSecurityHostdevLabelHelper)
      (AppArmorReleaseSecurityLabel, AppArmorRestoreSecurityAllLabel)
      (AppArmorSetSecurityProcessLabel)
      (AppArmorSetSecurityChildProcessLabel)
      (AppArmorSetSecurityImageLabel, AppArmorSecurityVerify)
      (AppArmorSetSecurityHostdevLabel)
      (AppArmorRestoreSecurityHostdevLabel, AppArmorSetFDLabel): Drop
      needless const.
      * src/security/security_selinux.c
      (virSecuritySELinuxSetSecurityFileLabel): Likewise.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      84e80917
  12. 01 10月, 2013 1 次提交
  13. 21 8月, 2013 1 次提交
    • E
      selinux: distinguish failure to label from request to avoid label · 0f082e69
      Eric Blake 提交于
      https://bugzilla.redhat.com/show_bug.cgi?id=924153
      
      Commit 904e05a2 (v0.9.9) added a per-<disk> seclabel element with
      an attribute relabel='no' in order to try and minimize the
      impact of shutdown delays when an NFS server disappears.  The idea
      was that if a disk is on NFS and can't be labeled in the first
      place, there is no need to attempt the (no-op) relabel on domain
      shutdown.  Unfortunately, the way this was implemented was by
      modifying the domain XML so that the optimization would survive
      libvirtd restart, but in a way that is indistinguishable from an
      explicit user setting.  Furthermore, once the setting is turned
      on, libvirt avoids attempts at labeling, even for operations like
      snapshot or blockcopy where the chain is being extended or pivoted
      onto non-NFS, where SELinux labeling is once again possible.  As
      a result, it was impossible to do a blockcopy to pivot from an
      NFS image file onto a local file.
      
      The solution is to separate the semantics of a chain that must
      not be labeled (which the user can set even on persistent domains)
      vs. the optimization of not attempting a relabel on cleanup (a
      live-only annotation), and using only the user's explicit notation
      rather than the optimization as the decision on whether to skip
      a label attempt in the first place.  When upgrading an older
      libvirtd to a newer, an NFS volume will still attempt the relabel;
      but as the avoidance of a relabel was only an optimization, this
      shouldn't cause any problems.
      
      In the ideal future, libvirt will eventually have XML describing
      EVERY file in the backing chain, with each file having a separate
      <seclabel> element.  At that point, libvirt will be able to track
      more closely which files need a relabel attempt at shutdown.  But
      until we reach that point, the single <seclabel> for the entire
      <disk> chain is treated as a hint - when a chain has only one
      file, then we know it is accurate; but if the chain has more than
      one file, we have to attempt relabel in spite of the attribute,
      in case part of the chain is local and SELinux mattered for that
      portion of the chain.
      
      * src/conf/domain_conf.h (_virSecurityDeviceLabelDef): Add new
      member.
      * src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML):
      Parse it, for live images only.
      (virSecurityDeviceLabelDefFormat): Output it.
      (virDomainDiskDefParseXML, virDomainChrSourceDefParseXML)
      (virDomainDiskSourceDefFormat, virDomainChrDefFormat)
      (virDomainDiskDefFormat): Pass flags on through.
      * src/security/security_selinux.c
      (virSecuritySELinuxRestoreSecurityImageLabelInt): Honor labelskip
      when possible.
      (virSecuritySELinuxSetSecurityFileLabel): Set labelskip, not
      norelabel, if labeling fails.
      (virSecuritySELinuxSetFileconHelper): Fix indentation.
      * docs/formatdomain.html.in (seclabel): Document new xml.
      * docs/schemas/domaincommon.rng (devSeclabel): Allow it in RNG.
      * tests/qemuxml2argvdata/qemuxml2argv-seclabel-*-labelskip.xml:
      * tests/qemuxml2argvdata/qemuxml2argv-seclabel-*-labelskip.args:
      * tests/qemuxml2xmloutdata/qemuxml2xmlout-seclabel-*-labelskip.xml:
      New test files.
      * tests/qemuxml2argvtest.c (mymain): Run the new tests.
      * tests/qemuxml2xmltest.c (mymain): Likewise.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      0f082e69
  14. 11 7月, 2013 1 次提交
  15. 10 7月, 2013 2 次提交
  16. 08 7月, 2013 2 次提交
    • P
      selinux: Always generate imagelabel · 2ce63c16
      Peter Krempa 提交于
      The imagelabel SELinux label was only generated when relabeling was
      enabled. This prohibited labeling of files created by libvirt that need
      to be labeled even if relabeling is turned off.
      
      The only codepath this change has direct impact on is labeling of FDs
      passed to qemu which is always safe in current state.
      2ce63c16
    • P
      selinux: Cleanup coding style · e45ee23c
      Peter Krempa 提交于
      e45ee23c
  17. 26 6月, 2013 1 次提交
  18. 11 6月, 2013 1 次提交
  19. 23 5月, 2013 1 次提交
  20. 21 5月, 2013 1 次提交
  21. 13 5月, 2013 1 次提交
  22. 02 5月, 2013 1 次提交
    • M
      virutil: Move string related functions to virstring.c · 7c9a2d88
      Michal Privoznik 提交于
      The source code base needs to be adapted as well. Some files
      include virutil.h just for the string related functions (here,
      the include is substituted to match the new file), some include
      virutil.h without any need (here, the include is removed), and
      some require both.
      7c9a2d88
  23. 30 4月, 2013 1 次提交
  24. 27 4月, 2013 1 次提交
  25. 26 4月, 2013 2 次提交
    • L
      security: update hostdev labelling functions for VFIO · f0bd70a9
      Laine Stump 提交于
      Legacy kvm style pci device assignment requires changes to the
      labelling of several sysfs files for each device, but for vfio device
      assignment, the only thing that needs to be relabelled/chowned is the
      "group" device for the group that contains the device to be assigned.
      f0bd70a9
    • L
      conf: put hostdev pci address in a struct · 9f80fc1b
      Laine Stump 提交于
      There will soon be other items related to pci hostdevs that need to be
      in the same part of the hostdevsubsys union as the pci address (which
      is currently a single member called "pci". This patch replaces the
      single member named pci with a struct named pci that contains a single
      member named "addr".
      9f80fc1b
  26. 24 4月, 2013 1 次提交
  27. 17 4月, 2013 1 次提交
    • O
      cleanup: Remove the duplicate header · bc95be5d
      Osier Yang 提交于
      Detected by a simple Shell script:
      
      for i in $(git ls-files -- '*.[ch]'); do
          awk 'BEGIN {
              fail=0
          }
          /# *include.*\.h/{
              match($0, /["<][^">]*[">]/)
              arr[substr($0, RSTART+1, RLENGTH-2)]++
          }
          END {
              for (key in arr) {
                  if (arr[key] > 1) {
                      fail=1
                      printf("%d %s\n", arr[key], key)
                  }
              }
              if (fail == 1)
                  exit 1
          }' $i
      
          if test $? != 0; then
              echo "Duplicate header(s) in $i"
          fi
      done;
      
      A later patch will add the syntax-check to avoid duplicate
      headers.
      bc95be5d
  28. 13 4月, 2013 1 次提交
  29. 28 3月, 2013 1 次提交
  30. 20 3月, 2013 1 次提交
  31. 14 3月, 2013 3 次提交
    • D
      Fix parsing of SELinux ranges without a category · 1732c1c6
      Daniel P. Berrange 提交于
      Normally libvirtd should run with a SELinux label
      
        system_u:system_r:virtd_t:s0-s0:c0.c1023
      
      If a user manually runs libvirtd though, it is sometimes
      possible to get into a situation where it is running
      
        system_u:system_r:init_t:s0
      
      The SELinux security driver isn't expecting this and can't
      parse the security label since it lacks the ':c0.c1023' part
      causing it to complain
      
        internal error Cannot parse sensitivity level in s0
      
      This updates the parser to cope with this, so if no category
      is present, libvirtd will hardcode the equivalent of c0.c1023.
      
      Now this won't work if SELinux is in Enforcing mode, but that's
      not an issue, because the user can only get into this problem
      if in Permissive mode. This means they can now start VMs in
      Permissive mode without hitting that parsing error
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      1732c1c6
    • D
      Separate MCS range parsing from MCS range checking · 4a92fe44
      Daniel P. Berrange 提交于
      Pull the code which parses the current process MCS range
      out of virSecuritySELinuxMCSFind and into a new method
      virSecuritySELinuxMCSGetProcessRange.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      4a92fe44
    • D
      Fix memory leak on OOM in virSecuritySELinuxMCSFind · f2d8190c
      Daniel P. Berrange 提交于
      The body of the loop in virSecuritySELinuxMCSFind would
      directly 'return NULL' on OOM, instead of jumping to the
      cleanup label. This caused a leak of several local vars.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      f2d8190c
  32. 16 2月, 2013 1 次提交
    • J
      security: Remove unnecessary checks for mgr == NULL · 676688b6
      John Ferlan 提交于
      Coverity found the DACGenLabel was checking for mgr == NULL after a
      possible dereference; however, in order to get into the function the
      virSecurityManagerGenLabel would have already dereferenced sec_managers[i]
      so the check was unnecessary. Same check is made in SELinuxGenSecurityLabel.
      676688b6
  33. 14 2月, 2013 1 次提交
    • 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