[PATCH] inotify: fix the running away counter of user watches

From: Alex Riesen
Date: Mon Jul 27 2009 - 14:51:01 EST


The counter of userspace inotify watches is incremented when a watch is
added, but was never decremented. This patch uses the fsnotify callback
(freeing_marks, which in turn calls inotify_ignored_and_remove_idr of
inotify userspace interface) called when an fsnotify mark is removed.

The bug has been reported in

http://bugzilla.kernel.org/show_bug.cgi?id=12754

Signed-off-by: Alex Riesen <raa.lkml@xxxxxxxxx>
---

Sorry for long Cc:, I'm a little confused about "fs_other@" (and the
list of participants) in the bug report.

The patch works in my limited testing. I just did:

# echo 10 >/proc/sys/fs/inotify/max_user_watches
# inotify-watch -r /lib # to max the counter
Ctrl-C
# inotify-watch /bin/true # must work

in a clean environment (init=/bin/bash).

But I don't know whether it safe to access the counter in this
callback, nor am I sure the patch is enough.

fs/notify/inotify/inotify_user.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
index ff27a29..c2d94df 100644
--- a/fs/notify/inotify/inotify_user.c
+++ b/fs/notify/inotify/inotify_user.c
@@ -404,6 +404,7 @@ skip_send_ignore:

/* removed from idr, drop that reference */
fsnotify_put_mark(entry);
+ atomic_dec(&group->inotify_data.user->inotify_watches);
}

/* ding dong the mark is dead */
--
1.6.4.rc3.56.g32a7


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/