Skip to content

Commit b1085ba

Browse files
LinoSanfilippo333eparis
authored andcommitted
fanotify: if set by user unset FMODE_NONOTIFY before fsnotify_perm() is called
Unsetting FMODE_NONOTIFY in fsnotify_open() is too late, since fsnotify_perm() is called before. If FMODE_NONOTIFY is set fsnotify_perm() will skip permission checks, so a user can still disable permission checks by setting this flag in an open() call. This patch corrects this by unsetting the flag before fsnotify_perm is called. Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de> Signed-off-by: Eric Paris <eparis@redhat.com>
1 parent 88d60c3 commit b1085ba

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

fs/namei.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,9 @@ struct file *do_filp_open(int dfd, const char *pathname,
17481748
if (!(open_flag & O_CREAT))
17491749
mode = 0;
17501750

1751+
/* Must never be set by userspace */
1752+
open_flag &= ~FMODE_NONOTIFY;
1753+
17511754
/*
17521755
* O_SYNC is implemented as __O_SYNC|O_DSYNC. As many places only
17531756
* check for O_DSYNC if the need any syncing at all we enforce it's

include/linux/fsnotify.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,6 @@ static inline void fsnotify_open(struct file *file)
235235
if (S_ISDIR(inode->i_mode))
236236
mask |= FS_ISDIR;
237237

238-
/* FMODE_NONOTIFY must never be set from user */
239-
file->f_mode &= ~FMODE_NONOTIFY;
240-
241238
fsnotify_parent(path, NULL, mask);
242239
fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
243240
}

0 commit comments

Comments
 (0)