Received: from goalie.tycho.ncsc.mil (goalie [144.51.242.250]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u7G7WOU8005572 for ; Tue, 16 Aug 2016 03:32:24 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B8D92C04B30A for ; Tue, 16 Aug 2016 07:32:21 +0000 (UTC) Received: from localhost.localdomain ([10.40.2.164]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7G7WKAO005397 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 16 Aug 2016 03:32:21 -0400 To: selinux@tycho.nsa.gov From: Vit Mojzis Subject: [Bug report] Semanage fcontext with incorrect regexp Message-ID: Date: Tue, 16 Aug 2016 09:32:19 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: When given invalid regexp, semanage reports error, but adds the invalid context to "/etc/selinux/targeted/contexts/files/file_contexts.local", which breaks the system (won't boot in enforcing mode). The new context doesn't show up on "#semanage fcontext -l -C" and cannot be removed by "semanage fcontext --delete". Investigation on Fedora version of libsemanage showed that "file_contexts.local" is not backed up before the new version is installed into the system and therefore cannot be restored after failure. For more details see: https://bugzilla.redhat.com/show_bug.cgi?id=1362041 # semanage fcontext -a -t httpd_exec_t "(/.*)?" specfiles SHA1 digest: 980289cabd78157523679695fd2e4fd0a5b5ff05 calculated using the following specfile(s): /etc/selinux/targeted/contexts/files/file_contexts.subs_dist /etc/selinux/targeted/contexts/files/file_contexts.subs /etc/selinux/targeted/contexts/files/file_contexts /etc/selinux/targeted/contexts/files/file_contexts.homedirs /etc/selinux/targeted/contexts/files/file_contexts.local libsemanage.semanage_exec_prog: Child process /sbin/sefcontext_compile did not exit cleanly. (No such file or directory). libsemanage.sefcontext_compile: sefcontext_compile returned error code -1. Compiling /etc/selinux/targeted/contexts/files/file_contexts.local (No such file or directory). specfiles SHA1 digest: 5097e1780892f53aedb6d30d5d61206a159a20e7 calculated using the following specfile(s): /etc/selinux/targeted/contexts/files/file_contexts.subs_dist /etc/selinux/targeted/contexts/files/file_contexts.subs /etc/selinux/targeted/contexts/files/file_contexts.bin /etc/selinux/targeted/contexts/files/file_contexts.homedirs /etc/selinux/targeted/contexts/files/file_contexts.local libsemanage.semanage_exec_prog: Child process /sbin/sefcontext_compile did not exit cleanly. (No such file or directory). libsemanage.sefcontext_compile: sefcontext_compile returned error code -1. Compiling /etc/selinux/targeted/contexts/files/file_contexts.local (No such file or directory). FileNotFoundError: [Errno 2] No such file or directory # semanage fcontext -l -C - # cat /etc/selinux/targeted/contexts/files/file_contexts.local # This file is auto-generated by libsemanage # Do not edit directly. (/.*)? system_u:object_r:httpd_exec_t:s0 # semanage fcontext -d -t httpd_exec_t "(/.*)?" ValueError: File context for (/.*)? is not defined