[CRIU] [PATCH] mount: Fix restore deleted bindmounts for regfiles

Cyrill Gorcunov gorcunov at openvz.org
Wed Sep 2 05:57:12 PDT 2015


 - make sure it doesn't exist using O_EXCL
 - don't forget to close it

Reported-by: Pavel Emelyanov <xemul at parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 mount.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mount.c b/mount.c
index 6d44eae442ac..45c54685051e 100644
--- a/mount.c
+++ b/mount.c
@@ -2008,10 +2008,13 @@ do_bind:
 					return -1;
 				}
 			} else if (S_ISREG(st.st_mode)) {
-				if (open(root, O_WRONLY | O_CREAT | O_TRUNC, (st.st_mode & ~S_IFMT)) < 0) {
+				int fd = open(root, O_WRONLY | O_CREAT | O_EXCL,
+					      st.st_mode & ~S_IFMT);
+				if (fd < 0) {
 					pr_perror("Can't re-create deleted file %s\n", root);
 					return -1;
 				}
+				close(fd);
 			} else {
 				pr_err("Unsupported st_mode 0%o deleted root %s\n",
 				       (int)st.st_mode, root);
-- 
2.4.3



More information about the CRIU mailing list