[libvirt] [PATCH v3 1/5] security, apparmor: add (Set|Restore)MemoryLabel

Jamie Strandboge jamie at canonical.com
Wed Mar 21 17:50:35 UTC 2018


On Wed, 2018-03-21 at 15:53 +0100, Christian Ehrhardt wrote:
> Recent changes have made implementing this mandatory to hot add any
> memory.
> Implementing this in apparmor fixes this as well as allows hot-add of
> nvdimm
> tpye memory with an nvdimmPath set generating a AppArmor rule for
> that
> path.
> 
> Example hot adding:
>   <memory model='nvdimm'>
>     <source>
>       <path>/tmp/nvdimm-test</path>
>     </source>
>     <target>
>       <size unit='KiB'>524288</size>
>       <node>0</node>
>     </target>
>   </memory>
> Creates now:
>   "/tmp/nvdimm-test" rwk,
> 
> Fixes: https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1755153
> 
> Signed-off-by: Christian Ehrhardt <christian.ehrhardt at canonical.com>
> ---
>  src/security/security_apparmor.c | 46
> ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
> 
> diff --git a/src/security/security_apparmor.c
> b/src/security/security_apparmor.c
> index a989992..18908c8 100644
> --- a/src/security/security_apparmor.c
> +++ b/src/security/security_apparmor.c
> @@ -718,6 +718,49 @@
> AppArmorRestoreSecurityDiskLabel(virSecurityManagerPtr mgr,
>  
>  /* Called when hotplugging */
>  static int
> +AppArmorSetMemoryLabel(virSecurityManagerPtr mgr,
> +                       virDomainDefPtr def,
> +                       virDomainMemoryDefPtr mem)
> +{
> +    if (mem == NULL)
> +        return 0;
> +
> +    switch ((virDomainMemoryModel) mem->model) {
> +    case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
> +        if (mem->nvdimmPath == NULL) {
> +            virReportError(VIR_ERR_INTERNAL_ERROR,
> +                           _("%s: nvdimm without a path"),
> +                           __func__);
> +            return -1;
> +        }
> +        if (!virFileExists(mem->nvdimmPath)) {
> +            virReportError(VIR_ERR_INTERNAL_ERROR,
> +                           _("%s: \'%s\' does not exist"),
> +                           __func__, mem->nvdimmPath);
> +            return -1;
> +        }
> +        return reload_profile(mgr, def, mem->nvdimmPath, true);
> +        break;
> +    case VIR_DOMAIN_MEMORY_MODEL_NONE:
> +    case VIR_DOMAIN_MEMORY_MODEL_DIMM:
> +    case VIR_DOMAIN_MEMORY_MODEL_LAST:
> +        break;
> +    }
> +
> +    return 0;
> +}
> +
> +
> +static int
> +AppArmorRestoreMemoryLabel(virSecurityManagerPtr mgr,
> +                           virDomainDefPtr def,
> +                           virDomainMemoryDefPtr mem
> ATTRIBUTE_UNUSED)
> +{
> +    return reload_profile(mgr, def, NULL, false);
> +}
> +
> +/* Called when hotplugging */
> +static int
>  AppArmorSetSecurityImageLabel(virSecurityManagerPtr mgr,
>                                virDomainDefPtr def,
>                                virStorageSourcePtr src)
> @@ -1115,6 +1158,9 @@ virSecurityDriver virAppArmorSecurityDriver = {
>      .domainSetSecurityImageLabel        =
> AppArmorSetSecurityImageLabel,
>      .domainRestoreSecurityImageLabel    =
> AppArmorRestoreSecurityImageLabel,
>  
> +    .domainSetSecurityMemoryLabel       = AppArmorSetMemoryLabel,
> +    .domainRestoreSecurityMemoryLabel   =
> AppArmorRestoreMemoryLabel,
> +
>      .domainSetSecurityDaemonSocketLabel =
> AppArmorSetSecurityDaemonSocketLabel,
>      .domainSetSecuritySocketLabel       =
> AppArmorSetSecuritySocketLabel,
>      .domainClearSecuritySocketLabel     =
> AppArmorClearSecuritySocketLabel,

+1 to apply. Thanks!

-- 
Jamie Strandboge             | http://www.canonical.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20180321/7e533841/attachment-0001.sig>


More information about the libvir-list mailing list