From patchwork Mon Oct 7 21:49:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 175440 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp4853723ill; Mon, 7 Oct 2019 14:58:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqyMmM5vqFEBRhasXkhd/G2Fv8BoV0/XvIqFl8b/eZJ+iyAH65V7Wec0RTEMD0kgjNhfHe9+ X-Received: by 2002:a6b:1456:: with SMTP id 83mr8334812iou.152.1570485523919; Mon, 07 Oct 2019 14:58:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570485523; cv=none; d=google.com; s=arc-20160816; b=CC9uj2ylVwtWUqpP6Kxp/yjYK5m+8ct3AWve6hC5cWEZ6p9OMMgUT7S9RkHQ5VH1CB XeRQzFvr5TBByEsFKf/K7FtlgGF7HixSXD4v+zMnbp1s74VplssmO2XlVajbrePTF6H/ ZraskJtLl9q1iBKUEvCSwIsgb2fk8W5SDxwoJRQj07Ljc7riDeg/9IWdXRncIk5lG9x1 S/7XPcxs/m++5g80fGis9LM6I7sXWzxh1esQZ2Ye896pSKG6WuYQES/nmViXWmrJSNtq y6ziUznmOOpIWnA0QDIuEFu6xpygJapYzuRpcKD1HYpiNjwaI03GWwDdw1OTA3y1VtJn 72Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=loO52K808zflaD8P7fdR5q5/eHC3XV6ktq3KksMrgMU=; b=RYLGYOKfqXeLBk/k5+HbSTW41pIf/wUOqsXErSyR0EQX63AuWYo+I4o1HjtNn5uEm+ ssOh9Zxzx906lnzcmh4q/eBGudeS3Ntg698PVudBIIBiO3vSwMfk+DkRMOKfshEodZkU VH52A6sIkDdG1A0kUVbxgnenSdxBVZKQ3OupkWoz7wUym6ZqOd/37PVwVqxy411PRLYw bWl4TZoMT+TXuDVlW/tNqLT/jnAp5YfvZAKQF85cFUn+T7xoyLcpS7qS77XtcwHSVZEm khlt5JWDe4msORjr1rlel8Go9ljDTKmGYbskXsG3oCISfIHQO+ZuH7/9pCpiZ630WlDY 9MXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id e9si18783562jam.73.2019.10.07.14.58.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Oct 2019 14:58:43 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 mx1.redhat.com (Postfix) with ESMTPS id AC45E18C8922; Mon, 7 Oct 2019 21:58:42 +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 57F7460BF4; Mon, 7 Oct 2019 21:58:42 +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 180E24EEB8; Mon, 7 Oct 2019 21:58:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x97Loto2015161 for ; Mon, 7 Oct 2019 17:50:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 858E15C224; Mon, 7 Oct 2019 21:50:55 +0000 (UTC) Delivered-To: libvir-list@redhat.com Received: from worklaptop.redhat.com (ovpn-123-156.rdu2.redhat.com [10.10.123.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 29ADF5C1D4; Mon, 7 Oct 2019 21:50:55 +0000 (UTC) From: Cole Robinson To: libvir-list@redhat.com Date: Mon, 7 Oct 2019 17:49:39 -0400 Message-Id: <0223a7618af9936a4db511d4ede7492a2313f905.1570482718.git.crobinso@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 25/30] security: selinux: Simplify SetImageLabelInternal 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 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.70]); Mon, 07 Oct 2019 21:58:43 +0000 (UTC) All the SetFileCon calls only differ by the label they pass in. Rework the conditionals to track what label we need, and use a single SetFileCon call Signed-off-by: Cole Robinson --- src/security/security_selinux.c | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) -- 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list Reviewed-by: Daniel Henrique Barboza diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index e879fa39ab..9d28bc5773 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1822,6 +1822,7 @@ virSecuritySELinuxSetImageLabelInternal(virSecurityManagerPtr mgr, virSecurityLabelDefPtr secdef; virSecurityDeviceLabelDefPtr disk_seclabel; virSecurityDeviceLabelDefPtr parent_seclabel = NULL; + char *use_label = NULL; bool remember; int ret; @@ -1856,40 +1857,28 @@ virSecuritySELinuxSetImageLabelInternal(virSecurityManagerPtr mgr, if (!disk_seclabel->relabel) return 0; - ret = virSecuritySELinuxSetFilecon(mgr, src->path, - disk_seclabel->label, remember); + use_label = disk_seclabel->label; } else if (parent_seclabel && (!parent_seclabel->relabel || parent_seclabel->label)) { if (!parent_seclabel->relabel) return 0; - ret = virSecuritySELinuxSetFilecon(mgr, src->path, - parent_seclabel->label, remember); + use_label = parent_seclabel->label; } else if (!parent || parent == src) { if (src->shared) { - ret = virSecuritySELinuxSetFilecon(mgr, - src->path, - data->file_context, - remember); + use_label = data->file_context; } else if (src->readonly) { - ret = virSecuritySELinuxSetFilecon(mgr, - src->path, - data->content_context, - remember); + use_label = data->content_context; } else if (secdef->imagelabel) { - ret = virSecuritySELinuxSetFilecon(mgr, - src->path, - secdef->imagelabel, - remember); + use_label = secdef->imagelabel; } else { - ret = 0; + return 0; } } else { - ret = virSecuritySELinuxSetFilecon(mgr, - src->path, - data->content_context, - remember); + use_label = data->content_context; } + ret = virSecuritySELinuxSetFilecon(mgr, src->path, use_label, remember); + if (ret == 1 && !disk_seclabel) { /* If we failed to set a label, but virt_use_nfs let us * proceed anyway, then we don't need to relabel later. */