fsnotify: More precious error handling

Submitted by Cyrill Gorcunov on June 4, 2019, 7:11 a.m.

Details

Message ID 20190604071128.28283-1-gorcunov@gmail.com
State Accepted
Series "fsnotify: More precious error handling"
Headers show

Commit Message

Cyrill Gorcunov June 4, 2019, 7:11 a.m.
- 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@gmail.com>
---
 criu/fsnotify.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

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;

Comments

Dmitry Safonov June 4, 2019, 1:47 p.m.
On 6/4/19 8:11 AM, Cyrill Gorcunov wrote:
>  - 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@gmail.com>

Reviewed-by: Dmitry Safonov <0x7f454c46@gmail.com>