From nobody Tue Sep 9 19:23:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1753104316; cv=none; d=zohomail.com; s=zohoarc; b=Oxt7N55YqqxP7FLKbplyKIFfMOiEer2Zld2Gf3Ymwxrpe/nGfqNowlxOLAREtJtTSBAwEwIDuTOT2KHczVLbtyHW3GSr2hF1My1JWDAPNvn0jQ0ksh9xnotipTwwNEiXFF/bpAqm/fQWfoc1nNbi5jYc6nYGT7CwjPHnK+HwF+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753104316; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=yjedDmiCOtYsmrhrNCV23Id2kZKjUHCO4LS4dqqlF3k=; b=aFFsKuzCzQgU/3bsSiG4Ug4T7YWVmSyMxjye+niSeQjcSEy599/tKtPpnTw4K+RgnLrl4jz4WL3MmEsyyqYnogHVZNDrZSzmN3NzOeNXXGqb99BIZ+G0hmZdcYM9ZFgR9Bk1FdM1eWBc+OBKzL4IIMoJuNUpgebFHKB29oi+Dmg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1753104316932299.4701934760744; Mon, 21 Jul 2025 06:25:16 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id D1617C15; Mon, 21 Jul 2025 09:25:15 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 26C1712B8; Mon, 21 Jul 2025 09:21:38 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B624F11B1; Mon, 21 Jul 2025 09:21:33 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 60D511324 for ; Mon, 21 Jul 2025 09:21:17 -0400 (EDT) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-128-7dXOgc51MRGGcU5xHBZ9XQ-1; Mon, 21 Jul 2025 09:21:15 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7F71B19560A3 for ; Mon, 21 Jul 2025 13:21:14 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.44.22.25]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7EBD218002B6 for ; Mon, 21 Jul 2025 13:21:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1753104076; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EOJ8nLutnkHx05DX9r/v/S6X9d+7iMQlPGGOtI/IQt4=; b=FqZnhQhM9rXEdoa8pTa+eVGvj9vHY0lAnn3g3kLuvDDpj0xLZdKo002zXV9pzw7Z9zsSek sZFWLX37BTHrX3Gi3ouR4Sb+XrD41qKmdHFJPBeZZibMeXS9dS5Fpz9lZh2XWDZ60Vt5lJ UTL901WTnHcvin/wzYnD+w4tOMGBjE8= X-MC-Unique: 7dXOgc51MRGGcU5xHBZ9XQ-1 X-Mimecast-MFC-AGG-ID: 7dXOgc51MRGGcU5xHBZ9XQ_1753104074 To: devel@lists.libvirt.org Subject: [PATCH 09/19] virSecuritySELinuxSet(Daemon)SocketLabel: Refactor cleanup Date: Mon, 21 Jul 2025 15:20:50 +0200 Message-ID: <4cb8efb048ef3c3471aaf445c85a846f9d4bbfc8.1753103831.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: KvSfXXSh8nvpUnaVzdfFE7oiWQ1FRIjfBETVfO3FQb8_1753104074 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: LM5NW4XVEC7QASP724BDEMBROPNQNKUC X-Message-ID-Hash: LM5NW4XVEC7QASP724BDEMBROPNQNKUC X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1753104318918116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Automatically free temporary variables and change 'cleanup' label to 'error'. Signed-off-by: Peter Krempa --- src/security/security_selinux.c | 37 +++++++++++++++------------------ 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 25f0c45955..ad789c611f 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -3147,9 +3147,8 @@ virSecuritySELinuxSetDaemonSocketLabel(virSecurityMan= ager *mgr G_GNUC_UNUSED, { /* TODO: verify DOI */ virSecurityLabelDef *secdef; - char *scon =3D NULL; - char *str =3D NULL; - int rc =3D -1; + g_autofree char *scon =3D NULL; + g_autofree char *str =3D NULL; secdef =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME); if (!secdef || !secdef->label) @@ -3159,34 +3158,33 @@ virSecuritySELinuxSetDaemonSocketLabel(virSecurityM= anager *mgr G_GNUC_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, _("security label driver mismatch: '%1$s' model con= figured for domain, but hypervisor driver is '%2$s'."), secdef->model, SECURITY_SELINUX_NAME); - goto done; + goto error; } if (getcon_raw(&scon) =3D=3D -1) { virReportSystemError(errno, _("unable to get current process context '%1$= s'"), secdef->label); - goto done; + goto error; } if (!(str =3D virSecuritySELinuxContextAddRange(secdef->label, scon))) - goto done; + goto error; VIR_DEBUG("Setting VM %s socket context %s", def->name, str); if (setsockcreatecon_raw(str) =3D=3D -1) { virReportSystemError(errno, _("unable to set socket security context '%1$= s'"), str); - goto done; + goto error; } - rc =3D 0; - done: + return 0; + error: if (security_getenforce() !=3D 1) - rc =3D 0; - freecon(scon); - VIR_FREE(str); - return rc; + return 0; + + return -1; } static int @@ -3194,7 +3192,6 @@ virSecuritySELinuxSetSocketLabel(virSecurityManager *= mgr G_GNUC_UNUSED, virDomainDef *vm) { virSecurityLabelDef *secdef; - int rc =3D -1; secdef =3D virDomainDefGetSecurityLabelDef(vm, SECURITY_SELINUX_NAME); if (!secdef || !secdef->label) @@ -3204,7 +3201,7 @@ virSecuritySELinuxSetSocketLabel(virSecurityManager *= mgr G_GNUC_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, _("security label driver mismatch: '%1$s' model con= figured for domain, but hypervisor driver is '%2$s'."), secdef->model, SECURITY_SELINUX_NAME); - goto done; + goto error; } VIR_DEBUG("Setting VM %s socket context %s", @@ -3213,16 +3210,16 @@ virSecuritySELinuxSetSocketLabel(virSecurityManager= *mgr G_GNUC_UNUSED, virReportSystemError(errno, _("unable to set socket security context '%1$= s'"), secdef->label); - goto done; + goto error; } - rc =3D 0; + return 0; - done: + error: if (security_getenforce() !=3D 1) - rc =3D 0; + return 0; - return rc; + return -1; } static int --=20 2.50.0