[CRIU] [PATCH] files-reg: Add testing of @mode immutability

Cyrill Gorcunov gorcunov at openvz.org
Fri Jun 17 05:14:31 PDT 2016


Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 criu/files-reg.c         | 18 ++++++++++++++----
 criu/include/files-reg.h |  2 +-
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/criu/files-reg.c b/criu/files-reg.c
index 6ad3a773730f..2f1c6952da0a 100644
--- a/criu/files-reg.c
+++ b/criu/files-reg.c
@@ -1473,7 +1473,8 @@ ext:
 		return -1;
 	}
 
-	if (rfi->rfe->has_size && !rfi->size_checked) {
+	if ((rfi->rfe->has_size || rfi->rfe->has_mode) &&
+	    !rfi->size_mode_checked) {
 		struct stat st;
 
 		if (fstat(tmp, &st) < 0) {
@@ -1481,19 +1482,28 @@ ext:
 			return -1;
 		}
 
-		if (st.st_size != rfi->rfe->size) {
+		if (rfi->rfe->has_size && (st.st_size != rfi->rfe->size)) {
 			pr_err("File %s has bad size %"PRIu64" (expect %"PRIu64")\n",
 					rfi->path, st.st_size,
 					rfi->rfe->size);
 			return -1;
 		}
 
+		if (rfi->rfe->has_mode && (st.st_mode != rfi->rfe->mode)) {
+			if (st.st_mode != rfi->rfe->mode) {
+				pr_err("File %s has bad mode 0%o (expect 0%o)\n",
+				       rfi->path, (int)st.st_mode,
+				       rfi->rfe->mode);
+				return -1;
+			}
+		}
+
 		/*
 		 * This is only visible in the current process, so
 		 * change w/o locks. Other tasks sharing the same
 		 * file will get one via unix sockets.
 		 */
-		rfi->size_checked = true;
+		rfi->size_mode_checked = true;
 	}
 
 	if (rfi->remap) {
@@ -1698,7 +1708,7 @@ static int collect_one_regfile(void *o, ProtobufCMessage *base, struct cr_img *i
 	else
 		rfi->path = rfi->rfe->name + 1;
 	rfi->remap = NULL;
-	rfi->size_checked = false;
+	rfi->size_mode_checked = false;
 
 	pr_info("Collected [%s] ID %#x\n", rfi->path, rfi->rfe->id);
 	return file_desc_add(&rfi->d, rfi->rfe->id, &reg_desc_ops);
diff --git a/criu/include/files-reg.h b/criu/include/files-reg.h
index 5ae279399341..dd4e7c009e55 100644
--- a/criu/include/files-reg.h
+++ b/criu/include/files-reg.h
@@ -22,7 +22,7 @@ struct reg_file_info {
 	struct file_desc	d;
 	RegFileEntry		*rfe;
 	struct file_remap	*remap;
-	bool			size_checked;
+	bool			size_mode_checked;
 	bool			is_dir;
 	char			*path;
 };
-- 
2.5.5



More information about the CRIU mailing list