Skip to content

Commit 85af5d9

Browse files
amir73iljankara
authored andcommitted
fanotify: use FAN_EVENT_ON_CHILD as implicit flag on sb/mount/non-dir marks
Up to now, fanotify allowed to set the FAN_EVENT_ON_CHILD flag on sb/mount marks and non-directory inode mask, but the flag was ignored. Mask out the flag if it is provided by user on sb/mount/non-dir marks and define it as an implicit flag that cannot be removed by user. This flag is going to be used internally to request for events with parent and name info. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent 4ed6814 commit 85af5d9

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

fs/notify/fanotify/fanotify_user.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
10501050
unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS;
10511051
bool ignored = flags & FAN_MARK_IGNORED_MASK;
10521052
unsigned int obj_type, fid_mode;
1053+
u32 umask = 0;
10531054
int ret;
10541055

10551056
pr_debug("%s: fanotify_fd=%d flags=%x dfd=%d pathname=%p mask=%llx\n",
@@ -1167,6 +1168,12 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
11671168
else
11681169
mnt = path.mnt;
11691170

1171+
/* Mask out FAN_EVENT_ON_CHILD flag for sb/mount/non-dir marks */
1172+
if (mnt || !S_ISDIR(inode->i_mode)) {
1173+
mask &= ~FAN_EVENT_ON_CHILD;
1174+
umask = FAN_EVENT_ON_CHILD;
1175+
}
1176+
11701177
/* create/update an inode mark */
11711178
switch (flags & (FAN_MARK_ADD | FAN_MARK_REMOVE)) {
11721179
case FAN_MARK_ADD:
@@ -1183,13 +1190,13 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
11831190
case FAN_MARK_REMOVE:
11841191
if (mark_type == FAN_MARK_MOUNT)
11851192
ret = fanotify_remove_vfsmount_mark(group, mnt, mask,
1186-
flags, 0);
1193+
flags, umask);
11871194
else if (mark_type == FAN_MARK_FILESYSTEM)
11881195
ret = fanotify_remove_sb_mark(group, mnt->mnt_sb, mask,
1189-
flags, 0);
1196+
flags, umask);
11901197
else
11911198
ret = fanotify_remove_inode_mark(group, inode, mask,
1192-
flags, 0);
1199+
flags, umask);
11931200
break;
11941201
default:
11951202
ret = -EINVAL;

0 commit comments

Comments
 (0)