diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-30 14:50:37 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-30 14:50:37 -0400 |
| commit | 1792f17b7210280a3d7ff29da9614ba779cfcedb (patch) | |
| tree | e45797137b7fc4877dd60b289d6fb75c6bdcdcf0 | |
| parent | f02a38d86a14b6e544e218d806ffb0442785f62b (diff) | |
| parent | 6bff7eccb0d9bdef4123aad5399e73cbc26683a6 (diff) | |
Merge branch 'for-linus' of git://git.infradead.org/users/eparis/notify
* 'for-linus' of git://git.infradead.org/users/eparis/notify: (22 commits)
Ensure FMODE_NONOTIFY is not set by userspace
make fanotify_read() restartable across signals
fsnotify: remove alignment padding from fsnotify_mark on 64 bit builds
fs/notify/fanotify/fanotify_user.c: fix warnings
fanotify: Fix FAN_CLOSE comments
fanotify: do not recalculate the mask if the ignored mask changed
fanotify: ignore events on directories unless specifically requested
fsnotify: rename FS_IN_ISDIR to FS_ISDIR
fanotify: do not send events for irregular files
fanotify: limit number of listeners per user
fanotify: allow userspace to override max marks
fanotify: limit the number of marks in a single fanotify group
fanotify: allow userspace to override max queue depth
fsnotify: implement a default maximum queue depth
fanotify: ignore fanotify ignore marks if open writers
fanotify: allow userspace to flush all marks
fsnotify: call fsnotify_parent in perm events
fsnotify: correctly handle return codes from listeners
fanotify: use __aligned_u64 in fanotify userspace metadata
fanotify: implement fanotify listener ordering
...
| -rw-r--r-- | fs/notify/Kconfig | 2 | ||||
| -rw-r--r-- | fs/notify/fanotify/fanotify.c | 27 | ||||
| -rw-r--r-- | fs/notify/fanotify/fanotify_user.c | 98 | ||||
| -rw-r--r-- | fs/notify/fsnotify.c | 35 | ||||
| -rw-r--r-- | fs/notify/inode_mark.c | 9 | ||||
| -rw-r--r-- | fs/notify/inotify/inotify_user.c | 2 | ||||
| -rw-r--r-- | fs/notify/vfsmount_mark.c | 6 | ||||
| -rw-r--r-- | include/linux/Kbuild | 1 | ||||
| -rw-r--r-- | include/linux/fanotify.h | 36 | ||||
| -rw-r--r-- | include/linux/fsnotify.h | 38 | ||||
| -rw-r--r-- | include/linux/fsnotify_backend.h | 26 | ||||
| -rw-r--r-- | include/linux/sched.h | 3 |
12 files changed, 219 insertions, 64 deletions
diff --git a/fs/notify/Kconfig b/fs/notify/Kconfig index b388443c3a09..22c629eedd82 100644 --- a/fs/notify/Kconfig +++ b/fs/notify/Kconfig | |||
| @@ -3,4 +3,4 @@ config FSNOTIFY | |||
| 3 | 3 | ||
| 4 | source "fs/notify/dnotify/Kconfig" | 4 | source "fs/notify/dnotify/Kconfig" |
| 5 | source "fs/notify/inotify/Kconfig" | 5 | source "fs/notify/inotify/Kconfig" |
| 6 | #source "fs/notify/fanotify/Kconfig" | 6 | source "fs/notify/fanotify/Kconfig" |
diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 85366c78cc37..b04f88eed09e 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c | |||
| @@ -131,6 +131,7 @@ static int fanotify_handle_event(struct fsnotify_group *group, | |||
| 131 | BUILD_BUG_ON(FAN_Q_OVERFLOW != FS_Q_OVERFLOW); | 131 | BUILD_BUG_ON(FAN_Q_OVERFLOW != FS_Q_OVERFLOW); |
| 132 | BUILD_BUG_ON(FAN_OPEN_PERM != FS_OPEN_PERM); | 132 | BUILD_BUG_ON(FAN_OPEN_PERM != FS_OPEN_PERM); |
| 133 | BUILD_BUG_ON(FAN_ACCESS_PERM != FS_ACCESS_PERM); | 133 | BUILD_BUG_ON(FAN_ACCESS_PERM != FS_ACCESS_PERM); |
| 134 | BUILD_BUG_ON(FAN_ONDIR != FS_ISDIR); | ||
| 134 | 135 | ||
| 135 | pr_debug("%s: group=%p event=%p\n", __func__, group, event); | 136 | pr_debug("%s: group=%p event=%p\n", __func__, group, event); |
| 136 | 137 | ||
| @@ -160,20 +161,21 @@ static bool fanotify_should_send_event(struct fsnotify_group *group, | |||
| 160 | __u32 event_mask, void *data, int data_type) | 161 | __u32 event_mask, void *data, int data_type) |
| 161 | { | 162 | { |
| 162 | __u32 marks_mask, marks_ignored_mask; | 163 | __u32 marks_mask, marks_ignored_mask; |
| 164 | struct path *path = data; | ||
| 163 | 165 | ||
| 164 | pr_debug("%s: group=%p to_tell=%p inode_mark=%p vfsmnt_mark=%p " | 166 | pr_debug("%s: group=%p to_tell=%p inode_mark=%p vfsmnt_mark=%p " |
| 165 | "mask=%x data=%p data_type=%d\n", __func__, group, to_tell, | 167 | "mask=%x data=%p data_type=%d\n", __func__, group, to_tell, |
| 166 | inode_mark, vfsmnt_mark, event_mask, data, data_type); | 168 | inode_mark, vfsmnt_mark, event_mask, data, data_type); |
| 167 | 169 | ||
| 168 | /* sorry, fanotify only gives a damn about files and dirs */ | ||
| 169 | if (!S_ISREG(to_tell->i_mode) && | ||
| 170 | !S_ISDIR(to_tell->i_mode)) | ||
| 171 | return false; | ||
| 172 | |||
| 173 | /* if we don't have enough info to send an event to userspace say no */ | 170 | /* if we don't have enough info to send an event to userspace say no */ |
| 174 | if (data_type != FSNOTIFY_EVENT_PATH) | 171 | if (data_type != FSNOTIFY_EVENT_PATH) |
| 175 | return false; | 172 | return false; |
| 176 | 173 | ||
| 174 | /* sorry, fanotify only gives a damn about files and dirs */ | ||
| 175 | if (!S_ISREG(path->dentry->d_inode->i_mode) && | ||
| 176 | !S_ISDIR(path->dentry->d_inode->i_mode)) | ||
| 177 | return false; | ||
| 178 | |||
| 177 | if (inode_mark && vfsmnt_mark) { | 179 | if (inode_mark && vfsmnt_mark) { |
| 178 | marks_mask = (vfsmnt_mark->mask | inode_mark->mask); | 180 | marks_mask = (vfsmnt_mark->mask | inode_mark->mask); |
| 179 | marks_ignored_mask = (vfsmnt_mark->ignored_mask | inode_mark->ignored_mask); | 181 | marks_ignored_mask = (vfsmnt_mark->ignored_mask | inode_mark->ignored_mask); |
| @@ -194,16 +196,29 @@ static bool fanotify_should_send_event(struct fsnotify_group *group, | |||
| 194 | BUG(); | 196 | BUG(); |
| 195 | } | 197 | } |
| 196 | 198 | ||
| 199 | if (S_ISDIR(path->dentry->d_inode->i_mode) && | ||
| 200 | (marks_ignored_mask & FS_ISDIR)) | ||
| 201 | return false; | ||
| 202 | |||
| 197 | if (event_mask & marks_mask & ~marks_ignored_mask) | 203 | if (event_mask & marks_mask & ~marks_ignored_mask) |
| 198 | return true; | 204 | return true; |
| 199 | 205 | ||
| 200 | return false; | 206 | return false; |
| 201 | } | 207 | } |
| 202 | 208 | ||
| 209 | static void fanotify_free_group_priv(struct fsnotify_group *group) | ||
| 210 | { | ||
| 211 | struct user_struct *user; | ||
| 212 | |||
| 213 | user = group->fanotify_data.user; | ||
| 214 | atomic_dec(&user->fanotify_listeners); | ||
| 215 | free_uid(user); | ||
| 216 | } | ||
| 217 | |||
| 203 | const struct fsnotify_ops fanotify_fsnotify_ops = { | 218 | const struct fsnotify_ops fanotify_fsnotify_ops = { |
| 204 | .handle_event = fanotify_handle_event, | 219 | .handle_event = fanotify_handle_event, |
| 205 | .should_send_event = fanotify_should_send_event, | 220 | .should_send_event = fanotify_should_send_event, |
| 206 | .free_group_priv = NULL, | 221 | .free_group_priv = fanotify_free_group_priv, |
| 207 | .free_event_priv = NULL, | 222 | .free_event_priv = NULL, |
| 208 | .freeing_mark = NULL, | 223 | .freeing_mark = NULL, |
| 209 | }; | 224 | }; |
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index bbcb98e7fcc6..063224812b7e 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c | |||
| @@ -16,6 +16,10 @@ | |||
| 16 | 16 | ||
| 17 | #include <asm/ioctls.h> | 17 | #include <asm/ioctls.h> |
| 18 | 18 | ||
| 19 | #define FANOTIFY_DEFAULT_MAX_EVENTS 16384 | ||
| 20 | #define FANOTIFY_DEFAULT_MAX_MARKS 8192 | ||
| 21 | #define FANOTIFY_DEFAULT_MAX_LISTENERS 128 | ||
| 22 | |||
| 19 | extern const struct fsnotify_ops fanotify_fsnotify_ops; | 23 | extern const struct fsnotify_ops fanotify_fsnotify_ops; |
| 20 | 24 | ||
| 21 | static struct kmem_cache *fanotify_mark_cache __read_mostly; | 25 | static struct kmem_cache *fanotify_mark_cache __read_mostly; |
| @@ -326,7 +330,7 @@ static ssize_t fanotify_read(struct file *file, char __user *buf, | |||
| 326 | ret = -EAGAIN; | 330 | ret = -EAGAIN; |
| 327 | if (file->f_flags & O_NONBLOCK) | 331 | if (file->f_flags & O_NONBLOCK) |
| 328 | break; | 332 | break; |
| 329 | ret = -EINTR; | 333 | ret = -ERESTARTSYS; |
| 330 | if (signal_pending(current)) | 334 | if (signal_pending(current)) |
| 331 | break; | 335 | break; |
| 332 | 336 | ||
| @@ -372,11 +376,10 @@ static ssize_t fanotify_write(struct file *file, const char __user *buf, size_t | |||
| 372 | static int fanotify_release(struct inode *ignored, struct file *file) | 376 | static int fanotify_release(struct inode *ignored, struct file *file) |
| 373 | { | 377 | { |
| 374 | struct fsnotify_group *group = file->private_data; | 378 | struct fsnotify_group *group = file->private_data; |
| 375 | struct fanotify_response_event *re, *lre; | ||
| 376 | |||
| 377 | pr_debug("%s: file=%p group=%p\n", __func__, file, group); | ||
| 378 | 379 | ||
| 379 | #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS | 380 | #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS |
| 381 | struct fanotify_response_event *re, *lre; | ||
| 382 | |||
| 380 | mutex_lock(&group->fanotify_data.access_mutex); | 383 | mutex_lock(&group->fanotify_data.access_mutex); |
| 381 | 384 | ||
| 382 | group->fanotify_data.bypass_perm = true; | 385 | group->fanotify_data.bypass_perm = true; |
| @@ -554,18 +557,24 @@ static __u32 fanotify_mark_add_to_mask(struct fsnotify_mark *fsn_mark, | |||
| 554 | __u32 mask, | 557 | __u32 mask, |
| 555 | unsigned int flags) | 558 | unsigned int flags) |
| 556 | { | 559 | { |
| 557 | __u32 oldmask; | 560 | __u32 oldmask = -1; |
| 558 | 561 | ||
| 559 | spin_lock(&fsn_mark->lock); | 562 | spin_lock(&fsn_mark->lock); |
| 560 | if (!(flags & FAN_MARK_IGNORED_MASK)) { | 563 | if (!(flags & FAN_MARK_IGNORED_MASK)) { |
| 561 | oldmask = fsn_mark->mask; | 564 | oldmask = fsn_mark->mask; |
| 562 | fsnotify_set_mark_mask_locked(fsn_mark, (oldmask | mask)); | 565 | fsnotify_set_mark_mask_locked(fsn_mark, (oldmask | mask)); |
| 563 | } else { | 566 | } else { |
| 564 | oldmask = fsn_mark->ignored_mask; | 567 | __u32 tmask = fsn_mark->ignored_mask | mask; |
| 565 | fsnotify_set_mark_ignored_mask_locked(fsn_mark, (oldmask | mask)); | 568 | fsnotify_set_mark_ignored_mask_locked(fsn_mark, tmask); |
| 566 | if (flags & FAN_MARK_IGNORED_SURV_MODIFY) | 569 | if (flags & FAN_MARK_IGNORED_SURV_MODIFY) |
| 567 | fsn_mark->flags |= FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY; | 570 | fsn_mark->flags |= FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY; |
| 568 | } | 571 | } |
| 572 | |||
| 573 | if (!(flags & FAN_MARK_ONDIR)) { | ||
| 574 | __u32 tmask = fsn_mark->ignored_mask | FAN_ONDIR; | ||
| 575 | fsnotify_set_mark_ignored_mask_locked(fsn_mark, tmask); | ||
| 576 | } | ||
| 577 | |||
| 569 | spin_unlock(&fsn_mark->lock); | 578 | spin_unlock(&fsn_mark->lock); |
| 570 | 579 | ||
| 571 | return mask & ~oldmask; | 580 | return mask & ~oldmask; |
| @@ -582,6 +591,9 @@ static int fanotify_add_vfsmount_mark(struct fsnotify_group *group, | |||
| 582 | if (!fsn_mark) { | 591 | if (!fsn_mark) { |
| 583 | int ret; | 592 | int ret; |
| 584 | 593 | ||
| 594 | if (atomic_read(&group->num_marks) > group->fanotify_data.max_marks) | ||
| 595 | return -ENOSPC; | ||
| 596 | |||
| 585 | fsn_mark = kmem_cache_alloc(fanotify_mark_cache, GFP_KERNEL); | 597 | fsn_mark = kmem_cache_alloc(fanotify_mark_cache, GFP_KERNEL); |
| 586 | if (!fsn_mark) | 598 | if (!fsn_mark) |
| 587 | return -ENOMEM; | 599 | return -ENOMEM; |
| @@ -610,10 +622,23 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group, | |||
| 610 | 622 | ||
| 611 | pr_debug("%s: group=%p inode=%p\n", __func__, group, inode); | 623 | pr_debug("%s: group=%p inode=%p\n", __func__, group, inode); |
| 612 | 624 | ||
| 625 | /* | ||
| 626 | * If some other task has this inode open for write we should not add | ||
| 627 | * an ignored mark, unless that ignored mark is supposed to survive | ||
| 628 | * modification changes anyway. | ||
| 629 | */ | ||
| 630 | if ((flags & FAN_MARK_IGNORED_MASK) && | ||
| 631 | !(flags & FAN_MARK_IGNORED_SURV_MODIFY) && | ||
| 632 | (atomic_read(&inode->i_writecount) > 0)) | ||
| 633 | return 0; | ||
| 634 | |||
| 613 | fsn_mark = fsnotify_find_inode_mark(group, inode); | 635 | fsn_mark = fsnotify_find_inode_mark(group, inode); |
| 614 | if (!fsn_mark) { | 636 | if (!fsn_mark) { |
| 615 | int ret; | 637 | int ret; |
| 616 | 638 | ||
| 639 | if (atomic_read(&group->num_marks) > group->fanotify_data.max_marks) | ||
| 640 | return -ENOSPC; | ||
| 641 | |||
| 617 | fsn_mark = kmem_cache_alloc(fanotify_mark_cache, GFP_KERNEL); | 642 | fsn_mark = kmem_cache_alloc(fanotify_mark_cache, GFP_KERNEL); |
| 618 | if (!fsn_mark) | 643 | if (!fsn_mark) |
| 619 | return -ENOMEM; | 644 | return -ENOMEM; |
| @@ -637,6 +662,7 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) | |||
| 637 | { | 662 | { |
| 638 | struct fsnotify_group *group; | 663 | struct fsnotify_group *group; |
| 639 | int f_flags, fd; | 664 | int f_flags, fd; |
| 665 | struct user_struct *user; | ||
| 640 | 666 | ||
| 641 | pr_debug("%s: flags=%d event_f_flags=%d\n", | 667 | pr_debug("%s: flags=%d event_f_flags=%d\n", |
| 642 | __func__, flags, event_f_flags); | 668 | __func__, flags, event_f_flags); |
| @@ -647,6 +673,12 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) | |||
| 647 | if (flags & ~FAN_ALL_INIT_FLAGS) | 673 | if (flags & ~FAN_ALL_INIT_FLAGS) |
| 648 | return -EINVAL; | 674 | return -EINVAL; |
| 649 | 675 | ||
| 676 | user = get_current_user(); | ||
| 677 | if (atomic_read(&user->fanotify_listeners) > FANOTIFY_DEFAULT_MAX_LISTENERS) { | ||
| 678 | free_uid(user); | ||
| 679 | return -EMFILE; | ||
| 680 | } | ||
| 681 | |||
| 650 | f_flags = O_RDWR | FMODE_NONOTIFY; | 682 | f_flags = O_RDWR | FMODE_NONOTIFY; |
| 651 | if (flags & FAN_CLOEXEC) | 683 | if (flags & FAN_CLOEXEC) |
| 652 | f_flags |= O_CLOEXEC; | 684 | f_flags |= O_CLOEXEC; |
| @@ -658,12 +690,47 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) | |||
| 658 | if (IS_ERR(group)) | 690 | if (IS_ERR(group)) |
| 659 | return PTR_ERR(group); | 691 | return PTR_ERR(group); |
| 660 | 692 | ||
| 693 | group->fanotify_data.user = user; | ||
| 694 | atomic_inc(&user->fanotify_listeners); | ||
| 695 | |||
| 661 | group->fanotify_data.f_flags = event_f_flags; | 696 | group->fanotify_data.f_flags = event_f_flags; |
| 662 | #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS | 697 | #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS |
| 663 | mutex_init(&group->fanotify_data.access_mutex); | 698 | mutex_init(&group->fanotify_data.access_mutex); |
| 664 | init_waitqueue_head(&group->fanotify_data.access_waitq); | 699 | init_waitqueue_head(&group->fanotify_data.access_waitq); |
| 665 | INIT_LIST_HEAD(&group->fanotify_data.access_list); | 700 | INIT_LIST_HEAD(&group->fanotify_data.access_list); |
| 666 | #endif | 701 | #endif |
| 702 | switch (flags & FAN_ALL_CLASS_BITS) { | ||
| 703 | case FAN_CLASS_NOTIF: | ||
| 704 | group->priority = FS_PRIO_0; | ||
| 705 | break; | ||
| 706 | case FAN_CLASS_CONTENT: | ||
| 707 | group->priority = FS_PRIO_1; | ||
| 708 | break; | ||
| 709 | case FAN_CLASS_PRE_CONTENT: | ||
| 710 | group->priority = FS_PRIO_2; | ||
| 711 | break; | ||
| 712 | default: | ||
| 713 | fd = -EINVAL; | ||
| 714 | goto out_put_group; | ||
| 715 | } | ||
| 716 | |||
| 717 | if (flags & FAN_UNLIMITED_QUEUE) { | ||
| 718 | fd = -EPERM; | ||
| 719 | if (!capable(CAP_SYS_ADMIN)) | ||
| 720 | goto out_put_group; | ||
| 721 | group->max_events = UINT_MAX; | ||
| 722 | } else { | ||
| 723 | group->max_events = FANOTIFY_DEFAULT_MAX_EVENTS; | ||
| 724 | } | ||
| 725 | |||
| 726 | if (flags & FAN_UNLIMITED_MARKS) { | ||
| 727 | fd = -EPERM; | ||
| 728 | if (!capable(CAP_SYS_ADMIN)) | ||
| 729 | goto out_put_group; | ||
| 730 | group->fanotify_data.max_marks = UINT_MAX; | ||
| 731 | } else { | ||
| 732 | group->fanotify_data.max_marks = FANOTIFY_DEFAULT_MAX_MARKS; | ||
| 733 | } | ||
| 667 | 734 | ||
| 668 | fd = anon_inode_getfd("[fanotify]", &fanotify_fops, group, f_flags); | 735 | fd = anon_inode_getfd("[fanotify]", &fanotify_fops, group, f_flags); |
| 669 | if (fd < 0) | 736 | if (fd < 0) |
| @@ -704,6 +771,12 @@ SYSCALL_DEFINE(fanotify_mark)(int fanotify_fd, unsigned int flags, | |||
| 704 | default: | 771 | default: |
| 705 | return -EINVAL; | 772 | return -EINVAL; |
| 706 | } | 773 | } |
| 774 | |||
| 775 | if (mask & FAN_ONDIR) { | ||
| 776 | flags |= FAN_MARK_ONDIR; | ||
| 777 | mask &= ~FAN_ONDIR; | ||
| 778 | } | ||
| 779 | |||
| 707 | #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS | 780 | #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS |
| 708 | if (mask & ~(FAN_ALL_EVENTS | FAN_ALL_PERM_EVENTS | FAN_EVENT_ON_CHILD)) | 781 | if (mask & ~(FAN_ALL_EVENTS | FAN_ALL_PERM_EVENTS | FAN_EVENT_ON_CHILD)) |
| 709 | #else | 782 | #else |
| @@ -719,6 +792,16 @@ SYSCALL_DEFINE(fanotify_mark)(int fanotify_fd, unsigned int flags, | |||
| 719 | ret = -EINVAL; | 792 | ret = -EINVAL; |
| 720 | if (unlikely(filp->f_op != &fanotify_fops)) | 793 | if (unlikely(filp->f_op != &fanotify_fops)) |
| 721 | goto fput_and_out; | 794 | goto fput_and_out; |
| 795 | group = filp->private_data; | ||
| 796 | |||
| 797 | /* | ||
| 798 | * group->priority == FS_PRIO_0 == FAN_CLASS_NOTIF. These are not | ||
| 799 | * allowed to set permissions events. | ||
| 800 | */ | ||
| 801 | ret = -EINVAL; | ||
| 802 | if (mask & FAN_ALL_PERM_EVENTS && | ||
| 803 | group->priority == FS_PRIO_0) | ||
| 804 | goto fput_and_out; | ||
| 722 | 805 | ||
| 723 | ret = fanotify_find_path(dfd, pathname, &path, flags); | 806 | ret = fanotify_find_path(dfd, pathname, &path, flags); |
| 724 | if (ret) | 807 | if (ret) |
| @@ -729,7 +812,6 @@ SYSCALL_DEFINE(fanotify_mark)(int fanotify_fd, unsigned int flags, | |||
| 729 | inode = path.dentry->d_inode; | 812 | inode = path.dentry->d_inode; |
| 730 | else | 813 | else |
| 731 | mnt = path.mnt; | 814 | mnt = path.mnt; |
| 732 | group = filp->private_data; | ||
| 733 | 815 | ||
| 734 | /* create/update an inode mark */ | 816 | /* create/update an inode mark */ |
| 735 | switch (flags & (FAN_MARK_ADD | FAN_MARK_REMOVE | FAN_MARK_FLUSH)) { | 817 | switch (flags & (FAN_MARK_ADD | FAN_MARK_REMOVE | FAN_MARK_FLUSH)) { |
diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 4498a208df94..20dc218707ca 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c | |||
| @@ -84,16 +84,17 @@ void __fsnotify_update_child_dentry_flags(struct inode *inode) | |||
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | /* Notify this dentry's parent about a child's events. */ | 86 | /* Notify this dentry's parent about a child's events. */ |
| 87 | void __fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask) | 87 | int __fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask) |
| 88 | { | 88 | { |
| 89 | struct dentry *parent; | 89 | struct dentry *parent; |
| 90 | struct inode *p_inode; | 90 | struct inode *p_inode; |
| 91 | int ret = 0; | ||
| 91 | 92 | ||
| 92 | if (!dentry) | 93 | if (!dentry) |
| 93 | dentry = path->dentry; | 94 | dentry = path->dentry; |
| 94 | 95 | ||
| 95 | if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED)) | 96 | if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED)) |
| 96 | return; | 97 | return 0; |
| 97 | 98 | ||
| 98 | parent = dget_parent(dentry); | 99 | parent = dget_parent(dentry); |
| 99 | p_inode = parent->d_inode; | 100 | p_inode = parent->d_inode; |
| @@ -106,14 +107,16 @@ void __fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask) | |||
| 106 | mask |= FS_EVENT_ON_CHILD; | 107 | mask |= FS_EVENT_ON_CHILD; |
| 107 | 108 | ||
| 108 | if (path) | 109 | if (path) |
| 109 | fsnotify(p_inode, mask, path, FSNOTIFY_EVENT_PATH, | 110 | ret = fsnotify(p_inode, mask, path, FSNOTIFY_EVENT_PATH, |
| 110 | dentry->d_name.name, 0); | 111 | dentry->d_name.name, 0); |
| 111 | else | 112 | else |
| 112 | fsnotify(p_inode, mask, dentry->d_inode, FSNOTIFY_EVENT_INODE, | 113 | ret = fsnotify(p_inode, mask, dentry->d_inode, FSNOTIFY_EVENT_INODE, |
| 113 | dentry->d_name.name, 0); | 114 | dentry->d_name.name, 0); |
| 114 | } | 115 | } |
| 115 | 116 | ||
| 116 | dput(parent); | 117 | dput(parent); |
| 118 | |||
| 119 | return ret; | ||
| 117 | } | 120 | } |
| 118 | EXPORT_SYMBOL_GPL(__fsnotify_parent); | 121 | EXPORT_SYMBOL_GPL(__fsnotify_parent); |
| 119 | 122 | ||
| @@ -252,20 +255,23 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is, | |||
| 252 | 255 | ||
| 253 | if (inode_group > vfsmount_group) { | 256 | if (inode_group > vfsmount_group) { |
| 254 | /* handle inode */ | 257 | /* handle inode */ |
| 255 | send_to_group(to_tell, NULL, inode_mark, NULL, mask, data, | 258 | ret = send_to_group(to_tell, NULL, inode_mark, NULL, mask, data, |
| 256 | data_is, cookie, file_name, &event); | 259 | data_is, cookie, file_name, &event); |
| 257 | /* we didn't use the vfsmount_mark */ | 260 | /* we didn't use the vfsmount_mark */ |
| 258 | vfsmount_group = NULL; | 261 | vfsmount_group = NULL; |
| 259 | } else if (vfsmount_group > inode_group) { | 262 | } else if (vfsmount_group > inode_group) { |
| 260 | send_to_group(to_tell, mnt, NULL, vfsmount_mark, mask, data, | 263 | ret = send_to_group(to_tell, mnt, NULL, vfsmount_mark, mask, data, |
| 261 | data_is, cookie, file_name, &event); | 264 | data_is, cookie, file_name, &event); |
| 262 | inode_group = NULL; | 265 | inode_group = NULL; |
| 263 | } else { | 266 | } else { |
| 264 | send_to_group(to_tell, mnt, inode_mark, vfsmount_mark, | 267 | ret = send_to_group(to_tell, mnt, inode_mark, vfsmount_mark, |
| 265 | mask, data, data_is, cookie, file_name, | 268 | mask, data, data_is, cookie, file_name, |
| 266 | &event); | 269 | &event); |
| 267 | } | 270 | } |
| 268 | 271 | ||
| 272 | if (ret && (mask & ALL_FSNOTIFY_PERM_EVENTS)) | ||
| 273 | goto out; | ||
| 274 | |||
| 269 | if (inode_group) | 275 | if (inode_group) |
| 270 | inode_node = srcu_dereference(inode_node->next, | 276 | inode_node = srcu_dereference(inode_node->next, |
| 271 | &fsnotify_mark_srcu); | 277 | &fsnotify_mark_srcu); |
| @@ -273,7 +279,8 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is, | |||
| 273 | vfsmount_node = srcu_dereference(vfsmount_node->next, | 279 | vfsmount_node = srcu_dereference(vfsmount_node->next, |
| 274 | &fsnotify_mark_srcu); | 280 | &fsnotify_mark_srcu); |
| 275 | } | 281 | } |
| 276 | 282 | ret = 0; | |
| 283 | out: | ||
| 277 | srcu_read_unlock(&fsnotify_mark_srcu, idx); | 284 | srcu_read_unlock(&fsnotify_mark_srcu, idx); |
| 278 | /* | 285 | /* |
| 279 | * fsnotify_create_event() took a reference so the event can't be cleaned | 286 | * fsnotify_create_event() took a reference so the event can't be cleaned |
diff --git a/fs/notify/inode_mark.c b/fs/notify/inode_mark.c index 21ed10660b80..4c29fcf557d1 100644 --- a/fs/notify/inode_mark.c +++ b/fs/notify/inode_mark.c | |||
| @@ -177,7 +177,8 @@ void fsnotify_set_inode_mark_mask_locked(struct fsnotify_mark *mark, | |||
| 177 | * Attach an initialized mark to a given inode. | 177 | * Attach an initialized mark to a given inode. |
| 178 | * These marks may be used for the fsnotify backend to determine which | 178 | * These marks may be used for the fsnotify backend to determine which |
| 179 | * event types should be delivered to which group and for which inodes. These | 179 | * event types should be delivered to which group and for which inodes. These |
| 180 | * marks are ordered according to the group's location in memory. | 180 | * marks are ordered according to priority, highest number first, and then by |
| 181 | * the group's location in memory. | ||
| 181 | */ | 182 | */ |
| 182 | int fsnotify_add_inode_mark(struct fsnotify_mark *mark, | 183 | int fsnotify_add_inode_mark(struct fsnotify_mark *mark, |
| 183 | struct fsnotify_group *group, struct inode *inode, | 184 | struct fsnotify_group *group, struct inode *inode, |
| @@ -211,7 +212,11 @@ int fsnotify_add_inode_mark(struct fsnotify_mark *mark, | |||
| 211 | goto out; | 212 | goto out; |
| 212 | } | 213 | } |
| 213 | 214 | ||
| 214 | if (mark->group < lmark->group) | 215 | if (mark->group->priority < lmark->group->priority) |
| 216 | continue; | ||
| 217 | |||
| 218 | if ((mark->group->priority == lmark->group->priority) && | ||
| 219 | (mark->group < lmark->group)) | ||
| 215 | continue; | 220 | continue; |
| 216 | 221 | ||
| 217 | hlist_add_before_rcu(&mark->i.i_list, &lmark->i.i_list); | 222 | hlist_add_before_rcu(&mark->i.i_list, &lmark->i.i_list); |
diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c index 24edc1185d53..444c305a468c 100644 --- a/fs/notify/inotify/inotify_user.c +++ b/fs/notify/inotify/inotify_user.c | |||
| @@ -862,7 +862,7 @@ static int __init inotify_user_setup(void) | |||
| 862 | BUILD_BUG_ON(IN_Q_OVERFLOW != FS_Q_OVERFLOW); | 862 | BUILD_BUG_ON(IN_Q_OVERFLOW != FS_Q_OVERFLOW); |
| 863 | BUILD_BUG_ON(IN_IGNORED != FS_IN_IGNORED); | 863 | BUILD_BUG_ON(IN_IGNORED != FS_IN_IGNORED); |
| 864 | BUILD_BUG_ON(IN_EXCL_UNLINK != FS_EXCL_UNLINK); | 864 | BUILD_BUG_ON(IN_EXCL_UNLINK != FS_EXCL_UNLINK); |
| 865 | BUILD_BUG_ON(IN_ISDIR != FS_IN_ISDIR); | 865 | BUILD_BUG_ON(IN_ISDIR != FS_ISDIR); |
| 866 | BUILD_BUG_ON(IN_ONESHOT != FS_IN_ONESHOT); | 866 | BUILD_BUG_ON(IN_ONESHOT != FS_IN_ONESHOT); |
| 867 | 867 | ||
| 868 | BUG_ON(hweight32(ALL_INOTIFY_BITS) != 21); | 868 | BUG_ON(hweight32(ALL_INOTIFY_BITS) != 21); |
diff --git a/fs/notify/vfsmount_mark.c b/fs/notify/vfsmount_mark.c index 56772b578fbd..85eebff6d0d7 100644 --- a/fs/notify/vfsmount_mark.c +++ b/fs/notify/vfsmount_mark.c | |||
| @@ -169,7 +169,11 @@ int fsnotify_add_vfsmount_mark(struct fsnotify_mark *mark, | |||
| 169 | goto out; | 169 | goto out; |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | if (mark->group < lmark->group) | 172 | if (mark->group->priority < lmark->group->priority) |
| 173 | continue; | ||
| 174 | |||
| 175 | if ((mark->group->priority == lmark->group->priority) && | ||
| 176 | (mark->group < lmark->group)) | ||
| 173 | continue; | 177 | continue; |
| 174 | 178 | ||
| 175 | hlist_add_before_rcu(&mark->m.m_list, &lmark->m.m_list); | 179 | hlist_add_before_rcu(&mark->m.m_list, &lmark->m.m_list); |
diff --git a/include/linux/Kbuild b/include/linux/Kbuild index 90e3ed3a3144..97319a8fc1e0 100644 --- a/include/linux/Kbuild +++ b/include/linux/Kbuild | |||
| @@ -118,6 +118,7 @@ header-y += eventpoll.h | |||
| 118 | header-y += ext2_fs.h | 118 | header-y += ext2_fs.h |
| 119 | header-y += fadvise.h | 119 | header-y += fadvise.h |
| 120 | header-y += falloc.h | 120 | header-y += falloc.h |
| 121 | header-y += fanotify.h | ||
| 121 | header-y += fb.h | 122 | header-y += fb.h |
| 122 | header-y += fcntl.h | 123 | header-y += fcntl.h |
| 123 | header-y += fd.h | 124 | header-y += fd.h |
diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h index 63531a6b4d2a..0f0121467fc4 100644 --- a/include/linux/fanotify.h +++ b/include/linux/fanotify.h | |||
| @@ -6,18 +6,19 @@ | |||
| 6 | /* the following events that user-space can register for */ | 6 | /* the following events that user-space can register for */ |
| 7 | #define FAN_ACCESS 0x00000001 /* File was accessed */ | 7 | #define FAN_ACCESS 0x00000001 /* File was accessed */ |
| 8 | #define FAN_MODIFY 0x00000002 /* File was modified */ | 8 | #define FAN_MODIFY 0x00000002 /* File was modified */ |
| 9 | #define FAN_CLOSE_WRITE 0x00000008 /* Unwrittable file closed */ | 9 | #define FAN_CLOSE_WRITE 0x00000008 /* Writtable file closed */ |
| 10 | #define FAN_CLOSE_NOWRITE 0x00000010 /* Writtable file closed */ | 10 | #define FAN_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed */ |
| 11 | #define FAN_OPEN 0x00000020 /* File was opened */ | 11 | #define FAN_OPEN 0x00000020 /* File was opened */ |
| 12 | 12 | ||
| 13 | #define FAN_EVENT_ON_CHILD 0x08000000 /* interested in child events */ | ||
| 14 | |||
| 15 | /* FIXME currently Q's have no limit.... */ | ||
| 16 | #define FAN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */ | 13 | #define FAN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */ |
| 17 | 14 | ||
| 18 | #define FAN_OPEN_PERM 0x00010000 /* File open in perm check */ | 15 | #define FAN_OPEN_PERM 0x00010000 /* File open in perm check */ |
| 19 | #define FAN_ACCESS_PERM 0x00020000 /* File accessed in perm check */ | 16 | #define FAN_ACCESS_PERM 0x00020000 /* File accessed in perm check */ |
| 20 | 17 | ||
| 18 | #define FAN_ONDIR 0x40000000 /* event occurred against dir */ | ||
| 19 | |||
| 20 | #define FAN_EVENT_ON_CHILD 0x08000000 /* interested in child events */ | ||
| 21 | |||
| 21 | /* helper events */ | 22 | /* helper events */ |
| 22 | #define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) /* close */ | 23 | #define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) /* close */ |
| 23 | 24 | ||
| @@ -25,7 +26,19 @@ | |||
| 25 | #define FAN_CLOEXEC 0x00000001 | 26 | #define FAN_CLOEXEC 0x00000001 |
| 26 | #define FAN_NONBLOCK 0x00000002 | 27 | #define FAN_NONBLOCK 0x00000002 |
| 27 | 28 | ||
| 28 | #define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK) | 29 | /* These are NOT bitwise flags. Both bits are used togther. */ |
| 30 | #define FAN_CLASS_NOTIF 0x00000000 | ||
| 31 | #define FAN_CLASS_CONTENT 0x00000004 | ||
| 32 | #define FAN_CLASS_PRE_CONTENT 0x00000008 | ||
| 33 | #define FAN_ALL_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | \ | ||
| 34 | FAN_CLASS_PRE_CONTENT) | ||
| 35 | |||
| 36 | #define FAN_UNLIMITED_QUEUE 0x00000010 | ||
| 37 | #define FAN_UNLIMITED_MARKS 0x00000020 | ||
| 38 | |||
| 39 | #define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK | \ | ||
| 40 | FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE |\ | ||
| 41 | FAN_UNLIMITED_MARKS) | ||
| 29 | 42 | ||
| 30 | /* flags used for fanotify_modify_mark() */ | 43 | /* flags used for fanotify_modify_mark() */ |
| 31 | #define FAN_MARK_ADD 0x00000001 | 44 | #define FAN_MARK_ADD 0x00000001 |
| @@ -36,6 +49,10 @@ | |||
| 36 | #define FAN_MARK_IGNORED_MASK 0x00000020 | 49 | #define FAN_MARK_IGNORED_MASK 0x00000020 |
| 37 | #define FAN_MARK_IGNORED_SURV_MODIFY 0x00000040 | 50 | #define FAN_MARK_IGNORED_SURV_MODIFY 0x00000040 |
| 38 | #define FAN_MARK_FLUSH 0x00000080 | 51 | #define FAN_MARK_FLUSH 0x00000080 |
| 52 | #ifdef __KERNEL__ | ||
| 53 | /* not valid from userspace, only kernel internal */ | ||
| 54 | #define FAN_MARK_ONDIR 0x00000100 | ||
| 55 | #endif | ||
| 39 | 56 | ||
| 40 | #define FAN_ALL_MARK_FLAGS (FAN_MARK_ADD |\ | 57 | #define FAN_ALL_MARK_FLAGS (FAN_MARK_ADD |\ |
| 41 | FAN_MARK_REMOVE |\ | 58 | FAN_MARK_REMOVE |\ |
| @@ -43,7 +60,8 @@ | |||
| 43 | FAN_MARK_ONLYDIR |\ | 60 | FAN_MARK_ONLYDIR |\ |
| 44 | FAN_MARK_MOUNT |\ | 61 | FAN_MARK_MOUNT |\ |
| 45 | FAN_MARK_IGNORED_MASK |\ | 62 | FAN_MARK_IGNORED_MASK |\ |
| 46 | FAN_MARK_IGNORED_SURV_MODIFY) | 63 | FAN_MARK_IGNORED_SURV_MODIFY |\ |
| 64 | FAN_MARK_FLUSH) | ||
| 47 | 65 | ||
| 48 | /* | 66 | /* |
| 49 | * All of the events - we build the list by hand so that we can add flags in | 67 | * All of the events - we build the list by hand so that we can add flags in |
| @@ -70,10 +88,10 @@ | |||
| 70 | struct fanotify_event_metadata { | 88 | struct fanotify_event_metadata { |
| 71 | __u32 event_len; | 89 | __u32 event_len; |
| 72 | __u32 vers; | 90 | __u32 vers; |
| 73 | __u64 mask; | 91 | __aligned_u64 mask; |
| 74 | __s32 fd; | 92 | __s32 fd; |
| 75 | __s32 pid; | 93 | __s32 pid; |
| 76 | } __attribute__ ((packed)); | 94 | }; |
| 77 | 95 | ||
| 78 | struct fanotify_response { | 96 | struct fanotify_response { |
| 79 | __s32 fd; | 97 | __s32 fd; |
diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 59d0df43ff9d..5c185fa27089 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h | |||
| @@ -26,12 +26,12 @@ static inline void fsnotify_d_instantiate(struct dentry *dentry, | |||
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | /* Notify this dentry's parent about a child's events. */ | 28 | /* Notify this dentry's parent about a child's events. */ |
| 29 | static inline void fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask) | 29 | static inline int fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask) |
| 30 | { | 30 | { |
| 31 | if (!dentry) | 31 | if (!dentry) |
| 32 | dentry = path->dentry; | 32 | dentry = path->dentry; |
| 33 | 33 | ||
| 34 | __fsnotify_parent(path, dentry, mask); | 34 | return __fsnotify_parent(path, dentry, mask); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | /* simple call site for access decisions */ | 37 | /* simple call site for access decisions */ |
| @@ -40,6 +40,7 @@ static inline int fsnotify_perm(struct file *file, int mask) | |||
| 40 | struct path *path = &file->f_path; | 40 | struct path *path = &file->f_path; |
| 41 | struct inode *inode = path->dentry->d_inode; | 41 | struct inode *inode = path->dentry->d_inode; |
| 42 | __u32 fsnotify_mask = 0; | 42 | __u32 fsnotify_mask = 0; |
| 43 | int ret; | ||
| 43 | 44 | ||
| 44 | if (file->f_mode & FMODE_NONOTIFY) | 45 | if (file->f_mode & FMODE_NONOTIFY) |
| 45 | return 0; | 46 | return 0; |
| @@ -52,6 +53,10 @@ static inline int fsnotify_perm(struct file *file, int mask) | |||
| 52 | else | 53 | else |
| 53 | BUG(); | 54 | BUG(); |
| 54 | 55 | ||
| 56 | ret = fsnotify_parent(path, NULL, fsnotify_mask); | ||
| 57 | if (ret) | ||
| 58 | return ret; | ||
| 59 | |||
| 55 | return fsnotify(inode, fsnotify_mask, path, FSNOTIFY_EVENT_PATH, NULL, 0); | 60 | return fsnotify(inode, fsnotify_mask, path, FSNOTIFY_EVENT_PATH, NULL, 0); |
| 56 | } | 61 | } |
| 57 | 62 | ||
| @@ -93,8 +98,8 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, | |||
| 93 | old_dir_mask |= FS_DN_RENAME; | 98 | old_dir_mask |= FS_DN_RENAME; |
| 94 | 99 | ||
| 95 | if (isdir) { | 100 | if (isdir) { |
| 96 | old_dir_mask |= FS_IN_ISDIR; | 101 | old_dir_mask |= FS_ISDIR; |
| 97 | new_dir_mask |= FS_IN_ISDIR; | 102 | new_dir_mask |= FS_ISDIR; |
| 98 | } | 103 | } |
| 99 | 104 | ||
| 100 | fsnotify(old_dir, old_dir_mask, old_dir, FSNOTIFY_EVENT_INODE, old_name, fs_cookie); | 105 | fsnotify(old_dir, old_dir_mask, old_dir, FSNOTIFY_EVENT_INODE, old_name, fs_cookie); |
| @@ -132,7 +137,7 @@ static inline void fsnotify_nameremove(struct dentry *dentry, int isdir) | |||
| 132 | __u32 mask = FS_DELETE; | 137 | __u32 mask = FS_DELETE; |
| 133 | 138 | ||
| 134 | if (isdir) | 139 | if (isdir) |
| 135 | mask |= FS_IN_ISDIR; | 140 | mask |= FS_ISDIR; |
| 136 | 141 | ||
| 137 | fsnotify_parent(NULL, dentry, mask); | 142 | fsnotify_parent(NULL, dentry, mask); |
| 138 | } | 143 | } |
| @@ -174,7 +179,7 @@ static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct | |||
| 174 | */ | 179 | */ |
| 175 | static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry) | 180 | static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry) |
| 176 | { | 181 | { |
| 177 | __u32 mask = (FS_CREATE | FS_IN_ISDIR); | 182 | __u32 mask = (FS_CREATE | FS_ISDIR); |
| 178 | struct inode *d_inode = dentry->d_inode; | 183 | struct inode *d_inode = dentry->d_inode; |
| 179 | 184 | ||
| 180 | audit_inode_child(dentry, inode); | 185 | audit_inode_child(dentry, inode); |
| @@ -192,7 +197,7 @@ static inline void fsnotify_access(struct file *file) | |||
| 192 | __u32 mask = FS_ACCESS; | 197 | __u32 mask = FS_ACCESS; |
| 193 | 198 | ||
| 194 | if (S_ISDIR(inode->i_mode)) | 199 | if (S_ISDIR(inode->i_mode)) |
| 195 | mask |= FS_IN_ISDIR; | 200 | mask |= FS_ISDIR; |
| 196 | 201 | ||
| 197 | if (!(file->f_mode & FMODE_NONOTIFY)) { | 202 | if (!(file->f_mode & FMODE_NONOTIFY)) { |
| 198 | fsnotify_parent(path, NULL, mask); | 203 | fsnotify_parent(path, NULL, mask); |
| @@ -210,7 +215,7 @@ static inline void fsnotify_modify(struct file *file) | |||
| 210 | __u32 mask = FS_MODIFY; | 215 | __u32 mask = FS_MODIFY; |
| 211 | 216 | ||
| 212 | if (S_ISDIR(inode->i_mode)) | 217 | if (S_ISDIR(inode->i_mode)) |
| 213 | mask |= FS_IN_ISDIR; | 218 | mask |= FS_ISDIR; |
| 214 | 219 | ||
| 215 | if (!(file->f_mode & FMODE_NONOTIFY)) { | 220 | if (!(file->f_mode & FMODE_NONOTIFY)) { |
| 216 | fsnotify_parent(path, NULL, mask); | 221 | fsnotify_parent(path, NULL, mask); |
| @@ -228,12 +233,13 @@ static inline void fsnotify_open(struct file *file) | |||
| 228 | __u32 mask = FS_OPEN; | 233 | __u32 mask = FS_OPEN; |
| 229 | 234 | ||
| 230 | if (S_ISDIR(inode->i_mode)) | 235 | if (S_ISDIR(inode->i_mode)) |
| 231 | mask |= FS_IN_ISDIR; | 236 | mask |= FS_ISDIR; |
| 232 | 237 | ||
| 233 | if (!(file->f_mode & FMODE_NONOTIFY)) { | 238 | /* FMODE_NONOTIFY must never be set from user */ |
| 234 | fsnotify_parent(path, NULL, mask); | 239 | file->f_mode &= ~FMODE_NONOTIFY; |
| 235 | fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0); | 240 | |
| 236 | } | 241 | fsnotify_parent(path, NULL, mask); |
| 242 | fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0); | ||
| 237 | } | 243 | } |
| 238 | 244 | ||
| 239 | /* | 245 | /* |
| @@ -247,7 +253,7 @@ static inline void fsnotify_close(struct file *file) | |||
| 247 | __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE; | 253 | __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE; |
| 248 | 254 | ||
| 249 | if (S_ISDIR(inode->i_mode)) | 255 | if (S_ISDIR(inode->i_mode)) |
| 250 | mask |= FS_IN_ISDIR; | 256 | mask |= FS_ISDIR; |
| 251 | 257 | ||
| 252 | if (!(file->f_mode & FMODE_NONOTIFY)) { | 258 | if (!(file->f_mode & FMODE_NONOTIFY)) { |
| 253 | fsnotify_parent(path, NULL, mask); | 259 | fsnotify_parent(path, NULL, mask); |
| @@ -264,7 +270,7 @@ static inline void fsnotify_xattr(struct dentry *dentry) | |||
| 264 | __u32 mask = FS_ATTRIB; | 270 | __u32 mask = FS_ATTRIB; |
| 265 | 271 | ||
| 266 | if (S_ISDIR(inode->i_mode)) | 272 | if (S_ISDIR(inode->i_mode)) |
| 267 | mask |= FS_IN_ISDIR; | 273 | mask |= FS_ISDIR; |
| 268 | 274 | ||
| 269 | fsnotify_parent(NULL, dentry, mask); | 275 | fsnotify_parent(NULL, dentry, mask); |
| 270 | fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); | 276 | fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); |
| @@ -299,7 +305,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid) | |||
| 299 | 305 | ||
| 300 | if (mask) { | 306 | if (mask) { |
| 301 | if (S_ISDIR(inode->i_mode)) | 307 | if (S_ISDIR(inode->i_mode)) |
| 302 | mask |= FS_IN_ISDIR; | 308 | mask |= FS_ISDIR; |
| 303 | 309 | ||
| 304 | fsnotify_parent(NULL, dentry, mask); | 310 | fsnotify_parent(NULL, dentry, mask); |
| 305 | fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); | 311 | fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); |
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index e40190d16878..0a68f924f06f 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h | |||
| @@ -45,7 +45,7 @@ | |||
| 45 | #define FS_ACCESS_PERM 0x00020000 /* access event in a permissions hook */ | 45 | #define FS_ACCESS_PERM 0x00020000 /* access event in a permissions hook */ |
| 46 | 46 | ||
| 47 | #define FS_EXCL_UNLINK 0x04000000 /* do not send events if object is unlinked */ | 47 | #define FS_EXCL_UNLINK 0x04000000 /* do not send events if object is unlinked */ |
| 48 | #define FS_IN_ISDIR 0x40000000 /* event occurred against dir */ | 48 | #define FS_ISDIR 0x40000000 /* event occurred against dir */ |
| 49 | #define FS_IN_ONESHOT 0x80000000 /* only send event once */ | 49 | #define FS_IN_ONESHOT 0x80000000 /* only send event once */ |
| 50 | 50 | ||
| 51 | #define FS_DN_RENAME 0x10000000 /* file renamed */ | 51 | #define FS_DN_RENAME 0x10000000 /* file renamed */ |
| @@ -64,13 +64,15 @@ | |||
| 64 | 64 | ||
| 65 | #define FS_MOVE (FS_MOVED_FROM | FS_MOVED_TO) | 65 | #define FS_MOVE (FS_MOVED_FROM | FS_MOVED_TO) |
| 66 | 66 | ||
| 67 | #define ALL_FSNOTIFY_PERM_EVENTS (FS_OPEN_PERM | FS_ACCESS_PERM) | ||
| 68 | |||
| 67 | #define ALL_FSNOTIFY_EVENTS (FS_ACCESS | FS_MODIFY | FS_ATTRIB | \ | 69 | #define ALL_FSNOTIFY_EVENTS (FS_ACCESS | FS_MODIFY | FS_ATTRIB | \ |
| 68 | FS_CLOSE_WRITE | FS_CLOSE_NOWRITE | FS_OPEN | \ | 70 | FS_CLOSE_WRITE | FS_CLOSE_NOWRITE | FS_OPEN | \ |
| 69 | FS_MOVED_FROM | FS_MOVED_TO | FS_CREATE | \ | 71 | FS_MOVED_FROM | FS_MOVED_TO | FS_CREATE | \ |
| 70 | FS_DELETE | FS_DELETE_SELF | FS_MOVE_SELF | \ | 72 | FS_DELETE | FS_DELETE_SELF | FS_MOVE_SELF | \ |
| 71 | FS_UNMOUNT | FS_Q_OVERFLOW | FS_IN_IGNORED | \ | 73 | FS_UNMOUNT | FS_Q_OVERFLOW | FS_IN_IGNORED | \ |
| 72 | FS_OPEN_PERM | FS_ACCESS_PERM | FS_EXCL_UNLINK | \ | 74 | FS_OPEN_PERM | FS_ACCESS_PERM | FS_EXCL_UNLINK | \ |
| 73 | FS_IN_ISDIR | FS_IN_ONESHOT | FS_DN_RENAME | \ | 75 | FS_ISDIR | FS_IN_ONESHOT | FS_DN_RENAME | \ |
| 74 | FS_DN_MULTISHOT | FS_EVENT_ON_CHILD) | 76 | FS_DN_MULTISHOT | FS_EVENT_ON_CHILD) |
| 75 | 77 | ||
| 76 | struct fsnotify_group; | 78 | struct fsnotify_group; |
| @@ -129,6 +131,14 @@ struct fsnotify_group { | |||
| 129 | wait_queue_head_t notification_waitq; /* read() on the notification file blocks on this waitq */ | 131 | wait_queue_head_t notification_waitq; /* read() on the notification file blocks on this waitq */ |
| 130 | unsigned int q_len; /* events on the queue */ | 132 | unsigned int q_len; /* events on the queue */ |
| 131 | unsigned int max_events; /* maximum events allowed on the list */ | 133 | unsigned int max_events; /* maximum events allowed on the list */ |
| 134 | /* | ||
| 135 | * Valid fsnotify group priorities. Events are send in order from highest | ||
| 136 | * priority to lowest priority. We default to the lowest priority. | ||
| 137 | */ | ||
| 138 | #define FS_PRIO_0 0 /* normal notifiers, no permissions */ | ||
| 139 | #define FS_PRIO_1 1 /* fanotify content based access control */ | ||
| 140 | #define FS_PRIO_2 2 /* fanotify pre-content access */ | ||
| 141 | unsigned int priority; | ||
| 132 | 142 | ||
| 133 | /* stores all fastpath marks assoc with this group so they can be cleaned on unregister */ | 143 | /* stores all fastpath marks assoc with this group so they can be cleaned on unregister */ |
| 134 | spinlock_t mark_lock; /* protect marks_list */ | 144 | spinlock_t mark_lock; /* protect marks_list */ |
| @@ -159,6 +169,8 @@ struct fsnotify_group { | |||
| 159 | bool bypass_perm; /* protected by access_mutex */ | 169 | bool bypass_perm; /* protected by access_mutex */ |
| 160 | #endif /* CONFIG_FANOTIFY_ACCESS_PERMISSIONS */ | 170 | #endif /* CONFIG_FANOTIFY_ACCESS_PERMISSIONS */ |
| 161 | int f_flags; | 171 | int f_flags; |
| 172 | unsigned int max_marks; | ||
| 173 | struct user_struct *user; | ||
| 162 | } fanotify_data; | 174 | } fanotify_data; |
| 163 | #endif /* CONFIG_FANOTIFY */ | 175 | #endif /* CONFIG_FANOTIFY */ |
| 164 | }; | 176 | }; |
| @@ -275,8 +287,8 @@ struct fsnotify_mark { | |||
| 275 | struct fsnotify_inode_mark i; | 287 | struct fsnotify_inode_mark i; |
| 276 | struct fsnotify_vfsmount_mark m; | 288 | struct fsnotify_vfsmount_mark m; |
| 277 | }; | 289 | }; |
| 278 | __u32 ignored_mask; /* events types to ignore */ | ||
| 279 | struct list_head free_g_list; /* tmp list used when freeing this mark */ | 290 | struct list_head free_g_list; /* tmp list used when freeing this mark */ |
| 291 | __u32 ignored_mask; /* events types to ignore */ | ||
| 280 | #define FSNOTIFY_MARK_FLAG_INODE 0x01 | 292 | #define FSNOTIFY_MARK_FLAG_INODE 0x01 |
| 281 | #define FSNOTIFY_MARK_FLAG_VFSMOUNT 0x02 | 293 | #define FSNOTIFY_MARK_FLAG_VFSMOUNT 0x02 |
| 282 | #define FSNOTIFY_MARK_FLAG_OBJECT_PINNED 0x04 | 294 | #define FSNOTIFY_MARK_FLAG_OBJECT_PINNED 0x04 |
| @@ -294,7 +306,7 @@ struct fsnotify_mark { | |||
| 294 | /* main fsnotify call to send events */ | 306 | /* main fsnotify call to send events */ |
| 295 | extern int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is, | 307 | extern int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is, |
| 296 | const unsigned char *name, u32 cookie); | 308 | const unsigned char *name, u32 cookie); |
| 297 | extern void __fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask); | 309 | extern int __fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask); |
| 298 | extern void __fsnotify_inode_delete(struct inode *inode); | 310 | extern void __fsnotify_inode_delete(struct inode *inode); |
| 299 | extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt); | 311 | extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt); |
| 300 | extern u32 fsnotify_get_cookie(void); | 312 | extern u32 fsnotify_get_cookie(void); |
| @@ -423,8 +435,10 @@ static inline int fsnotify(struct inode *to_tell, __u32 mask, void *data, int da | |||
| 423 | return 0; | 435 | return 0; |
| 424 | } | 436 | } |
| 425 | 437 | ||
| 426 | static inline void __fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask) | 438 | static inline int __fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask) |
| 427 | {} | 439 | { |
| 440 | return 0; | ||
| 441 | } | ||
| 428 | 442 | ||
| 429 | static inline void __fsnotify_inode_delete(struct inode *inode) | 443 | static inline void __fsnotify_inode_delete(struct inode *inode) |
| 430 | {} | 444 | {} |
diff --git a/include/linux/sched.h b/include/linux/sched.h index f53cdf216cef..d0036e52a24a 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
| @@ -672,6 +672,9 @@ struct user_struct { | |||
| 672 | atomic_t inotify_watches; /* How many inotify watches does this user have? */ | 672 | atomic_t inotify_watches; /* How many inotify watches does this user have? */ |
| 673 | atomic_t inotify_devs; /* How many inotify devs does this user have opened? */ | 673 | atomic_t inotify_devs; /* How many inotify devs does this user have opened? */ |
| 674 | #endif | 674 | #endif |
| 675 | #ifdef CONFIG_FANOTIFY | ||
| 676 | atomic_t fanotify_listeners; | ||
| 677 | #endif | ||
| 675 | #ifdef CONFIG_EPOLL | 678 | #ifdef CONFIG_EPOLL |
| 676 | atomic_t epoll_watches; /* The number of file descriptors currently watched */ | 679 | atomic_t epoll_watches; /* The number of file descriptors currently watched */ |
| 677 | #endif | 680 | #endif |
