fanotify: allow userspace to override max marks
authorEric Paris <eparis@redhat.com>
Thu, 28 Oct 2010 21:21:58 +0000 (17:21 -0400)
committerEric Paris <eparis@redhat.com>
Thu, 28 Oct 2010 21:22:15 +0000 (17:22 -0400)
Some fanotify groups, especially those like AV scanners, will need to place
lots of marks, particularly ignore marks.  Since ignore marks do not pin
inodes in cache and are cleared if the inode is removed from core (usually
under memory pressure) we expose an interface for listeners, with
CAP_SYS_ADMIN, to override the maximum number of marks and be allowed to
set and 'unlimited' number of marks.  Programs which make use of this
feature will be able to OOM a machine.

Signed-off-by: Eric Paris <eparis@redhat.com>
fs/notify/fanotify/fanotify_user.c
include/linux/fanotify.h

index 1d33d7db277a75e641a486d753acf8ec891c1b89..f9216102b4261f997b6838be271110f4a3238a6e 100644 (file)
@@ -707,7 +707,14 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
                group->max_events = FANOTIFY_DEFAULT_MAX_EVENTS;
        }
 
-       group->fanotify_data.max_marks = FANOTIFY_DEFAULT_MAX_MARKS;
+       if (flags & FAN_UNLIMITED_MARKS) {
+               fd = -EPERM;
+               if (!capable(CAP_SYS_ADMIN))
+                       goto out_put_group;
+               group->fanotify_data.max_marks = UINT_MAX;
+       } else {
+               group->fanotify_data.max_marks = FANOTIFY_DEFAULT_MAX_MARKS;
+       }
 
        fd = anon_inode_getfd("[fanotify]", &fanotify_fops, group, f_flags);
        if (fd < 0)
index e37f559c95e1316dec36cc549c63234d671f062d..7592a366a57b1deea86a553663964839c2ea9ea8 100644 (file)
                                 FAN_CLASS_PRE_CONTENT)
 
 #define FAN_UNLIMITED_QUEUE    0x00000010
+#define FAN_UNLIMITED_MARKS    0x00000020
 
 #define FAN_ALL_INIT_FLAGS     (FAN_CLOEXEC | FAN_NONBLOCK | \
-                                FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE)
+                                FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE |\
+                                FAN_UNLIMITED_MARKS)
 
 /* flags used for fanotify_modify_mark() */
 #define FAN_MARK_ADD           0x00000001