[CRIU] [PATCH] fsnotify: More precious error handling

Cyrill Gorcunov gorcunov at gmail.com
Tue Jun 4 10:11:28 MSK 2019


 - make sure the alloc_openable is not failed with
   memory error, so that we should not lookup via
   irmap

 - irmap lookup should provide us a copy of the path
   instead of reference to irmap entry

https://github.com/checkpoint-restore/criu/issues/698

Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
 criu/fsnotify.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/criu/fsnotify.c b/criu/fsnotify.c
index ed8a67a216e6..09093c0bed90 100644
--- a/criu/fsnotify.c
+++ b/criu/fsnotify.c
@@ -175,7 +175,7 @@ static char *alloc_openable(unsigned int s_dev, unsigned long i_ino, FhEntry *f_
 			if (st.st_ino == i_ino) {
 				path = xstrdup(buf);
 				if (path == NULL)
-					goto err;
+					return ERR_PTR(-ENOMEM);
 				if (root_ns_mask & CLONE_NEWNS) {
 					f_handle->has_mnt_id = true;
 					f_handle->mnt_id = m->mnt_id;
@@ -227,8 +227,8 @@ static int open_handle(unsigned int s_dev, unsigned long i_ino,
 int check_open_handle(unsigned int s_dev, unsigned long i_ino,
 		FhEntry *f_handle)
 {
+	char *path, *irmap_path;
 	int fd = -1;
-	char *path;
 
 	if (fault_injected(FI_CHECK_OPEN_HANDLE)) {
 		fd = -1;
@@ -262,6 +262,8 @@ int check_open_handle(unsigned int s_dev, unsigned long i_ino,
 		path = alloc_openable(s_dev, i_ino, f_handle);
 		if (!IS_ERR_OR_NULL(path))
 			goto out;
+		else if (IS_ERR(path) && PTR_ERR(path) == -ENOMEM)
+			goto err;
 
 		if ((mi->fstype->code == FSTYPE__TMPFS) ||
 		    (mi->fstype->code == FSTYPE__DEVTMPFS)) {
@@ -284,11 +286,14 @@ int check_open_handle(unsigned int s_dev, unsigned long i_ino,
 	}
 
 	pr_warn("\tHandle 0x%x:0x%lx cannot be opened\n", s_dev, i_ino);
-	path = irmap_lookup(s_dev, i_ino);
-	if (!path) {
+	irmap_path = irmap_lookup(s_dev, i_ino);
+	if (!irmap_path) {
 		pr_err("\tCan't dump that handle\n");
 		return -1;
 	}
+	path = xstrdup(irmap_path);
+	if (!path)
+		goto err;
 out:
 	pr_debug("\tDumping %s as path for handle\n", path);
 	f_handle->path = path;
-- 
2.20.1



More information about the CRIU mailing list