From nobody Sat Feb 7 15:12:39 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554208918485498.188483495018; Tue, 2 Apr 2019 05:41:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6743B74F0B; Tue, 2 Apr 2019 12:41:55 +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 44E621853F; Tue, 2 Apr 2019 12:41:55 +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 0A8ED41F3C; Tue, 2 Apr 2019 12:41:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x32Cepf1008805 for ; Tue, 2 Apr 2019 08:40:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id D927068403; Tue, 2 Apr 2019 12:40:51 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-56.ams2.redhat.com [10.36.112.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCE626A49C; Tue, 2 Apr 2019 12:40:50 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 2 Apr 2019 13:40:35 +0100 Message-Id: <20190402124036.2415-4-berrange@redhat.com> In-Reply-To: <20190402124036.2415-1-berrange@redhat.com> References: <20190402124036.2415-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/4] security: avoid use of dirent d_type field 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 02 Apr 2019 12:41:56 +0000 (UTC) The d_type field cannot be assumed to be filled. Some filesystems, such as older XFS, will simply report DT_UNKNOWN. Even if the d_type is filled in, the use of it in the SELinux functions is dubious. If labelling all files in a directory there's no reason to skip things which are not regular files. We merely need to skip "." and "..", which is done by virDirRead() already. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/security/security_selinux.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 2fceb547b4..3611bb8ebe 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -3282,9 +3282,6 @@ virSecuritySELinuxSetFileLabels(virSecurityManagerPtr= mgr, return -1; =20 while ((ret =3D virDirRead(dir, &ent, path)) > 0) { - if (ent->d_type !=3D DT_REG) - continue; - if (virAsprintf(&filename, "%s/%s", path, ent->d_name) < 0) { ret =3D -1; break; @@ -3334,7 +3331,8 @@ virSecuritySELinuxRestoreFileLabels(virSecurityManage= rPtr mgr, return -1; =20 while ((ret =3D virDirRead(dir, &ent, path)) > 0) { - if (ent->d_type !=3D DT_REG) + if (STREQ(ent->d_name, ".") || + STREQ(ent->d_name, "..")) continue; =20 if (virAsprintf(&filename, "%s/%s", path, ent->d_name) < 0) { --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list