From nobody Fri Apr 26 19:42:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=canonical.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 163362977631334.60017077425664; Thu, 7 Oct 2021 11:02:56 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-391-g-CTBFTCMQuXyCHxxIEMbg-1; Thu, 07 Oct 2021 14:02:53 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 82ACC882B58; Thu, 7 Oct 2021 18:02:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0C7E61E6E6F; Thu, 7 Oct 2021 18:02:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 19F981800B8B; Thu, 7 Oct 2021 18:02:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 197HWhn0020073 for ; Thu, 7 Oct 2021 13:32:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2D0CB2156713; Thu, 7 Oct 2021 17:32:43 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 27CEC215670D for ; Thu, 7 Oct 2021 17:32:43 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0E116106655B for ; Thu, 7 Oct 2021 17:32:43 +0000 (UTC) Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-435-pWMk1KKbNJa0xIzikWpVww-1; Thu, 07 Oct 2021 13:32:41 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 9520940010 for ; Thu, 7 Oct 2021 17:25:43 +0000 (UTC) Received: by mail-wr1-f70.google.com with SMTP id j19-20020adfb313000000b00160a9de13b3so5262820wrd.8 for ; Thu, 07 Oct 2021 10:25:43 -0700 (PDT) Received: from localhost (o5wzrf.static.otenet.gr. [2.84.75.34]) by smtp.gmail.com with ESMTPSA id c185sm29865wma.8.2021.10.07.10.25.42 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Oct 2021 10:25:42 -0700 (PDT) X-MC-Unique: g-CTBFTCMQuXyCHxxIEMbg-1 X-MC-Unique: pWMk1KKbNJa0xIzikWpVww-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=43QRFkt6LULEvwm04r3+vYFdu+53nCR3UMwl6bVwwIE=; b=shLlaYxH8TD+F4ptphUKquL8XNsIe3w/o9LVwTqA0QKIDr8MwOI1Qv7ErwMi7fDYJ9 2SOfQEvoRnHU0+uxtC+uyY5+TDmYIvrooMgmIBdwKG/Tu4hcvZXgQjqxIPIAWXqOzGcF q04mo9wAZl3rODk8Cp1tFSBbLVQPRIhpgRNBdjyd8KXVCO4VSANacIyrhxCb0hrih+be OgO2/2hrmlWxMSju5E1rbv9cHxn9OMC4O0cF6prYDenVIuU5xpeewzjuEYtEjfGcCs4d agWTjx37K6MzgTaYxUPglv/NsNmmNRvpG4JnKGlAobc+81oZynS/sTG93uTGumugy059 JQKQ== X-Gm-Message-State: AOAM533nRyiUKs1D+dMt8FPiXqWWVncifnWP7hrMFofEkyUvweRONnBi spWI3BFVoNCE+XABOZGxZvDIKmfPzKnh/Foh13iHEZ7DZgGDmUkoVJDX737Kf/BssL0wDgiaea0 +/QdJa+GZvMfoYUKkg0tQOk6g13NoIH4ydg== X-Received: by 2002:a1c:19c6:: with SMTP id 189mr17672194wmz.121.1633627542895; Thu, 07 Oct 2021 10:25:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyU61wlixs0eOG1O5Ab1iV2f89+taV2cFrPePPhGzOiUjEkUTqZ7Xa8a+3PNc532WFj70yqyQ== X-Received: by 2002:a1c:19c6:: with SMTP id 189mr17672177wmz.121.1633627542692; Thu, 07 Oct 2021 10:25:42 -0700 (PDT) From: Ioanna Alifieraki To: libvir-list@redhat.com, christian.ehrhardt@canonical.com, alejandro.santoyo@canonical.com Subject: [PATCH 1/4] virt-aa-helper: Move create and remove profile into separate functions Date: Thu, 7 Oct 2021 20:25:35 +0300 Message-Id: <20211007172539.25224-2-ioanna-maria.alifieraki@canonical.com> In-Reply-To: <20211007172539.25224-1-ioanna-maria.alifieraki@canonical.com> References: <20211007172539.25224-1-ioanna-maria.alifieraki@canonical.com> X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 2 X-Mimecast-Originator: redhat.com X-ZM-MESSAGEID: 1633629777082100002 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Reorganise create and remove functionality into functions for later reuse in calls from multiple places. Signed-off-by: Ioanna Alifieraki --- src/security/virt-aa-helper.c | 55 ++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 77b2307594..269c372704 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -262,7 +262,7 @@ update_include_file(const char *include_file, const cha= r *included_files, * Create a profile based on a template */ static int -create_profile(const char *profile, const char *profile_name, +_create_profile(const char *profile, const char *profile_name, const char *profile_files, int virtType) { g_autofree char *template =3D NULL; @@ -1437,6 +1437,36 @@ vahParseArgv(vahControl * ctl, int argc, char **argv) return 0; } =20 +static int create_profile(vahControl *ctl, char *profile, char *include_fi= le) +{ + + int rc =3D 0; + char *tmp =3D g_strdup_printf(" #include \n", c= tl->uuid); + if (ctl->dryrun) { + vah_info(profile); + vah_info(ctl->uuid); + vah_info(tmp); + } else if ((rc =3D _create_profile(profile, ctl->uuid, tmp, + ctl->def->virtType)) !=3D 0) { + unlink(include_file); + rc =3D -1; + } + VIR_FREE(tmp); + + return rc; +} + +static int remove_profile(vahControl *ctl, char *include_file) +{ + int rc =3D 0; + + if ((rc =3D parserRemove(ctl->uuid)) !=3D 0) + return rc; + if (ctl->cmd =3D=3D 'D') + unlink(include_file); + + return rc; +} =20 /* * virt-aa-helper -c -u UUID < file.xml @@ -1489,9 +1519,7 @@ main(int argc, char **argv) if (ctl->cmd =3D=3D 'a') { rc =3D parserLoad(ctl->uuid); } else if (ctl->cmd =3D=3D 'R' || ctl->cmd =3D=3D 'D') { - rc =3D parserRemove(ctl->uuid); - if (ctl->cmd =3D=3D 'D') - unlink(include_file); + rc =3D remove_profile(ctl, include_file); } else if (ctl->cmd =3D=3D 'c' || ctl->cmd =3D=3D 'r') { char *included_files =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; @@ -1538,22 +1566,9 @@ main(int argc, char **argv) =20 =20 /* create the profile from TEMPLATE */ - if (ctl->cmd =3D=3D 'c') { - char *tmp =3D NULL; - tmp =3D g_strdup_printf(" #include \n", ctl= ->uuid); - - if (ctl->dryrun) { - vah_info(profile); - vah_info(ctl->uuid); - vah_info(tmp); - rc =3D 0; - } else if ((rc =3D create_profile(profile, ctl->uuid, tmp, - ctl->def->virtType)) !=3D 0) { - vah_error(ctl, 0, _("could not create profile")); - unlink(include_file); - } - VIR_FREE(tmp); - } + if (ctl->cmd =3D=3D 'c') + if ((rc =3D create_profile(ctl, profile, include_file)) != =3D 0) + vah_error(ctl, 0, _("could not create profile")); =20 if (rc =3D=3D 0 && !ctl->dryrun) { if (ctl->cmd =3D=3D 'c') --=20 2.17.1 From nobody Fri Apr 26 19:42:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=canonical.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1633629785034417.42652287340957; Thu, 7 Oct 2021 11:03:05 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-384-_XAAMZ4QOqi_8jm18CDLOw-1; Thu, 07 Oct 2021 14:03:01 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7AEF3802B40; Thu, 7 Oct 2021 18:02:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5B278610A7; Thu, 7 Oct 2021 18:02:56 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 297F157DC5; Thu, 7 Oct 2021 18:02:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 197HWvj0020114 for ; Thu, 7 Oct 2021 13:32:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id 596212026D48; Thu, 7 Oct 2021 17:32:57 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 54AA32026D46 for ; Thu, 7 Oct 2021 17:32:57 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3C0B1185A794 for ; Thu, 7 Oct 2021 17:32:57 +0000 (UTC) Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-473-9Ve7XMzbP1akBmsHl2E6tQ-1; Thu, 07 Oct 2021 13:32:55 -0400 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 45C743FFE3 for ; Thu, 7 Oct 2021 17:25:45 +0000 (UTC) Received: by mail-wr1-f72.google.com with SMTP id e12-20020a056000178c00b001606927de88so5254831wrg.10 for ; Thu, 07 Oct 2021 10:25:45 -0700 (PDT) Received: from localhost (o5wzrf.static.otenet.gr. [2.84.75.34]) by smtp.gmail.com with ESMTPSA id 73sm5531wmb.40.2021.10.07.10.25.43 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Oct 2021 10:25:43 -0700 (PDT) X-MC-Unique: _XAAMZ4QOqi_8jm18CDLOw-1 X-MC-Unique: 9Ve7XMzbP1akBmsHl2E6tQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=vzRHX0Plw46XkI7LCaO3XOG4F4NnBfh75dq1rsotobk=; b=G0uXzWL3WEExOxF9wFto6QUaVOh5gpy4UNEqTIP7L7ZewoNnAQKnP/MB/2TzSWJr7v JECdtROnZTy4soW2juSI/hPtsRZjF3dz7fc9xwFENGaRXKIPmPh4SjihLGw4/0E/Qo+E 8Xg64cD6svPlhtFby66Wulh9YrYjHWyE9dom20VnmGwSAaJMzBwuJYOiw32wLBIgqPg0 5J6G48cpbdVDd/3kqiWo07r4GTRumiEwN+1s9wjSyQAdd4gZEIdLqH+suH0s/6+uQReI haM5ZaTXq1XqhMeVrDGcn4E0zWjag1qS++7ooB69d/jVnHdEdFBB7VvE5vgoNjFK9cdd MLdw== X-Gm-Message-State: AOAM533pd6H4YwVAKi4s9UJNwmV3pS8YNopJiT+Cf23E2C3C6Oxg0QtZ pB5C2SFtWIY0eIye/u/+IUQfinODYhl5F2OziOUm8yQ2lkfzqAMhMhl3sNQZV5Pl4zSH0HoZfvH nitoBSEXuDuiH3VVSa2Xm48j/FQZGE+OYxQ== X-Received: by 2002:a7b:c841:: with SMTP id c1mr3876985wml.40.1633627544545; Thu, 07 Oct 2021 10:25:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyT8dHBqXmOFpnZz38ifx0+drID0Oc/yMzXRnxc5Xkib96+cVh5PZiM2fPDWMMhOVO0/tQu/g== X-Received: by 2002:a7b:c841:: with SMTP id c1mr3876960wml.40.1633627544296; Thu, 07 Oct 2021 10:25:44 -0700 (PDT) From: Ioanna Alifieraki To: libvir-list@redhat.com, christian.ehrhardt@canonical.com, alejandro.santoyo@canonical.com Subject: [PATCH 2/4] virt-aa-helper: Add new purge (-P) option Date: Thu, 7 Oct 2021 20:25:36 +0300 Message-Id: <20211007172539.25224-3-ioanna-maria.alifieraki@canonical.com> In-Reply-To: <20211007172539.25224-1-ioanna-maria.alifieraki@canonical.com> References: <20211007172539.25224-1-ioanna-maria.alifieraki@canonical.com> X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 2 X-Mimecast-Originator: redhat.com X-ZM-MESSAGEID: 1633629785514100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently there is no way to remove the profile file. This commit provides this functionality (required for next commit). Signed-off-by: Ioanna Alifieraki --- src/security/virt-aa-helper.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 269c372704..5ec0fb8807 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -101,6 +101,7 @@ vah_usage(void) " -a | --add load profile\n" " -c | --create create profile from templa= te\n" " -D | --delete unload profile and delete = generated rules\n" + " -P | --purge purge profile\n" " -r | --replace reload profile\n" " -R | --remove unload profile\n" " Options:\n" @@ -1361,13 +1362,14 @@ vahParseArgv(vahControl * ctl, int argc, char **arg= v) {"add-file", 0, 0, 'f'}, {"append-file", 0, 0, 'F'}, {"help", 0, 0, 'h'}, + {"purge", 0, 0, 'P'}, {"replace", 0, 0, 'r'}, {"remove", 0, 0, 'R'}, {"uuid", 1, 0, 'u'}, {0, 0, 0, 0} }; =20 - while ((arg =3D getopt_long(argc, argv, "acdDhrRH:b:u:p:f:F:", opt, + while ((arg =3D getopt_long(argc, argv, "acdDhPrRH:b:u:p:f:F:", opt, &idx)) !=3D -1) { switch (arg) { case 'a': @@ -1391,6 +1393,9 @@ vahParseArgv(vahControl * ctl, int argc, char **argv) vah_usage(); exit(EXIT_SUCCESS); break; + case 'P': + ctl->cmd =3D 'P'; + break; case 'r': ctl->cmd =3D 'r'; break; @@ -1456,7 +1461,7 @@ static int create_profile(vahControl *ctl, char *prof= ile, char *include_file) return rc; } =20 -static int remove_profile(vahControl *ctl, char *include_file) +static int remove_profile(vahControl *ctl, char *profile, char *include_fi= le) { int rc =3D 0; =20 @@ -1464,6 +1469,8 @@ static int remove_profile(vahControl *ctl, char *incl= ude_file) return rc; if (ctl->cmd =3D=3D 'D') unlink(include_file); + if (ctl->cmd =3D=3D 'P') + unlink(profile); =20 return rc; } @@ -1519,7 +1526,7 @@ main(int argc, char **argv) if (ctl->cmd =3D=3D 'a') { rc =3D parserLoad(ctl->uuid); } else if (ctl->cmd =3D=3D 'R' || ctl->cmd =3D=3D 'D') { - rc =3D remove_profile(ctl, include_file); + rc =3D remove_profile(ctl, profile, include_file); } else if (ctl->cmd =3D=3D 'c' || ctl->cmd =3D=3D 'r') { char *included_files =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; --=20 2.17.1 From nobody Fri Apr 26 19:42:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=canonical.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1633629767961959.8797891795007; Thu, 7 Oct 2021 11:02:47 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-572-caOlAG28O32IQDujtVRang-1; Thu, 07 Oct 2021 14:02:41 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B5EBD362F8; Thu, 7 Oct 2021 18:02:35 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 989305BAE1; Thu, 7 Oct 2021 18:02:35 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6492257DC3; Thu, 7 Oct 2021 18:02:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 197HWlrG020096 for ; Thu, 7 Oct 2021 13:32:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 378482026D48; Thu, 7 Oct 2021 17:32:47 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 319562026D46 for ; Thu, 7 Oct 2021 17:32:47 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 17A43899EC0 for ; Thu, 7 Oct 2021 17:32:47 +0000 (UTC) Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-562-gaONOB6eN3iGvYL88PG6sg-1; Thu, 07 Oct 2021 13:32:41 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id C532640011 for ; Thu, 7 Oct 2021 17:25:48 +0000 (UTC) Received: by mail-wr1-f71.google.com with SMTP id 41-20020adf812c000000b00160dfbfe1a2so1591153wrm.3 for ; Thu, 07 Oct 2021 10:25:48 -0700 (PDT) Received: from localhost (o5wzrf.static.otenet.gr. [2.84.75.34]) by smtp.gmail.com with ESMTPSA id y16sm24729wmq.10.2021.10.07.10.25.45 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Oct 2021 10:25:45 -0700 (PDT) X-MC-Unique: caOlAG28O32IQDujtVRang-1 X-MC-Unique: gaONOB6eN3iGvYL88PG6sg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=J1wV5d8ud1sHy0k+PvAFIbBHLFzUQcyM9lDulu9uVKE=; b=4zpyE7PcJetUGJjI695ZQRPizYyMcyDYImroxKXCXYB31FZbnqNZkWSuJ31GYuEZEI fcbAuWRwFiozMhtlmK+MkM8c+cpeA9NHLxebrKEJilDWOFi3JSK2UIAUQe80jd/xGrwv lzf75ZjHcan5D8NnENAujF8SEOApeOeJ0yB28wJ7g9o7X78eFd7i3mAGcqXjCIPEvsM5 X3QrqrpmJIJf763EA7A/LiR8KsrCkvoI37e2s9CihhBQco9DGdZmcttHqdi/QtEmLz5/ pMuoWzepAaIQs4bZqxWQsQfAh9yAEyIZl3fQOsFuIg1ghRpOu9u8yHHb27BW24D0XGDI WtoA== X-Gm-Message-State: AOAM533n6He1rsRtq/j+qoTCF3Gj48rZ5gL+AVrj6Fjlo0KpQUOrNbil 2nnn3O1QlvelYnui5clm5YtHn7d6kOHvhh/mKtDOdWMI9yRD+IZMGH0JpWIBDk1jUJBF8Pjxs6p /dHXjEbBzfghm1jYvk1HSgPPDCSanhrFmbQ== X-Received: by 2002:a5d:6c65:: with SMTP id r5mr7097220wrz.26.1633627546192; Thu, 07 Oct 2021 10:25:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBnSBsOeZNAi1LpiyWUrdAbQ9abFssdldr7R27eB9gQLoEPwhu1BOURxhENmKcAnkFhALhaA== X-Received: by 2002:a5d:6c65:: with SMTP id r5mr7097198wrz.26.1633627545936; Thu, 07 Oct 2021 10:25:45 -0700 (PDT) From: Ioanna Alifieraki To: libvir-list@redhat.com, christian.ehrhardt@canonical.com, alejandro.santoyo@canonical.com Subject: [PATCH 3/4] virt-aa-helper: Purge profile if corrupted Date: Thu, 7 Oct 2021 20:25:37 +0300 Message-Id: <20211007172539.25224-4-ioanna-maria.alifieraki@canonical.com> In-Reply-To: <20211007172539.25224-1-ioanna-maria.alifieraki@canonical.com> References: <20211007172539.25224-1-ioanna-maria.alifieraki@canonical.com> X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 2 X-Mimecast-Originator: redhat.com X-ZM-MESSAGEID: 1633629769821100003 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This commit aims to address the bug reported in [1] and [2]. If the profile is corrupted (0-size) the VM cannot be launched. To overcome this check if the profile exists and if it has 0 size remove it and create it again. [1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=3D890084 [2] https://bugs.launchpad.net/bugs/1927519 Signed-off-by: Ioanna Alifieraki --- src/security/virt-aa-helper.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 5ec0fb8807..5e13b29053 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1489,6 +1489,7 @@ main(int argc, char **argv) int rc =3D -1; char *profile =3D NULL; char *include_file =3D NULL; + off_t size; =20 if (virGettextInitialize() < 0 || virErrorInitialize() < 0) { @@ -1534,6 +1535,28 @@ main(int argc, char **argv) if (ctl->cmd =3D=3D 'c' && virFileExists(profile)) vah_error(ctl, 1, _("profile exists")); =20 + /* + * Rare cases can leave corrupted empty files behind breaking + * the guest. An empty file is never correct as virt-aa-helper + * would at least add the basic rules, therefore clean this up + * for a proper refresh. + */ + + if (virFileExists(profile)) { + size =3D virFileLength(profile, -1); + if (size =3D=3D 0) { + char temp; + vah_warning(_("Profile of 0 size detected, will attempt to= remove and re-create it")); + temp =3D ctl->cmd; + ctl->cmd =3D 'P'; + if ((rc =3D remove_profile(ctl, profile, include_file)) != =3D 0) + vah_error(ctl, 1, _("could not remove corrupted profil= e")); + ctl->cmd =3D temp; + if ((rc =3D create_profile(ctl, profile, include_file)) != =3D 0) + vah_error(ctl, 1, _("could not re-create profile")); + } + } + if (ctl->append && ctl->newfile) { if (vah_add_file(&buf, ctl->newfile, "rwk") !=3D 0) goto cleanup; --=20 2.17.1 From nobody Fri Apr 26 19:42:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=canonical.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1633629776195410.6213437592078; Thu, 7 Oct 2021 11:02:56 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-411-RMWoz2cBOgaQWHsmgKOY4A-1; Thu, 07 Oct 2021 14:02:53 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AF037882B35; Thu, 7 Oct 2021 18:01:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7DAAF5CCFF2; Thu, 7 Oct 2021 18:01:43 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B02E157DC1; Thu, 7 Oct 2021 18:01:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 197HWhqr020072 for ; Thu, 7 Oct 2021 13:32:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 11E212026D48; Thu, 7 Oct 2021 17:32:43 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0DB962026D46 for ; Thu, 7 Oct 2021 17:32:43 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E7DFF899EC0 for ; Thu, 7 Oct 2021 17:32:42 +0000 (UTC) Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-435-94v3nK9SN26GI-t6nZDUkg-1; Thu, 07 Oct 2021 13:32:41 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 4487840012 for ; Thu, 7 Oct 2021 17:25:50 +0000 (UTC) Received: by mail-wr1-f70.google.com with SMTP id e12-20020a056000178c00b001606927de88so5254949wrg.10 for ; Thu, 07 Oct 2021 10:25:50 -0700 (PDT) Received: from localhost (o5wzrf.static.otenet.gr. [2.84.75.34]) by smtp.gmail.com with ESMTPSA id o26sm9422479wmc.17.2021.10.07.10.25.47 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Oct 2021 10:25:47 -0700 (PDT) X-MC-Unique: RMWoz2cBOgaQWHsmgKOY4A-1 X-MC-Unique: 94v3nK9SN26GI-t6nZDUkg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=JWgwwN+mRE8XO1xwOWJzpi2mvJHkUO/XVP07VASKkw0=; b=zyxP0Ezemk21N+UqaUidHj86Y0IBHqCgwpE2ZLLNF0u8ptGZwKhsjyZN3kL+MVUYTl PkHtGAWWynokYy8INqYnEPVQzbOhN8B1LFD4rB38zAIpNsloq7avkq6b5SBUv1zlmTUN 5j5Df/ODWffy+Vki/C2F1XMD19+/OUjH33LL7NFw0kYVBiR9b3ewDRTs2VZ2DrVKJJL+ /w06YJjxTNbGsmaE8scEjjJ/Rp3l0YxWLvy9D09yCCeZywJ8G2ftnLUqCGhig2h9eC3x FBYQQ8kkA/ceo3XMmRh6rIVwv7TkoXrdbz2+WKoqIKNmWiZJmCENVvx+iZoKzGvjmxNk aJLg== X-Gm-Message-State: AOAM530qEbqQzt6WxSqguHYbEsSEFha3Frs03UoLCTFx+Jr/ZRQlYrve BMcxitFZNXK0VWc1aoUA/d5HRfo0VxYyYjprAjyHSwkGf7mK0hwC5xqc7sRzQKLrUVccJzY/p1x 1H6LRPmVcVfIYChjrMp7M4BfrY4er+mrRYg== X-Received: by 2002:adf:a48e:: with SMTP id g14mr7044557wrb.11.1633627547915; Thu, 07 Oct 2021 10:25:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSiJ/2PTFmog9ZzhBDilJDvzH1xPxrA+WgNM/pM/hDyyKZiIfJAX12k4fhEYDQsxvCsaxpaA== X-Received: by 2002:adf:a48e:: with SMTP id g14mr7044542wrb.11.1633627547681; Thu, 07 Oct 2021 10:25:47 -0700 (PDT) From: Ioanna Alifieraki To: libvir-list@redhat.com, christian.ehrhardt@canonical.com, alejandro.santoyo@canonical.com Subject: [PATCH 4/4] virt-aa-helper: test: add test for new option -P Date: Thu, 7 Oct 2021 20:25:38 +0300 Message-Id: <20211007172539.25224-5-ioanna-maria.alifieraki@canonical.com> In-Reply-To: <20211007172539.25224-1-ioanna-maria.alifieraki@canonical.com> References: <20211007172539.25224-1-ioanna-maria.alifieraki@canonical.com> X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 2 X-Mimecast-Originator: redhat.com X-ZM-MESSAGEID: 1633629777067100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Create a corrupt profile and expect to be removed after the test is run. Signed-off-by: Ioanna Alifieraki Reviewed-by: J=C3=A1n Tomko --- tests/meson.build | 1 + tests/virt-aa-helper-test | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/tests/meson.build b/tests/meson.build index dfbc2c01e2..991cfc402d 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -40,6 +40,7 @@ tests_env =3D [ 'LC_ALL=3DC', 'LIBVIRT_AUTOSTART=3D0', 'G_DEBUG=3Dfatal-warnings', + 'sysconfdir=3D@0@'.format(get_option('prefix') / get_option('sysconfdir'= )), ] =20 if use_expensive_tests diff --git a/tests/virt-aa-helper-test b/tests/virt-aa-helper-test index 83f53acef6..135c4968b5 100755 --- a/tests/virt-aa-helper-test +++ b/tests/virt-aa-helper-test @@ -16,6 +16,7 @@ fi output=3D"/dev/null" use_valgrind=3D"" ld_library_path=3D"$abs_top_builddir/src/" +profile_path=3D"$sysconfdir/apparmor.d/libvirt/" if [ ! -z "$1" ] && [ "$1" =3D "-d" ]; then output=3D"/dev/stdout" shift @@ -399,6 +400,34 @@ testme "0" "shmem doorbell" "-r -u $valid_uuid" "$test= _xml" "\"/var/lib/libvirt/ sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,,= ,g" "$template_xml"= > "$test_xml" testme "0" "shmem doorbell serverpath" "-r -u $valid_uuid" "$test_xml" "\"= /var/lib/libvirt/ivshmem_socket\"\s*rw,$" =20 +# For the next test to run apparmor needs to be installed and enabled. +# In some environments (e.g. containers) even though apparmor is +# installed, it is not enabled because securityfs is not mounted. +# In those environments this test cannot run so skip it. +# This test also needs to be run as root. +if [ `eval id -u` =3D 0 ] && [ -x "$(command -v aa-enabled)" ] && [ `eval = aa-enabled` =3D "Yes" ]; then + sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk2,g" "$template_xml" = > "$test_xml" + # Running the tests does not require libvirt to be installed. As a + # result the appropriate directories have not been created. Create= them + # now to run the test. + mkdir -p "$profile_path" + # create a corrupted profile + touch "$profile_path/$valid_uuid" + testme "0" "purge" "-r -u $valid_uuid" "$test_xml" + # All the tests are run with the --dry-run option this test is + # never going to fail because the profile is not going to be loaded. + # However, since we touch the profile if it's still here after the test + # it means that something went wrong, so make the test fail. + if [ -f "$profile_path/$valid_uuid" ]; then + echo "FAIL: failed to purge corrupted profile" >$output + echo " '$extra_args $args': " + errors=3D$(($errors + 1)) + # remove corrupted profile anyways not to interfere with + # subsequent runs of the tests. + rm "$profile_path/$valid_uuid" + fi +fi + testme "0" "help" "-h" =20 echo "" >$output --=20 2.17.1