Commit 6685df31 authored by Miklos Szeredi's avatar Miklos Szeredi Committed by Jan Kara

fanotify: clean up CONFIG_FANOTIFY_ACCESS_PERMISSIONS ifdefs

The only negative from this patch should be an addition of 32bytes to
'struct fsnotify_group' if CONFIG_FANOTIFY_ACCESS_PERMISSIONS is not
defined.
Reviewed-by: default avatarAmir Goldstein <amir73il@gmail.com>
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent 3427ce71
...@@ -35,15 +35,13 @@ static int fanotify_merge(struct list_head *list, struct fsnotify_event *event) ...@@ -35,15 +35,13 @@ static int fanotify_merge(struct list_head *list, struct fsnotify_event *event)
pr_debug("%s: list=%p event=%p\n", __func__, list, event); pr_debug("%s: list=%p event=%p\n", __func__, list, event);
#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
/* /*
* Don't merge a permission event with any other event so that we know * Don't merge a permission event with any other event so that we know
* the event structure we have created in fanotify_handle_event() is the * the event structure we have created in fanotify_handle_event() is the
* one we should check for permission response. * one we should check for permission response.
*/ */
if (event->mask & FAN_ALL_PERM_EVENTS) if (fanotify_is_perm_event(event->mask))
return 0; return 0;
#endif
list_for_each_entry_reverse(test_event, list, list) { list_for_each_entry_reverse(test_event, list, list) {
if (should_merge(test_event, event)) { if (should_merge(test_event, event)) {
...@@ -55,7 +53,6 @@ static int fanotify_merge(struct list_head *list, struct fsnotify_event *event) ...@@ -55,7 +53,6 @@ static int fanotify_merge(struct list_head *list, struct fsnotify_event *event)
return 0; return 0;
} }
#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
static int fanotify_get_response(struct fsnotify_group *group, static int fanotify_get_response(struct fsnotify_group *group,
struct fanotify_perm_event_info *event, struct fanotify_perm_event_info *event,
struct fsnotify_iter_info *iter_info) struct fsnotify_iter_info *iter_info)
...@@ -82,7 +79,6 @@ static int fanotify_get_response(struct fsnotify_group *group, ...@@ -82,7 +79,6 @@ static int fanotify_get_response(struct fsnotify_group *group,
return ret; return ret;
} }
#endif
static bool fanotify_should_send_event(struct fsnotify_mark *inode_mark, static bool fanotify_should_send_event(struct fsnotify_mark *inode_mark,
struct fsnotify_mark *vfsmnt_mark, struct fsnotify_mark *vfsmnt_mark,
...@@ -141,8 +137,7 @@ struct fanotify_event_info *fanotify_alloc_event(struct inode *inode, u32 mask, ...@@ -141,8 +137,7 @@ struct fanotify_event_info *fanotify_alloc_event(struct inode *inode, u32 mask,
{ {
struct fanotify_event_info *event; struct fanotify_event_info *event;
#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS if (fanotify_is_perm_event(mask)) {
if (mask & FAN_ALL_PERM_EVENTS) {
struct fanotify_perm_event_info *pevent; struct fanotify_perm_event_info *pevent;
pevent = kmem_cache_alloc(fanotify_perm_event_cachep, pevent = kmem_cache_alloc(fanotify_perm_event_cachep,
...@@ -153,7 +148,6 @@ struct fanotify_event_info *fanotify_alloc_event(struct inode *inode, u32 mask, ...@@ -153,7 +148,6 @@ struct fanotify_event_info *fanotify_alloc_event(struct inode *inode, u32 mask,
pevent->response = 0; pevent->response = 0;
goto init; goto init;
} }
#endif
event = kmem_cache_alloc(fanotify_event_cachep, GFP_KERNEL); event = kmem_cache_alloc(fanotify_event_cachep, GFP_KERNEL);
if (!event) if (!event)
return NULL; return NULL;
...@@ -200,8 +194,7 @@ static int fanotify_handle_event(struct fsnotify_group *group, ...@@ -200,8 +194,7 @@ static int fanotify_handle_event(struct fsnotify_group *group,
pr_debug("%s: group=%p inode=%p mask=%x\n", __func__, group, inode, pr_debug("%s: group=%p inode=%p mask=%x\n", __func__, group, inode,
mask); mask);
#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS if (fanotify_is_perm_event(mask)) {
if (mask & FAN_ALL_PERM_EVENTS) {
/* /*
* fsnotify_prepare_user_wait() fails if we race with mark * fsnotify_prepare_user_wait() fails if we race with mark
* deletion. Just let the operation pass in that case. * deletion. Just let the operation pass in that case.
...@@ -209,7 +202,6 @@ static int fanotify_handle_event(struct fsnotify_group *group, ...@@ -209,7 +202,6 @@ static int fanotify_handle_event(struct fsnotify_group *group,
if (!fsnotify_prepare_user_wait(iter_info)) if (!fsnotify_prepare_user_wait(iter_info))
return 0; return 0;
} }
#endif
event = fanotify_alloc_event(inode, mask, data); event = fanotify_alloc_event(inode, mask, data);
ret = -ENOMEM; ret = -ENOMEM;
...@@ -225,21 +217,15 @@ static int fanotify_handle_event(struct fsnotify_group *group, ...@@ -225,21 +217,15 @@ static int fanotify_handle_event(struct fsnotify_group *group,
fsnotify_destroy_event(group, fsn_event); fsnotify_destroy_event(group, fsn_event);
ret = 0; ret = 0;
goto finish; } else if (fanotify_is_perm_event(mask)) {
}
#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
if (mask & FAN_ALL_PERM_EVENTS) {
ret = fanotify_get_response(group, FANOTIFY_PE(fsn_event), ret = fanotify_get_response(group, FANOTIFY_PE(fsn_event),
iter_info); iter_info);
fsnotify_destroy_event(group, fsn_event); fsnotify_destroy_event(group, fsn_event);
} }
finish: finish:
if (mask & FAN_ALL_PERM_EVENTS) if (fanotify_is_perm_event(mask))
fsnotify_finish_user_wait(iter_info); fsnotify_finish_user_wait(iter_info);
#else
finish:
#endif
return ret; return ret;
} }
...@@ -259,13 +245,11 @@ static void fanotify_free_event(struct fsnotify_event *fsn_event) ...@@ -259,13 +245,11 @@ static void fanotify_free_event(struct fsnotify_event *fsn_event)
event = FANOTIFY_E(fsn_event); event = FANOTIFY_E(fsn_event);
path_put(&event->path); path_put(&event->path);
put_pid(event->tgid); put_pid(event->tgid);
#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS if (fanotify_is_perm_event(fsn_event->mask)) {
if (fsn_event->mask & FAN_ALL_PERM_EVENTS) {
kmem_cache_free(fanotify_perm_event_cachep, kmem_cache_free(fanotify_perm_event_cachep,
FANOTIFY_PE(fsn_event)); FANOTIFY_PE(fsn_event));
return; return;
} }
#endif
kmem_cache_free(fanotify_event_cachep, event); kmem_cache_free(fanotify_event_cachep, event);
} }
......
...@@ -21,7 +21,6 @@ struct fanotify_event_info { ...@@ -21,7 +21,6 @@ struct fanotify_event_info {
struct pid *tgid; struct pid *tgid;
}; };
#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
/* /*
* Structure for permission fanotify events. It gets allocated and freed in * Structure for permission fanotify events. It gets allocated and freed in
* fanotify_handle_event() since we wait there for user response. When the * fanotify_handle_event() since we wait there for user response. When the
...@@ -40,7 +39,12 @@ FANOTIFY_PE(struct fsnotify_event *fse) ...@@ -40,7 +39,12 @@ FANOTIFY_PE(struct fsnotify_event *fse)
{ {
return container_of(fse, struct fanotify_perm_event_info, fae.fse); return container_of(fse, struct fanotify_perm_event_info, fae.fse);
} }
#endif
static inline bool fanotify_is_perm_event(u32 mask)
{
return IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS) &&
mask & FAN_ALL_PERM_EVENTS;
}
static inline struct fanotify_event_info *FANOTIFY_E(struct fsnotify_event *fse) static inline struct fanotify_event_info *FANOTIFY_E(struct fsnotify_event *fse)
{ {
......
...@@ -142,7 +142,6 @@ static int fill_event_metadata(struct fsnotify_group *group, ...@@ -142,7 +142,6 @@ static int fill_event_metadata(struct fsnotify_group *group,
return ret; return ret;
} }
#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
static struct fanotify_perm_event_info *dequeue_event( static struct fanotify_perm_event_info *dequeue_event(
struct fsnotify_group *group, int fd) struct fsnotify_group *group, int fd)
{ {
...@@ -199,7 +198,6 @@ static int process_access_response(struct fsnotify_group *group, ...@@ -199,7 +198,6 @@ static int process_access_response(struct fsnotify_group *group,
return 0; return 0;
} }
#endif
static ssize_t copy_event_to_user(struct fsnotify_group *group, static ssize_t copy_event_to_user(struct fsnotify_group *group,
struct fsnotify_event *event, struct fsnotify_event *event,
...@@ -221,10 +219,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group, ...@@ -221,10 +219,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
fanotify_event_metadata.event_len)) fanotify_event_metadata.event_len))
goto out_close_fd; goto out_close_fd;
#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS if (fanotify_is_perm_event(event->mask))
if (event->mask & FAN_ALL_PERM_EVENTS)
FANOTIFY_PE(event)->fd = fd; FANOTIFY_PE(event)->fd = fd;
#endif
if (fd != FAN_NOFD) if (fd != FAN_NOFD)
fd_install(fd, f); fd_install(fd, f);
...@@ -309,10 +305,9 @@ static ssize_t fanotify_read(struct file *file, char __user *buf, ...@@ -309,10 +305,9 @@ static ssize_t fanotify_read(struct file *file, char __user *buf,
* Permission events get queued to wait for response. Other * Permission events get queued to wait for response. Other
* events can be destroyed now. * events can be destroyed now.
*/ */
if (!(kevent->mask & FAN_ALL_PERM_EVENTS)) { if (!fanotify_is_perm_event(kevent->mask)) {
fsnotify_destroy_event(group, kevent); fsnotify_destroy_event(group, kevent);
} else { } else {
#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
if (ret <= 0) { if (ret <= 0) {
FANOTIFY_PE(kevent)->response = FAN_DENY; FANOTIFY_PE(kevent)->response = FAN_DENY;
wake_up(&group->fanotify_data.access_waitq); wake_up(&group->fanotify_data.access_waitq);
...@@ -322,7 +317,6 @@ static ssize_t fanotify_read(struct file *file, char __user *buf, ...@@ -322,7 +317,6 @@ static ssize_t fanotify_read(struct file *file, char __user *buf,
&group->fanotify_data.access_list); &group->fanotify_data.access_list);
spin_unlock(&group->notification_lock); spin_unlock(&group->notification_lock);
} }
#endif
} }
if (ret < 0) if (ret < 0)
break; break;
...@@ -338,11 +332,13 @@ static ssize_t fanotify_read(struct file *file, char __user *buf, ...@@ -338,11 +332,13 @@ static ssize_t fanotify_read(struct file *file, char __user *buf,
static ssize_t fanotify_write(struct file *file, const char __user *buf, size_t count, loff_t *pos) static ssize_t fanotify_write(struct file *file, const char __user *buf, size_t count, loff_t *pos)
{ {
#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
struct fanotify_response response = { .fd = -1, .response = -1 }; struct fanotify_response response = { .fd = -1, .response = -1 };
struct fsnotify_group *group; struct fsnotify_group *group;
int ret; int ret;
if (!IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS))
return -EINVAL;
group = file->private_data; group = file->private_data;
if (count > sizeof(response)) if (count > sizeof(response))
...@@ -358,16 +354,11 @@ static ssize_t fanotify_write(struct file *file, const char __user *buf, size_t ...@@ -358,16 +354,11 @@ static ssize_t fanotify_write(struct file *file, const char __user *buf, size_t
count = ret; count = ret;
return count; return count;
#else
return -EINVAL;
#endif
} }
static int fanotify_release(struct inode *ignored, struct file *file) static int fanotify_release(struct inode *ignored, struct file *file)
{ {
struct fsnotify_group *group = file->private_data; struct fsnotify_group *group = file->private_data;
#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
struct fanotify_perm_event_info *event, *next; struct fanotify_perm_event_info *event, *next;
struct fsnotify_event *fsn_event; struct fsnotify_event *fsn_event;
...@@ -403,14 +394,14 @@ static int fanotify_release(struct inode *ignored, struct file *file) ...@@ -403,14 +394,14 @@ static int fanotify_release(struct inode *ignored, struct file *file)
spin_unlock(&group->notification_lock); spin_unlock(&group->notification_lock);
fsnotify_destroy_event(group, fsn_event); fsnotify_destroy_event(group, fsn_event);
spin_lock(&group->notification_lock); spin_lock(&group->notification_lock);
} else } else {
FANOTIFY_PE(fsn_event)->response = FAN_ALLOW; FANOTIFY_PE(fsn_event)->response = FAN_ALLOW;
} }
}
spin_unlock(&group->notification_lock); spin_unlock(&group->notification_lock);
/* Response for all permission events it set, wakeup waiters */ /* Response for all permission events it set, wakeup waiters */
wake_up(&group->fanotify_data.access_waitq); wake_up(&group->fanotify_data.access_waitq);
#endif
/* matches the fanotify_init->fsnotify_alloc_group */ /* matches the fanotify_init->fsnotify_alloc_group */
fsnotify_destroy_group(group); fsnotify_destroy_group(group);
...@@ -768,10 +759,8 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) ...@@ -768,10 +759,8 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
if (force_o_largefile()) if (force_o_largefile())
event_f_flags |= O_LARGEFILE; event_f_flags |= O_LARGEFILE;
group->fanotify_data.f_flags = event_f_flags; group->fanotify_data.f_flags = event_f_flags;
#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
init_waitqueue_head(&group->fanotify_data.access_waitq); init_waitqueue_head(&group->fanotify_data.access_waitq);
INIT_LIST_HEAD(&group->fanotify_data.access_list); INIT_LIST_HEAD(&group->fanotify_data.access_list);
#endif
switch (flags & FAN_ALL_CLASS_BITS) { switch (flags & FAN_ALL_CLASS_BITS) {
case FAN_CLASS_NOTIF: case FAN_CLASS_NOTIF:
group->priority = FS_PRIO_0; group->priority = FS_PRIO_0;
...@@ -825,6 +814,7 @@ SYSCALL_DEFINE5(fanotify_mark, int, fanotify_fd, unsigned int, flags, ...@@ -825,6 +814,7 @@ SYSCALL_DEFINE5(fanotify_mark, int, fanotify_fd, unsigned int, flags,
struct fsnotify_group *group; struct fsnotify_group *group;
struct fd f; struct fd f;
struct path path; struct path path;
u32 valid_mask = FAN_ALL_EVENTS | FAN_EVENT_ON_CHILD;
int ret; int ret;
pr_debug("%s: fanotify_fd=%d flags=%x dfd=%d pathname=%p mask=%llx\n", pr_debug("%s: fanotify_fd=%d flags=%x dfd=%d pathname=%p mask=%llx\n",
...@@ -855,11 +845,10 @@ SYSCALL_DEFINE5(fanotify_mark, int, fanotify_fd, unsigned int, flags, ...@@ -855,11 +845,10 @@ SYSCALL_DEFINE5(fanotify_mark, int, fanotify_fd, unsigned int, flags,
mask &= ~FAN_ONDIR; mask &= ~FAN_ONDIR;
} }
#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS if (IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS))
if (mask & ~(FAN_ALL_EVENTS | FAN_ALL_PERM_EVENTS | FAN_EVENT_ON_CHILD)) valid_mask |= FAN_ALL_PERM_EVENTS;
#else
if (mask & ~(FAN_ALL_EVENTS | FAN_EVENT_ON_CHILD)) if (mask & ~valid_mask)
#endif
return -EINVAL; return -EINVAL;
f = fdget(fanotify_fd); f = fdget(fanotify_fd);
...@@ -949,10 +938,10 @@ static int __init fanotify_user_setup(void) ...@@ -949,10 +938,10 @@ static int __init fanotify_user_setup(void)
{ {
fanotify_mark_cache = KMEM_CACHE(fsnotify_mark, SLAB_PANIC); fanotify_mark_cache = KMEM_CACHE(fsnotify_mark, SLAB_PANIC);
fanotify_event_cachep = KMEM_CACHE(fanotify_event_info, SLAB_PANIC); fanotify_event_cachep = KMEM_CACHE(fanotify_event_info, SLAB_PANIC);
#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS if (IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS)) {
fanotify_perm_event_cachep = KMEM_CACHE(fanotify_perm_event_info, fanotify_perm_event_cachep =
SLAB_PANIC); KMEM_CACHE(fanotify_perm_event_info, SLAB_PANIC);
#endif }
return 0; return 0;
} }
......
...@@ -183,11 +183,9 @@ struct fsnotify_group { ...@@ -183,11 +183,9 @@ struct fsnotify_group {
#endif #endif
#ifdef CONFIG_FANOTIFY #ifdef CONFIG_FANOTIFY
struct fanotify_group_private_data { struct fanotify_group_private_data {
#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
/* allows a group to block waiting for a userspace response */ /* allows a group to block waiting for a userspace response */
struct list_head access_list; struct list_head access_list;
wait_queue_head_t access_waitq; wait_queue_head_t access_waitq;
#endif /* CONFIG_FANOTIFY_ACCESS_PERMISSIONS */
int f_flags; int f_flags;
unsigned int max_marks; unsigned int max_marks;
struct user_struct *user; struct user_struct *user;
......
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