[libvirt] [PATCH 1/2] virt-aa-helper: apparmor wildcards to forbidden chars

Jamie Strandboge jamie at canonical.com
Thu Oct 26 14:12:14 UTC 2017


On Thu, 2017-10-26 at 15:22 +0200, Christian Ehrhardt wrote:
> Some globbing chars in the domain name could be used to break out of
> apparmor rules, so lets forbid these when in virt-aa-helper.
> 
> Also adding a test to ensure all those cases were detected as bad
> char.
> 
> Signed-off-by: Christian Ehrhardt <christian.ehrhardt at canonical.com>
> ---
>  src/security/virt-aa-helper.c |  2 +-
>  tests/virt-aa-helper-test     | 20 ++++++++++++++++++++
>  2 files changed, 21 insertions(+), 1 deletion(-)
> 
> diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-
> helper.c
> index ef1bf01..4f1c195 100644
> --- a/src/security/virt-aa-helper.c
> +++ b/src/security/virt-aa-helper.c
> @@ -449,7 +449,7 @@ valid_name(const char *name)
>  {
>      /* just try to filter out any dangerous characters in the name
> that can be
>       * used to subvert the profile */
> -    const char *bad = "/[]*";
> +    const char *bad = "/[]{}?^,\"*";
>  
>      if (strlen(name) == 0)
>          return -1;
> diff --git a/tests/virt-aa-helper-test b/tests/virt-aa-helper-test
> index 0599046..e837668 100755
> --- a/tests/virt-aa-helper-test
> +++ b/tests/virt-aa-helper-test
> @@ -211,6 +211,26 @@ testme "1" "-c with no os.type" "-c -u
> $valid_uuid" "$test_xml"
>  sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e
> "s,hvm</type>,hvm_invalid</type>,g" "$template_xml" > "$test_xml"
>  testme "1" "-c with invalid hvm" "-c -u $valid_uuid" "$test_xml"
>  
> +sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,virt-
> aa-helper-test,virt-aa-helper-test-/,g" "$template_xml" > "$test_xml"
> +testme "1" "-c with invalid domain name char /" "-c -u $valid_uuid"
> "$test_xml"
> +sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,virt-
> aa-helper-test,virt-aa-helper-test-[,g" "$template_xml" > "$test_xml"
> +testme "1" "-c with invalid domain name char [" "-c -u $valid_uuid"
> "$test_xml"
> +sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,virt-
> aa-helper-test,virt-aa-helper-test-],g" "$template_xml" > "$test_xml"
> +testme "1" "-c with invalid domain name char ]" "-c -u $valid_uuid"
> "$test_xml"
> +sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,virt-
> aa-helper-test,virt-aa-helper-test-{,g" "$template_xml" > "$test_xml"
> +testme "1" "-c with invalid domain name char {" "-c -u $valid_uuid"
> "$test_xml"
> +sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,virt-
> aa-helper-test,virt-aa-helper-test-},g" "$template_xml" > "$test_xml"
> +testme "1" "-c with invalid domain name char }" "-c -u $valid_uuid"
> "$test_xml"
> +sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,virt-
> aa-helper-test,virt-aa-helper-test-?,g" "$template_xml" > "$test_xml"
> +testme "1" "-c with invalid domain name char ?" "-c -u $valid_uuid"
> "$test_xml"
> +sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,virt-
> aa-helper-test,virt-aa-helper-test-^,g" "$template_xml" > "$test_xml"
> +testme "1" "-c with invalid domain name char ^" "-c -u $valid_uuid"
> "$test_xml"
> +sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,virt-
> aa-helper-test,virt-aa-helper-test-\,,g" "$template_xml" >
> "$test_xml"
> +testme "1" "-c with invalid domain name char ," "-c -u $valid_uuid"
> "$test_xml"
> +sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,virt-
> aa-helper-test,virt-aa-helper-test-\",g" "$template_xml" >
> "$test_xml"
> +testme "1" "-c with invalid domain name char \"" "-c -u $valid_uuid"
> "$test_xml"
> +sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,virt-
> aa-helper-test,virt-aa-helper-test-*,g" "$template_xml" > "$test_xml"
> +testme "1" "-c with invalid domain name char *" "-c -u $valid_uuid"
> "$test_xml"
>  
>  echo "Expected pass:" >$output
>  sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g"
> "$template_xml" > "$test_xml"

LGTM, thanks!

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


More information about the libvir-list mailing list