From: Eric Paris <eparis@redhat.com>
To: linux-kernel@vger.kernel.org, linus-fsdevel@vger.kernel.org
Cc: viro@zeniv.linux.org.uk, hch@infradead.org, agruen@suse.de,
eparis@redhat.com
Subject: [PATCH 01/10] vfs: introduce FMODE_NONOTIFY
Date: Sat, 31 Oct 2009 14:47:21 -0400 [thread overview]
Message-ID: <20091031184721.17244.16465.stgit@paris.rdu.redhat.com> (raw)
This is a new f_mode which can only be set by the kernel. It indicates
that the fd was opened by fanotify and should not cause future fanotify
events. This is needed to prevent fanotify livelock. An example of
obvious livelock is from fanotify close events.
Process A closes file1
This creates a close event for file1.
fanotify opens file1 for Listener X
Listener X deals with the event and closes its fd for file1.
This creates a close event for file1.
fanotify opens file1 for Listener X
Listener X deals with the event and closes its fd for file1.
This creates a close event for file1.
fanotify opens file1 for Listener X
Listener X deals with the event and closes its fd for file1.
notice a pattern?
The fix is to add the FMODE_NONOTIFY bit to the open filp done by the kernel
for fanotify. Thus when that file is used it will not generate future
events.
This patch simply defines the bit.
Signed-off-by: Eric Paris <eparis@redhat.com>
---
fs/open.c | 7 ++++---
include/asm-generic/fcntl.h | 8 ++++++++
include/linux/fs.h | 3 +++
include/linux/fsnotify.h | 24 ++++++++++++++++--------
4 files changed, 31 insertions(+), 11 deletions(-)
diff --git a/fs/open.c b/fs/open.c
index ce737b3..7347eef 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -831,9 +831,10 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
struct inode *inode;
int error;
- f->f_flags = flags;
- f->f_mode = (__force fmode_t)((flags+1) & O_ACCMODE) | FMODE_LSEEK |
- FMODE_PREAD | FMODE_PWRITE;
+ f->f_flags = (flags & ~(FMODE_EXEC | FMODE_NONOTIFY));
+ f->f_mode = (__force fmode_t)((flags+1) & O_ACCMODE) | (flags & FMODE_NONOTIFY) |
+ FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE;
+
inode = dentry->d_inode;
if (f->f_mode & FMODE_WRITE) {
error = __get_file_write_access(inode, mnt);
diff --git a/include/asm-generic/fcntl.h b/include/asm-generic/fcntl.h
index 104fce8..30bece2 100644
--- a/include/asm-generic/fcntl.h
+++ b/include/asm-generic/fcntl.h
@@ -3,6 +3,14 @@
#include <linux/types.h>
+/*
+ * FMODE_EXEC is 0x20
+ * FMODE_NONOTIFY is 0x800000
+ * These cannot be used by userspace O_* until internal and external open
+ * flags are split.
+ * -Eric Paris
+ */
+
#define O_ACCMODE 00000003
#define O_RDONLY 00000000
#define O_WRONLY 00000001
diff --git a/include/linux/fs.h b/include/linux/fs.h
index ab92f13..752056f 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -87,6 +87,9 @@ struct inodes_stat_t {
*/
#define FMODE_NOCMTIME ((__force fmode_t)2048)
+/* File was opened by fanotify and shouldn't generate fanotify events */
+#define FMODE_NONOTIFY ((__force fmode_t)8388608)
+
/*
* The below are the various read and write types that we support. Some of
* them include behavioral modifiers that send information down to the
diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
index 294f488..cc4dead 100644
--- a/include/linux/fsnotify.h
+++ b/include/linux/fsnotify.h
@@ -197,8 +197,10 @@ static inline void fsnotify_access(struct file *file)
inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
- fsnotify_parent(path, NULL, mask);
- fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
+ if (!(file->f_mode & FMODE_NONOTIFY)) {
+ fsnotify_parent(path, NULL, mask);
+ fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
+ }
}
/*
@@ -215,8 +217,10 @@ static inline void fsnotify_modify(struct file *file)
inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
- fsnotify_parent(path, NULL, mask);
- fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
+ if (!(file->f_mode & FMODE_NONOTIFY)) {
+ fsnotify_parent(path, NULL, mask);
+ fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
+ }
}
/*
@@ -233,8 +237,10 @@ static inline void fsnotify_open(struct file *file)
inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
- fsnotify_parent(path, NULL, mask);
- fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
+ if (!(file->f_mode & FMODE_NONOTIFY)) {
+ fsnotify_parent(path, NULL, mask);
+ fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
+ }
}
/*
@@ -252,8 +258,10 @@ static inline void fsnotify_close(struct file *file)
inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
- fsnotify_parent(path, NULL, mask);
- fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
+ if (!(file->f_mode & FMODE_NONOTIFY)) {
+ fsnotify_parent(path, NULL, mask);
+ fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
+ }
}
/*
next reply other threads:[~2009-10-31 18:47 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-31 18:47 Eric Paris [this message]
2009-10-31 18:47 ` [PATCH 02/10] fanotify: fscking all notification system Eric Paris
2009-11-06 15:31 ` Eric Paris
2009-11-06 15:54 ` Andreas Gruenbacher
2009-10-31 18:47 ` [PATCH 03/10] fanotify:drop notification if they exist in the outgoing queue Eric Paris
2009-10-31 18:47 ` [PATCH 04/10] fanotify: merge notification events with different masks Eric Paris
2009-10-31 18:47 ` [PATCH 05/10] fanotify: do not clone on merge unless needed Eric Paris
2009-10-31 18:47 ` [PATCH 06/10] fanotify: fanotify_init syscall declaration Eric Paris
2009-10-31 18:48 ` [PATCH 07/10] fanotify: fanotify_init syscall implementation Eric Paris
2009-10-31 18:48 ` [PATCH 08/10] fanotify: sys_fanotify_mark declartion Eric Paris
2009-10-31 18:48 ` [PATCH 09/10] fanotify: fanotify_mark syscall implementation Eric Paris
2009-10-31 18:48 ` [PATCH 10/10] send events using read Eric Paris
2009-11-03 23:59 ` Jonathan Corbet
2009-11-04 0:55 ` Eric Paris
2009-11-04 8:07 ` Vegard Nossum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20091031184721.17244.16465.stgit@paris.rdu.redhat.com \
--to=eparis@redhat.com \
--cc=agruen@suse.de \
--cc=hch@infradead.org \
--cc=linus-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®