Blame SOURCES/0040-policycoreutils-setfiles-do-not-restrict-checks-agai.patch

dea676
From d10e773c014a12b17fefd9caef0bd02528d75d18 Mon Sep 17 00:00:00 2001
dea676
From: Antoine Tenart <antoine.tenart@bootlin.com>
dea676
Date: Tue, 7 Jul 2020 16:35:01 +0200
dea676
Subject: [PATCH] policycoreutils: setfiles: do not restrict checks against a
dea676
 binary policy
dea676
dea676
The -c option allows to check the validity of contexts against a
dea676
specified binary policy. Its use is restricted: no pathname can be used
dea676
when a binary policy is given to setfiles. It's not clear if this is
dea676
intentional as the built-in help and the man page are not stating the
dea676
same thing about this (the man page document -c as a normal option,
dea676
while the built-in help shows it is restricted).
dea676
dea676
When generating full system images later used with SELinux in enforcing
dea676
mode, the extended attributed of files have to be set by the build
dea676
machine. The issue is setfiles always checks the contexts against a
dea676
policy (ctx_validate = 1) and using an external binary policy is not
dea676
currently possible when using a pathname. This ends up in setfiles
dea676
failing early as the contexts of the target image are not always
dea676
compatible with the ones of the build machine.
dea676
dea676
This patch reworks a check on optind only made when -c is used, that
dea676
enforced the use of a single argument to allow 1+ arguments, allowing to
dea676
use setfiles with an external binary policy and pathnames. The following
dea676
command is then allowed, as already documented in the man page:
dea676
dea676
  $ setfiles -m -r target/ -c policy.32 file_contexts target/
dea676
dea676
Signed-off-by: Antoine Tenart <antoine.tenart@bootlin.com>
dea676
Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
dea676
dea676
(cherry-picked from SElinuxProject
dea676
 commit: c94e542c98da2f26863c1cbd9d7ad9bc5cca6aff )
dea676
---
dea676
 policycoreutils/setfiles/setfiles.c | 11 +++++------
dea676
 1 file changed, 5 insertions(+), 6 deletions(-)
dea676
dea676
diff --git a/policycoreutils/setfiles/setfiles.c b/policycoreutils/setfiles/setfiles.c
dea676
index 82d0aaa7..4fd3d756 100644
dea676
--- a/policycoreutils/setfiles/setfiles.c
dea676
+++ b/policycoreutils/setfiles/setfiles.c
dea676
@@ -39,11 +39,10 @@ static __attribute__((__noreturn__)) void usage(const char *const name)
dea676
 			name, name);
dea676
 	} else {
dea676
 		fprintf(stderr,
dea676
-			"usage:  %s [-diIDlmnpqvFW] [-e excludedir] [-r alt_root_path] spec_file pathname...\n"
dea676
-			"usage:  %s [-diIDlmnpqvFW] [-e excludedir] [-r alt_root_path] spec_file -f filename\n"
dea676
-			"usage:  %s -s [-diIDlmnpqvFW] spec_file\n"
dea676
-			"usage:  %s -c policyfile spec_file\n",
dea676
-			name, name, name, name);
dea676
+			"usage:  %s [-diIDlmnpqvEFW] [-e excludedir] [-r alt_root_path] [-c policyfile] spec_file pathname...\n"
dea676
+			"usage:  %s [-diIDlmnpqvEFW] [-e excludedir] [-r alt_root_path] [-c policyfile] spec_file -f filename\n"
dea676
+			"usage:  %s -s [-diIDlmnpqvFW] spec_file\n",
dea676
+			name, name, name);
dea676
 	}
dea676
 	exit(-1);
dea676
 }
dea676
@@ -376,7 +375,7 @@ int main(int argc, char **argv)
dea676
 
dea676
 	if (!iamrestorecon) {
dea676
 		if (policyfile) {
dea676
-			if (optind != (argc - 1))
dea676
+			if (optind > (argc - 1))
dea676
 				usage(argv[0]);
dea676
 		} else if (use_input_file) {
dea676
 			if (optind != (argc - 1)) {
dea676
-- 
dea676
2.30.2
dea676