Blame SOURCES/0032-restorecond-Fix-redundant-console-log-output-error.patch

c33c08
From 76371721bafed56efcb7a83b3fa3285383ede5b7 Mon Sep 17 00:00:00 2001
c33c08
From: Baichuan Kong <kongbaichuan@huawei.com>
c33c08
Date: Thu, 14 Nov 2019 10:48:07 +0800
c33c08
Subject: [PATCH] restorecond: Fix redundant console log output error
c33c08
c33c08
When starting restorecond without any option the following redundant
c33c08
console log is outputed:
c33c08
c33c08
/dev/log 100.0%
c33c08
/var/volatile/run/syslogd.pid 100.0%
c33c08
...
c33c08
c33c08
This is caused by two global variables of same name r_opts. When
c33c08
executes r_opts = opts in restore_init(), it originally intends
c33c08
to assign the address of struct r_opts in "restorecond.c" to the
c33c08
pointer *r_opts in "restore.c".
c33c08
c33c08
However, the address is assigned to the struct r_opts and covers
c33c08
the value of low eight bytes in it. That causes unexpected value
c33c08
of member varibale 'nochange' and 'verbose' in struct r_opts, thus
c33c08
affects value of 'restorecon_flags' and executes unexpected operations
c33c08
when restorecon the files such as the redundant console log output or
c33c08
file label nochange.
c33c08
c33c08
Cause restorecond/restore.c is copied from policycoreutils/setfiles,
c33c08
which share the same pattern. It also has potential risk to generate
c33c08
same problems, So fix it in case.
c33c08
c33c08
Signed-off-by: Baichuan Kong <kongbaichuan@huawei.com>
c33c08
c33c08
(cherry-picked from SElinuxProject
c33c08
commit ad2208ec220f55877a4d31084be2b4d6413ee082)
c33c08
c33c08
Resolves: rhbz#1626468
c33c08
---
c33c08
 policycoreutils/setfiles/restore.c | 42 ++++++++++++++----------------
c33c08
 restorecond/restore.c              | 40 +++++++++++++---------------
c33c08
 2 files changed, 37 insertions(+), 45 deletions(-)
c33c08
c33c08
diff --git a/policycoreutils/setfiles/restore.c b/policycoreutils/setfiles/restore.c
c33c08
index 9dea5656..d3335d1a 100644
c33c08
--- a/policycoreutils/setfiles/restore.c
c33c08
+++ b/policycoreutils/setfiles/restore.c
c33c08
@@ -17,40 +17,37 @@
c33c08
 char **exclude_list;
c33c08
 int exclude_count;
c33c08
 
c33c08
-struct restore_opts *r_opts;
c33c08
-
c33c08
 void restore_init(struct restore_opts *opts)
c33c08
 {
c33c08
 	int rc;
c33c08
 
c33c08
-	r_opts = opts;
c33c08
 	struct selinux_opt selinux_opts[] = {
c33c08
-		{ SELABEL_OPT_VALIDATE, r_opts->selabel_opt_validate },
c33c08
-		{ SELABEL_OPT_PATH, r_opts->selabel_opt_path },
c33c08
-		{ SELABEL_OPT_DIGEST, r_opts->selabel_opt_digest }
c33c08
+		{ SELABEL_OPT_VALIDATE, opts->selabel_opt_validate },
c33c08
+		{ SELABEL_OPT_PATH, opts->selabel_opt_path },
c33c08
+		{ SELABEL_OPT_DIGEST, opts->selabel_opt_digest }
c33c08
 	};
c33c08
 
c33c08
-	r_opts->hnd = selabel_open(SELABEL_CTX_FILE, selinux_opts, 3);
c33c08
-	if (!r_opts->hnd) {
c33c08
-		perror(r_opts->selabel_opt_path);
c33c08
+	opts->hnd = selabel_open(SELABEL_CTX_FILE, selinux_opts, 3);
c33c08
+	if (!opts->hnd) {
c33c08
+		perror(opts->selabel_opt_path);
c33c08
 		exit(1);
c33c08
 	}
c33c08
 
c33c08
-	r_opts->restorecon_flags = 0;
c33c08
-	r_opts->restorecon_flags = r_opts->nochange | r_opts->verbose |
c33c08
-			   r_opts->progress | r_opts->set_specctx  |
c33c08
-			   r_opts->add_assoc | r_opts->ignore_digest |
c33c08
-			   r_opts->recurse | r_opts->userealpath |
c33c08
-			   r_opts->xdev | r_opts->abort_on_error |
c33c08
-			   r_opts->syslog_changes | r_opts->log_matches |
c33c08
-			   r_opts->ignore_noent | r_opts->ignore_mounts |
c33c08
-			   r_opts->mass_relabel;
c33c08
+	opts->restorecon_flags = 0;
c33c08
+	opts->restorecon_flags = opts->nochange | opts->verbose |
c33c08
+			   opts->progress | opts->set_specctx  |
c33c08
+			   opts->add_assoc | opts->ignore_digest |
c33c08
+			   opts->recurse | opts->userealpath |
c33c08
+			   opts->xdev | opts->abort_on_error |
c33c08
+			   opts->syslog_changes | opts->log_matches |
c33c08
+			   opts->ignore_noent | opts->ignore_mounts |
c33c08
+			   opts->mass_relabel;
c33c08
 
c33c08
 	/* Use setfiles, restorecon and restorecond own handles */
c33c08
-	selinux_restorecon_set_sehandle(r_opts->hnd);
c33c08
+	selinux_restorecon_set_sehandle(opts->hnd);
c33c08
 
c33c08
-	if (r_opts->rootpath) {
c33c08
-		rc = selinux_restorecon_set_alt_rootpath(r_opts->rootpath);
c33c08
+	if (opts->rootpath) {
c33c08
+		rc = selinux_restorecon_set_alt_rootpath(opts->rootpath);
c33c08
 		if (rc) {
c33c08
 			fprintf(stderr,
c33c08
 				"selinux_restorecon_set_alt_rootpath error: %s.\n",
c33c08
@@ -81,7 +78,6 @@ int process_glob(char *name, struct restore_opts *opts)
c33c08
 	size_t i = 0;
c33c08
 	int len, rc, errors;
c33c08
 
c33c08
-	r_opts = opts;
c33c08
 	memset(&globbuf, 0, sizeof(globbuf));
c33c08
 
c33c08
 	errors = glob(name, GLOB_TILDE | GLOB_PERIOD |
c33c08
@@ -96,7 +92,7 @@ int process_glob(char *name, struct restore_opts *opts)
c33c08
 		if (len > 0 && strcmp(&globbuf.gl_pathv[i][len], "/..") == 0)
c33c08
 			continue;
c33c08
 		rc = selinux_restorecon(globbuf.gl_pathv[i],
c33c08
-					r_opts->restorecon_flags);
c33c08
+					opts->restorecon_flags);
c33c08
 		if (rc < 0)
c33c08
 			errors = rc;
c33c08
 	}
c33c08
diff --git a/restorecond/restore.c b/restorecond/restore.c
c33c08
index f6e30001..b93b5fdb 100644
c33c08
--- a/restorecond/restore.c
c33c08
+++ b/restorecond/restore.c
c33c08
@@ -12,39 +12,36 @@
c33c08
 char **exclude_list;
c33c08
 int exclude_count;
c33c08
 
c33c08
-struct restore_opts *r_opts;
c33c08
-
c33c08
 void restore_init(struct restore_opts *opts)
c33c08
 {
c33c08
 	int rc;
c33c08
 
c33c08
-	r_opts = opts;
c33c08
 	struct selinux_opt selinux_opts[] = {
c33c08
-		{ SELABEL_OPT_VALIDATE, r_opts->selabel_opt_validate },
c33c08
-		{ SELABEL_OPT_PATH, r_opts->selabel_opt_path },
c33c08
-		{ SELABEL_OPT_DIGEST, r_opts->selabel_opt_digest }
c33c08
+		{ SELABEL_OPT_VALIDATE, opts->selabel_opt_validate },
c33c08
+		{ SELABEL_OPT_PATH, opts->selabel_opt_path },
c33c08
+		{ SELABEL_OPT_DIGEST, opts->selabel_opt_digest }
c33c08
 	};
c33c08
 
c33c08
-	r_opts->hnd = selabel_open(SELABEL_CTX_FILE, selinux_opts, 3);
c33c08
-	if (!r_opts->hnd) {
c33c08
-		perror(r_opts->selabel_opt_path);
c33c08
+	opts->hnd = selabel_open(SELABEL_CTX_FILE, selinux_opts, 3);
c33c08
+	if (!opts->hnd) {
c33c08
+		perror(opts->selabel_opt_path);
c33c08
 		exit(1);
c33c08
 	}
c33c08
 
c33c08
-	r_opts->restorecon_flags = 0;
c33c08
-	r_opts->restorecon_flags = r_opts->nochange | r_opts->verbose |
c33c08
-			   r_opts->progress | r_opts->set_specctx  |
c33c08
-			   r_opts->add_assoc | r_opts->ignore_digest |
c33c08
-			   r_opts->recurse | r_opts->userealpath |
c33c08
-			   r_opts->xdev | r_opts->abort_on_error |
c33c08
-			   r_opts->syslog_changes | r_opts->log_matches |
c33c08
-			   r_opts->ignore_noent | r_opts->ignore_mounts;
c33c08
+	opts->restorecon_flags = 0;
c33c08
+	opts->restorecon_flags = opts->nochange | opts->verbose |
c33c08
+			   opts->progress | opts->set_specctx  |
c33c08
+			   opts->add_assoc | opts->ignore_digest |
c33c08
+			   opts->recurse | opts->userealpath |
c33c08
+			   opts->xdev | opts->abort_on_error |
c33c08
+			   opts->syslog_changes | opts->log_matches |
c33c08
+			   opts->ignore_noent | opts->ignore_mounts;
c33c08
 
c33c08
 	/* Use setfiles, restorecon and restorecond own handles */
c33c08
-	selinux_restorecon_set_sehandle(r_opts->hnd);
c33c08
+	selinux_restorecon_set_sehandle(opts->hnd);
c33c08
 
c33c08
-	if (r_opts->rootpath) {
c33c08
-		rc = selinux_restorecon_set_alt_rootpath(r_opts->rootpath);
c33c08
+	if (opts->rootpath) {
c33c08
+		rc = selinux_restorecon_set_alt_rootpath(opts->rootpath);
c33c08
 		if (rc) {
c33c08
 			fprintf(stderr,
c33c08
 				"selinux_restorecon_set_alt_rootpath error: %s.\n",
c33c08
@@ -75,7 +72,6 @@ int process_glob(char *name, struct restore_opts *opts)
c33c08
 	size_t i = 0;
c33c08
 	int len, rc, errors;
c33c08
 
c33c08
-	r_opts = opts;
c33c08
 	memset(&globbuf, 0, sizeof(globbuf));
c33c08
 
c33c08
 	errors = glob(name, GLOB_TILDE | GLOB_PERIOD |
c33c08
@@ -90,7 +86,7 @@ int process_glob(char *name, struct restore_opts *opts)
c33c08
 		if (len > 0 && strcmp(&globbuf.gl_pathv[i][len], "/..") == 0)
c33c08
 			continue;
c33c08
 		rc = selinux_restorecon(globbuf.gl_pathv[i],
c33c08
-					r_opts->restorecon_flags);
c33c08
+					opts->restorecon_flags);
c33c08
 		if (rc < 0)
c33c08
 			errors = rc;
c33c08
 	}
c33c08
-- 
c33c08
2.21.0
c33c08