Blame SOURCES/0004-libsemanage-sync-filesystem-with-sandbox.patch

ea8539
From 11e381e5aa3468aa5c2634f14706336c7824f226 Mon Sep 17 00:00:00 2001
ea8539
From: Petr Lautrbach <plautrba@redhat.com>
ea8539
Date: Wed, 27 Jan 2021 12:00:55 +0100
ea8539
Subject: [PATCH] libsemanage: sync filesystem with sandbox
ea8539
ea8539
Commit 331a109f91ea ("libsemanage: fsync final files before rename")
ea8539
added fsync() for policy files and improved situation when something
ea8539
unexpected happens right after rename(). However the module store could
ea8539
be affected as well. After the following steps module files could be 0
ea8539
size:
ea8539
ea8539
1. Run `semanage fcontext -a -t var_t "/tmp/abc"`
ea8539
2. Force shutdown the server during the command is run, or right after
ea8539
   it's finished
ea8539
3. Boot the system and look for empty files:
ea8539
    # find /var/lib/selinux/targeted/ -type f -size 0 | wc -l
ea8539
    1266
ea8539
ea8539
It looks like this situation can be avoided if the filesystem with the
ea8539
sandbox is sync()ed before we start to rename() directories in the
ea8539
store.
ea8539
ea8539
Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
ea8539
Acked-by: Nicolas Iooss <nicolas.iooss@m4x.org>
ea8539
---
ea8539
 libsemanage/src/semanage_store.c | 13 +++++++++++++
ea8539
 1 file changed, 13 insertions(+)
ea8539
ea8539
diff --git a/libsemanage/src/semanage_store.c b/libsemanage/src/semanage_store.c
ea8539
index 733df8da37c2..ae023582e907 100644
ea8539
--- a/libsemanage/src/semanage_store.c
ea8539
+++ b/libsemanage/src/semanage_store.c
ea8539
@@ -1737,6 +1737,19 @@ static int semanage_commit_sandbox(semanage_handle_t * sh)
ea8539
 	}
ea8539
 	close(fd);
ea8539
 
ea8539
+	/* sync changes in sandbox to filesystem */
ea8539
+	fd = open(sandbox, O_DIRECTORY);
ea8539
+	if (fd == -1) {
ea8539
+		ERR(sh, "Error while opening %s for syncfs(): %d", sandbox, errno);
ea8539
+		return -1;
ea8539
+	}
ea8539
+	if (syncfs(fd) == -1) {
ea8539
+		ERR(sh, "Error while syncing %s to filesystem: %d", sandbox, errno);
ea8539
+		close(fd);
ea8539
+		return -1;
ea8539
+	}
ea8539
+	close(fd);
ea8539
+
ea8539
 	retval = commit_number;
ea8539
 
ea8539
 	if (semanage_get_active_lock(sh) < 0) {
ea8539
-- 
ea8539
2.30.0
ea8539