From ffec56803412afbb3f13d16d57101742e50984c6 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Tue, 4 Jun 2019 10:11:28 +0300 Subject: [PATCH] fsnotify: More precious error handling - 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 Reviewed-by: Dmitry Safonov <0x7f454c46@gmail.com> Signed-off-by: Andrei Vagin --- criu/fsnotify.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/criu/fsnotify.c b/criu/fsnotify.c index ed8a67a21..09093c0be 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 @@ out: 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 @@ fault: 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 @@ fault: } 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;