We need to report FS_ISDIR flag with MOVE_SELF and DELETE_SELF events for fanotify, because fanotify API requires the user to explicitly request events on directories by FAN_ONDIR flag. inotify never reported IN_ISDIR with those events. It looks like an oversight, but to avoid the risk of breaking existing inotify programs, mask the FS_ISDIR flag out when reprting those events to inotify backend. We also add the FS_ISDIR flag with FS_ATTRIB event in the case of rename over an empty target directory. inotify did not report IN_ISDIR in this case, but it normally does report IN_ISDIR along with IN_ATTRIB event, so in this case, we do not mask out the FS_ISDIR flag. [JK: Simplify the checks in fsnotify_move()]
Showing the changes to include/linux (1 of 2 files). Show all
Unified · Split
| @@ -87,7 +87,12 @@ static inline int fsnotify_perm(struct file *file, int mask) · 86 unmodified lines | ||
| 87 | 87 | */ |
| 88 | 88 | static inline void fsnotify_link_count(struct inode *inode) |
| 89 | 89 | { |
| 90 | − fsnotify(inode, FS_ATTRIB, inode, FSNOTIFY_EVENT_INODE, NULL, 0); | |
| 90 | + __u32 mask = FS_ATTRIB; | |
| 91 | + | |
| 92 | + if (S_ISDIR(inode->i_mode)) | |
| 93 | + mask |= FS_ISDIR; | |
| 94 | + | |
| 95 | + fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); | |
| 91 | 96 | } |
| 92 | 97 | |
| 93 | 98 | /* |
| @@ -95,12 +100,14 @@ static inline void fsnotify_link_count(struct inode *inode) · 1 unmodified line | ||
| 95 | 100 | */ |
| 96 | 101 | static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, |
| 97 | 102 | const unsigned char *old_name, |
| 98 | − int isdir, struct inode *target, struct dentry *moved) | |
| 103 | + int isdir, struct inode *target, | |
| 104 | + struct dentry *moved) | |
| 99 | 105 | { |
| 100 | 106 | struct inode *source = moved->d_inode; |
| 101 | 107 | u32 fs_cookie = fsnotify_get_cookie(); |
| 102 | 108 | __u32 old_dir_mask = FS_MOVED_FROM; |
| 103 | 109 | __u32 new_dir_mask = FS_MOVED_TO; |
| 110 | + __u32 mask = FS_MOVE_SELF; | |
| 104 | 111 | const unsigned char *new_name = moved->d_name.name; |
| 105 | 112 | |
| 106 | 113 | if (old_dir == new_dir) |
| @@ -109,6 +116,7 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, · 2 unmodified lines | ||
| 109 | 116 | if (isdir) { |
| 110 | 117 | old_dir_mask |= FS_ISDIR; |
| 111 | 118 | new_dir_mask |= FS_ISDIR; |
| 119 | + mask |= FS_ISDIR; | |
| 112 | 120 | } |
| 113 | 121 | |
| 114 | 122 | fsnotify(old_dir, old_dir_mask, source, FSNOTIFY_EVENT_INODE, old_name, |
| @@ -120,7 +128,7 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, · 5 unmodified lines | ||
| 120 | 128 | fsnotify_link_count(target); |
| 121 | 129 | |
| 122 | 130 | if (source) |
| 123 | − fsnotify(source, FS_MOVE_SELF, moved->d_inode, FSNOTIFY_EVENT_INODE, NULL, 0); | |
| 131 | + fsnotify(source, mask, source, FSNOTIFY_EVENT_INODE, NULL, 0); | |
| 124 | 132 | audit_inode_child(new_dir, moved, AUDIT_TYPE_CHILD_CREATE); |
| 125 | 133 | } |
| 126 | 134 | |
| @@ -178,7 +186,12 @@ static inline void fsnotify_nameremove(struct dentry *dentry, int isdir) · 51 unmodified lines | ||
| 178 | 186 | */ |
| 179 | 187 | static inline void fsnotify_inoderemove(struct inode *inode) |
| 180 | 188 | { |
| 181 | − fsnotify(inode, FS_DELETE_SELF, inode, FSNOTIFY_EVENT_INODE, NULL, 0); | |
| 189 | + __u32 mask = FS_DELETE_SELF; | |
| 190 | + | |
| 191 | + if (S_ISDIR(inode->i_mode)) | |
| 192 | + mask |= FS_ISDIR; | |
| 193 | + | |
| 194 | + fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); | |
| 182 | 195 | __fsnotify_inode_delete(inode); |
| 183 | 196 | } |
| 184 | 197 | |