4e4c210
From 62c9d2674b31d4c8a674bee86b7edc6da2803aea Mon Sep 17 00:00:00 2001
4e4c210
From: ZhangXiaoxu <zhangxiaoxu5@huawei.com>
4e4c210
Date: Sat, 2 Mar 2019 09:17:32 +0800
4e4c210
Subject: [PATCH] inotify: Fix fsnotify_mark refcount leak in
4e4c210
 inotify_update_existing_watch()
4e4c210
4e4c210
Commit 4d97f7d53da7dc83 ("inotify: Add flag IN_MASK_CREATE for
4e4c210
inotify_add_watch()") forgot to call fsnotify_put_mark() with
4e4c210
IN_MASK_CREATE after fsnotify_find_mark()
4e4c210
4e4c210
Fixes: 4d97f7d53da7dc83 ("inotify: Add flag IN_MASK_CREATE for inotify_add_watch()")
4e4c210
Signed-off-by: ZhangXiaoxu <zhangxiaoxu5@huawei.com>
4e4c210
Signed-off-by: Jan Kara <jack@suse.cz>
4e4c210
---
4e4c210
 fs/notify/inotify/inotify_user.c | 7 +++++--
4e4c210
 1 file changed, 5 insertions(+), 2 deletions(-)
4e4c210
4e4c210
diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
4e4c210
index e2901fbb9f76..7b53598c8804 100644
4e4c210
--- a/fs/notify/inotify/inotify_user.c
4e4c210
+++ b/fs/notify/inotify/inotify_user.c
4e4c210
@@ -519,8 +519,10 @@ static int inotify_update_existing_watch(struct fsnotify_group *group,
4e4c210
 	fsn_mark = fsnotify_find_mark(&inode->i_fsnotify_marks, group);
4e4c210
 	if (!fsn_mark)
4e4c210
 		return -ENOENT;
4e4c210
-	else if (create)
4e4c210
-		return -EEXIST;
4e4c210
+	else if (create) {
4e4c210
+		ret = -EEXIST;
4e4c210
+		goto out;
4e4c210
+	}
4e4c210
4e4c210
 	i_mark = container_of(fsn_mark, struct inotify_inode_mark, fsn_mark);
4e4c210
4e4c210
@@ -548,6 +550,7 @@ static int inotify_update_existing_watch(struct fsnotify_group *group,
4e4c210
 	/* return the wd */
4e4c210
 	ret = i_mark->wd;
4e4c210
4e4c210
+out:
4e4c210
 	/* match the get from fsnotify_find_mark() */
4e4c210
 	fsnotify_put_mark(fsn_mark);
4e4c210
4e4c210
-- 
4e4c210
2.20.1
4e4c210