Commit e7099d8a authored by Eric Paris's avatar Eric Paris

fanotify: limit the number of marks in a single fanotify group

There is currently no limit on the number of marks a given fanotify group
can have.  Since fanotify is gated on CAP_SYS_ADMIN this was not seen as
a serious DoS threat.  This patch implements a default of 8192, the same as
inotify to work towards removing the CAP_SYS_ADMIN gating and eliminating
the default DoS'able status.
Signed-off-by: default avatarEric Paris <eparis@redhat.com>
parent 5dd03f55
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <asm/ioctls.h> #include <asm/ioctls.h>
#define FANOTIFY_DEFAULT_MAX_EVENTS 16384 #define FANOTIFY_DEFAULT_MAX_EVENTS 16384
#define FANOTIFY_DEFAULT_MAX_MARKS 8192
extern const struct fsnotify_ops fanotify_fsnotify_ops; extern const struct fsnotify_ops fanotify_fsnotify_ops;
...@@ -584,6 +585,9 @@ static int fanotify_add_vfsmount_mark(struct fsnotify_group *group, ...@@ -584,6 +585,9 @@ static int fanotify_add_vfsmount_mark(struct fsnotify_group *group,
if (!fsn_mark) { if (!fsn_mark) {
int ret; int ret;
if (atomic_read(&group->num_marks) > group->fanotify_data.max_marks)
return -ENOSPC;
fsn_mark = kmem_cache_alloc(fanotify_mark_cache, GFP_KERNEL); fsn_mark = kmem_cache_alloc(fanotify_mark_cache, GFP_KERNEL);
if (!fsn_mark) if (!fsn_mark)
return -ENOMEM; return -ENOMEM;
...@@ -626,6 +630,9 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group, ...@@ -626,6 +630,9 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group,
if (!fsn_mark) { if (!fsn_mark) {
int ret; int ret;
if (atomic_read(&group->num_marks) > group->fanotify_data.max_marks)
return -ENOSPC;
fsn_mark = kmem_cache_alloc(fanotify_mark_cache, GFP_KERNEL); fsn_mark = kmem_cache_alloc(fanotify_mark_cache, GFP_KERNEL);
if (!fsn_mark) if (!fsn_mark)
return -ENOMEM; return -ENOMEM;
...@@ -700,6 +707,8 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) ...@@ -700,6 +707,8 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
group->max_events = FANOTIFY_DEFAULT_MAX_EVENTS; group->max_events = FANOTIFY_DEFAULT_MAX_EVENTS;
} }
group->fanotify_data.max_marks = FANOTIFY_DEFAULT_MAX_MARKS;
fd = anon_inode_getfd("[fanotify]", &fanotify_fops, group, f_flags); fd = anon_inode_getfd("[fanotify]", &fanotify_fops, group, f_flags);
if (fd < 0) if (fd < 0)
goto out_put_group; goto out_put_group;
......
...@@ -169,6 +169,7 @@ struct fsnotify_group { ...@@ -169,6 +169,7 @@ struct fsnotify_group {
bool bypass_perm; /* protected by access_mutex */ bool bypass_perm; /* protected by access_mutex */
#endif /* CONFIG_FANOTIFY_ACCESS_PERMISSIONS */ #endif /* CONFIG_FANOTIFY_ACCESS_PERMISSIONS */
int f_flags; int f_flags;
unsigned int max_marks;
} fanotify_data; } fanotify_data;
#endif /* CONFIG_FANOTIFY */ #endif /* CONFIG_FANOTIFY */
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment