Skip to content

Commit f874e1a

Browse files
committed
inotify: force inotify and fsnotify use same bits
inotify uses bits called IN_* and fsnotify uses bits called FS_*. These need to line up. This patch adds build time checks to make sure noone can change these bits so they are not the same. Signed-off-by: Eric Paris <eparis@redhat.com>
1 parent 8c1934c commit f874e1a

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

fs/notify/inotify/inotify_user.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,27 @@ SYSCALL_DEFINE2(inotify_rm_watch, int, fd, __s32, wd)
839839
*/
840840
static int __init inotify_user_setup(void)
841841
{
842+
BUILD_BUG_ON(IN_ACCESS != FS_ACCESS);
843+
BUILD_BUG_ON(IN_MODIFY != FS_MODIFY);
844+
BUILD_BUG_ON(IN_ATTRIB != FS_ATTRIB);
845+
BUILD_BUG_ON(IN_CLOSE_WRITE != FS_CLOSE_WRITE);
846+
BUILD_BUG_ON(IN_CLOSE_NOWRITE != FS_CLOSE_NOWRITE);
847+
BUILD_BUG_ON(IN_OPEN != FS_OPEN);
848+
BUILD_BUG_ON(IN_MOVED_FROM != FS_MOVED_FROM);
849+
BUILD_BUG_ON(IN_MOVED_TO != FS_MOVED_TO);
850+
BUILD_BUG_ON(IN_CREATE != FS_CREATE);
851+
BUILD_BUG_ON(IN_DELETE != FS_DELETE);
852+
BUILD_BUG_ON(IN_DELETE_SELF != FS_DELETE_SELF);
853+
BUILD_BUG_ON(IN_MOVE_SELF != FS_MOVE_SELF);
854+
BUILD_BUG_ON(IN_UNMOUNT != FS_UNMOUNT);
855+
BUILD_BUG_ON(IN_Q_OVERFLOW != FS_Q_OVERFLOW);
856+
BUILD_BUG_ON(IN_IGNORED != FS_IN_IGNORED);
857+
BUILD_BUG_ON(IN_EXCL_UNLINK != FS_EXCL_UNLINK);
858+
BUILD_BUG_ON(IN_ISDIR != FS_IN_ISDIR);
859+
BUILD_BUG_ON(IN_ONESHOT != FS_IN_ONESHOT);
860+
861+
BUG_ON(hweight32(ALL_INOTIFY_BITS) != 21);
862+
842863
inotify_inode_mark_cachep = KMEM_CACHE(inotify_inode_mark, SLAB_PANIC);
843864
event_priv_cachep = KMEM_CACHE(inotify_event_private_data, SLAB_PANIC);
844865

include/linux/inotify.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ struct inotify_event {
7373
#ifdef __KERNEL__
7474
#include <linux/sysctl.h>
7575
extern struct ctl_table inotify_table[]; /* for sysctl */
76+
77+
#define ALL_INOTIFY_BITS (IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | \
78+
IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM | \
79+
IN_MOVED_TO | IN_CREATE | IN_DELETE | \
80+
IN_DELETE_SELF | IN_MOVE_SELF | IN_UNMOUNT | \
81+
IN_Q_OVERFLOW | IN_IGNORED | IN_ONLYDIR | \
82+
IN_DONT_FOLLOW | IN_EXCL_UNLINK | IN_MASK_ADD | \
83+
IN_ISDIR | IN_ONESHOT)
84+
7685
#endif
7786

7887
#endif /* _LINUX_INOTIFY_H */

0 commit comments

Comments
 (0)