From nobody Fri Apr 26 12:43:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1574931006; cv=none; d=zohomail.com; s=zohoarc; b=Qp34aJB7CqPuGpA9pCTL6Q9ZQniy8mIBxMqTZ/Ci7YDIyjSwSST5EOQ2y3QG55uEIiF9T78tIUSPc8MIADlTSTwSHL9360teyZfOeGvVQoj0iATLrRyT300WaTgG/GXdmAgsRnJcuE8vip81AJUEBC5DGaTj5/+gKMeXzegMb9c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574931006; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=kbTo4xE9eYjmznLzPLhyLAagYuFTS8Oz0Aafuv1oeR4=; b=YHFeZSXR6ZLFMBU2nteBeMWp6CiNfn52hqX0mLDnxljOeVqgQY64BxGYZdL6Y6SJ8ZvNc9xJlGIIhriu3HDsTF1RG0l2spcWpxG+gb1Vb/LoGeyXTXV+LOMQZHhM8LNb0xtl3fveqGguHFYLYG7tF5g0ci/8qpK/Kj6+2X794FI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1574931006214234.65152186112448; Thu, 28 Nov 2019 00:50:06 -0800 (PST) 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-83-KhXOS6XpOP2_-AqlgttXfA-1; Thu, 28 Nov 2019 03:50:03 -0500 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 31130800D4C; Thu, 28 Nov 2019 08:49:57 +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 E8B8C6084E; Thu, 28 Nov 2019 08:49: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 E14FB4BB65; Thu, 28 Nov 2019 08:49:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xAS8nt2W023578 for ; Thu, 28 Nov 2019 03:49:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id 109779301; Thu, 28 Nov 2019 08:49:55 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 903A8194BB for ; Thu, 28 Nov 2019 08:49:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574931005; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=kbTo4xE9eYjmznLzPLhyLAagYuFTS8Oz0Aafuv1oeR4=; b=cF3h5ipefLy1SPbDFPZGSPUE0ACoGYIcN4Cupu25cIgowX6Oqdb0DExmxtOAHVaYvJAARL acFdweSCdCandO8qhoS7GmArOBWT4XIQfxtjvXdCAo9njgCsL18QKL6NOz7dDCbPYb+zrg y12w3E76COcoVTNk9CYQqGbFcuhDt4I= From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 28 Nov 2019 09:49:46 +0100 Message-Id: <63427008159d77b8b44fd6a4d4795671a5dce2d5.1574930986.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] selinux: Drop needless getfilecon()-s 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 X-MC-Unique: KhXOS6XpOP2_-AqlgttXfA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" When SELinux support was first introduced the libselinux library wasn't that advanced and setfilecon_raw() or fsetfilecon_raw() could fail even when the target context was set. Looking at the current code [1][2] this is no longer the case. We can drop our workarounds. 1: https://github.com/SELinuxProject/selinux/blob/master/libselinux/src/set= filecon.c#L10 2: https://github.com/SELinuxProject/selinux/blob/master/libselinux/src/fse= tfilecon.c#L10 Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrang=C3=A9 --- src/security/security_selinux.c | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index e05ef7593e..0bfb6a7fa6 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1249,8 +1249,6 @@ virSecuritySELinuxSetFileconImpl(const char *path, const char *tcon, bool privileged) { - security_context_t econ; - /* Be aware that this function might run in a separate process. * Therefore, any driver state changes would be thrown away. */ =20 @@ -1259,15 +1257,6 @@ virSecuritySELinuxSetFileconImpl(const char *path, if (setfilecon_raw(path, (const char *)tcon) < 0) { int setfilecon_errno =3D errno; =20 - if (getfilecon_raw(path, &econ) >=3D 0) { - if (STREQ(tcon, econ)) { - freecon(econ); - /* It's alright, there's nothing to change anyway. */ - return 1; - } - freecon(econ); - } - /* If the error complaint is related to an image hosted on a (poss= ibly * read-only) NFS mount, or a usbfs/sysfs filesystem not supporting * labelling, then just ignore it & hope for the best. The user @@ -1401,22 +1390,11 @@ virSecuritySELinuxSetFilecon(virSecurityManagerPtr = mgr, static int virSecuritySELinuxFSetFilecon(int fd, char *tcon) { - security_context_t econ; - VIR_INFO("Setting SELinux context on fd %d to '%s'", fd, tcon); =20 if (fsetfilecon_raw(fd, tcon) < 0) { int fsetfilecon_errno =3D errno; =20 - if (fgetfilecon_raw(fd, &econ) >=3D 0) { - if (STREQ(tcon, econ)) { - freecon(econ); - /* It's alright, there's nothing to change anyway. */ - return 0; - } - freecon(econ); - } - /* if the error complaint is related to an image hosted on * an nfs mount, or a usbfs/sysfs filesystem not supporting * labelling, then just ignore it & hope for the best. --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list