|
@@ -143,7 +143,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)
|
|
{
|
|
{
|
|
@@ -200,7 +199,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,
|
|
@@ -222,10 +220,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 (event->mask & FAN_ALL_PERM_EVENTS)
|
|
|
|
|
|
+ if (fanotify_is_perm_event(event->mask))
|
|
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);
|
|
@@ -310,10 +306,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);
|
|
@@ -323,7 +318,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;
|
|
@@ -339,11 +333,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))
|
|
@@ -359,16 +355,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;
|
|
|
|
|
|
@@ -404,14 +395,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);
|
|
@@ -769,10 +760,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;
|
|
@@ -826,6 +815,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",
|
|
@@ -856,11 +846,10 @@ SYSCALL_DEFINE5(fanotify_mark, int, fanotify_fd, unsigned int, flags,
|
|
mask &= ~FAN_ONDIR;
|
|
mask &= ~FAN_ONDIR;
|
|
}
|
|
}
|
|
|
|
|
|
-#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
|
|
|
|
- if (mask & ~(FAN_ALL_EVENTS | FAN_ALL_PERM_EVENTS | FAN_EVENT_ON_CHILD))
|
|
|
|
-#else
|
|
|
|
- if (mask & ~(FAN_ALL_EVENTS | FAN_EVENT_ON_CHILD))
|
|
|
|
-#endif
|
|
|
|
|
|
+ if (IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS))
|
|
|
|
+ valid_mask |= FAN_ALL_PERM_EVENTS;
|
|
|
|
+
|
|
|
|
+ if (mask & ~valid_mask)
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
|
|
|
|
f = fdget(fanotify_fd);
|
|
f = fdget(fanotify_fd);
|
|
@@ -950,10 +939,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
|
|
|
|
- fanotify_perm_event_cachep = KMEM_CACHE(fanotify_perm_event_info,
|
|
|
|
- SLAB_PANIC);
|
|
|
|
-#endif
|
|
|
|
|
|
+ if (IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS)) {
|
|
|
|
+ fanotify_perm_event_cachep =
|
|
|
|
+ KMEM_CACHE(fanotify_perm_event_info, SLAB_PANIC);
|
|
|
|
+ }
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|