fanotify: Disallow permission events for proc filesystem
Subsystems (3)
Jan Kara
maintainerPATCH 1/1 fanotify: Disallow permission events for proc filesystem
Proc filesystem has special locking rules for various files. Thus fanotify which opens files on event delivery can easily deadlock against another process that waits for fanotify permission event to be handled. Since permission events on /proc have doubtful value anyway, just disallow them.
--- fs/notify/fanotify/fanotify_user.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
fs/notify/fanotify/fanotify_user.c +20 -0
@@ -920,6 +920,20 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)return 0 ; } +static int fanotify_events_supported (struct path *path,__u64 mask) +{ +/* +* Proc is special and various files have special locking rules so +* fanotify permission events have high chances of deadlocking the +* system. Just disallow them. +*/ +if (mask &FANOTIFY_PERM_EVENTS && + !strcmp (path->mnt->mnt_sb->s_type->name,"proc" )) { +return -EOPNOTSUPP ; + } +return 0 ; +} +static int do_fanotify_mark (int fanotify_fd,unsigned int flags,__u64 mask,int dfd,const char __user *pathname) {
@@ -1018,6 +1032,12 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,if (ret) goto fput_and_out; +if (flags &FAN_MARK_ADD ) { + ret =fanotify_events_supported (&path, mask); +if (ret) + goto path_put_and_out; + } +if (FAN_GROUP_FLAG (group,FAN_REPORT_FID )) { ret =fanotify_test_fid (&path, &__fsid);if (ret)
Signature · 1 line
2.16.4
Amir Goldstein
reviewerQuoted 7 lines · Jan Kara
Proc filesystem has special locking rules for various files. Thus fanotify which opens files on event delivery can easily deadlock against another process that waits for fanotify permission event to be handled. Since permission events on /proc have doubtful value anyway, just disallow them.
Let's add context:
Quoted 12 lines
Signed-off-by Jan Kara <[email protected]>--- fs/notify/fanotify/fanotify_user.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)fs/notify/fanotify/fanotify_user.c +0
-0@@ -920,6 +920,20 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)return 0 ; }
fs/notify/fanotify/fanotify_user.c static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) · line 931
Quoted 10 lines
fs/notify/fanotify/fanotify_user.c +9
-0+static int fanotify_events_supported (struct path *path,__u64 mask) +{ +/* +* Proc is special and various files have special locking rules so +* fanotify permission events have high chances of deadlocking the +* system. Just disallow them. +*/ +if (mask &FANOTIFY_PERM_EVENTS && + !strcmp (path->mnt->mnt_sb->s_type->name,"proc" )) {
Better use an SB_I_ flag to forbid permission events on fs?
fs/notify/fanotify/fanotify_user.c static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) · line 932
Quoted 1 line
fs/notify/fanotify/fanotify_user.c +1
-0+return -EOPNOTSUPP ;
I would go with EINVAL following precedent of per filesystem flags check on rename(2), but not insisting.
Anyway, following Matthew's man page update for FAN_REPORT_FID, we should also add this as reason for EOPNOTSUPP/EINVAL.
Thanks,
Amir.
Jan Kara
maintainerQuoted 11 lines · Amir Goldstein
Quoted 7 lines · Jan Kara
Proc filesystem has special locking rules for various files. Thus fanotify which opens files on event delivery can easily deadlock against another process that waits for fanotify permission event to be handled. Since permission events on /proc have doubtful value anyway, just disallow them.
Let's add context:
OK, will add.
Quoted 13 lines
Quoted 13 lines
Signed-off-by Jan Kara <[email protected]>--- fs/notify/fanotify/fanotify_user.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)fs/notify/fanotify/fanotify_user.c +0
-0@@ -920,6 +920,20 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)return 0 ; }
Quoted 11 lines
fs/notify/fanotify/fanotify_user.c static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) · line 931
Quoted 9 lines
fs/notify/fanotify/fanotify_user.c +9
-0+static int fanotify_events_supported (struct path *path,__u64 mask) +{ +/* +* Proc is special and various files have special locking rules so +* fanotify permission events have high chances of deadlocking the +* system. Just disallow them. +*/ +if (mask &FANOTIFY_PERM_EVENTS && + !strcmp (path->mnt->mnt_sb->s_type->name,"proc" )) {Better use an
SB_I_flag to forbid permission events on fs?
So checking s_type->name indeed felt dirty. I don't think we need a superblock flag though. I'll probably just go with FS_XXX flag in file_system_type.
Quoted 5 lines
fs/notify/fanotify/fanotify_user.c static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) · line 932
Quoted 2 lines
fs/notify/fanotify/fanotify_user.c +1
-0+return -EOPNOTSUPP ;I would go with EINVAL following precedent of per filesystem flags check on rename(2), but not insisting.
I was undecided between EOPNOTSUPP and EINVAL. So let's go with EINVAL.
Quoted 2 lines
Anyway, following Matthew's man page update for
FAN_REPORT_FID, we should also add this as reason for EOPNOTSUPP/EINVAL.
Good point.
Thanks for review!
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 40 lines · Jan Kara
Quoted 11 lines · Amir Goldstein
Quoted 7 lines · Jan Kara
Proc filesystem has special locking rules for various files. Thus fanotify which opens files on event delivery can easily deadlock against another process that waits for fanotify permission event to be handled. Since permission events on /proc have doubtful value anyway, just disallow them.
Let's add context:
OK, will add.
Quoted 13 lines
Quoted 13 lines
Signed-off-by Jan Kara <[email protected]>--- fs/notify/fanotify/fanotify_user.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)fs/notify/fanotify/fanotify_user.c +0
-0@@ -920,6 +920,20 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)return 0 ; }Quoted 11 lines
fs/notify/fanotify/fanotify_user.c static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) · line 931
Quoted 9 lines
fs/notify/fanotify/fanotify_user.c +9
-0+static int fanotify_events_supported (struct path *path,__u64 mask) +{ +/* +* Proc is special and various files have special locking rules so +* fanotify permission events have high chances of deadlocking the +* system. Just disallow them. +*/ +if (mask &FANOTIFY_PERM_EVENTS && + !strcmp (path->mnt->mnt_sb->s_type->name,"proc" )) {Better use an
SB_I_flag to forbid permission events on fs?
Quoted 3 lines
So checking
s_type->nameindeed felt dirty. I don't think we need a superblock flag though. I'll probably just go withFS_XXXflag infile_system_type.
Would the same apply for some files that backed by sysfs and reside in /sys?
Quoted 7 lines
Quoted 5 lines
fs/notify/fanotify/fanotify_user.c static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) · line 932
Quoted 2 lines
fs/notify/fanotify/fanotify_user.c +1
-0+return -EOPNOTSUPP ;I would go with EINVAL following precedent of per filesystem flags check on rename(2), but not insisting.
I was undecided between EOPNOTSUPP and EINVAL. So let's go with EINVAL.
I was also thinking that EINVAL makes more sense in this particular case.
Quoted 4 lines
Quoted 2 lines
Anyway, following Matthew's man page update for
FAN_REPORT_FID, we should also add this as reason for EOPNOTSUPP/EINVAL.Good point.
I've followed up Michael in regards to the FAN_REPORT_FID patch series, but no response as of yet. I'm happy to write the changes for this one if you like?
Signature · 1 line
Matthew Bobrowski
Jan Kara
maintainerQuoted 27 lines · Matthew Bobrowski
Quoted 26 lines · Jan Kara
Quoted 24 lines · Amir Goldstein
Quoted 12 lines
Signed-off-by Jan Kara <[email protected]>--- fs/notify/fanotify/fanotify_user.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)fs/notify/fanotify/fanotify_user.c +0
-0@@ -920,6 +920,20 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)return 0 ; }fs/notify/fanotify/fanotify_user.c static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) · line 931
Quoted 10 lines
fs/notify/fanotify/fanotify_user.c +9
-0+static int fanotify_events_supported (struct path *path,__u64 mask) +{ +/* +* Proc is special and various files have special locking rules so +* fanotify permission events have high chances of deadlocking the +* system. Just disallow them. +*/ +if (mask &FANOTIFY_PERM_EVENTS && + !strcmp (path->mnt->mnt_sb->s_type->name,"proc" )) {Better use an
SB_I_flag to forbid permission events on fs?
Quoted 6 lines
Quoted 3 lines
So checking
s_type->nameindeed felt dirty. I don't think we need a superblock flag though. I'll probably just go withFS_XXXflag infile_system_type.Would the same apply for some files that backed by sysfs and reside in /sys?
So far I'm not aware of similar easy to trigger deadlocks with sysfs. So I opted for a cautious path and disabled permission events only for proc. We'll see how that fares.
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
fs/notify/fanotify/fanotify_user.c static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) · line 932
Quoted 1 line
fs/notify/fanotify/fanotify_user.c +1
-0+return -EOPNOTSUPP ;I would go with EINVAL following precedent of per filesystem flags check on rename(2), but not insisting.
I was undecided between EOPNOTSUPP and EINVAL. So let's go with EINVAL.
I was also thinking that EINVAL makes more sense in this particular case.
Good, that's what I used in v2.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Anyway, following Matthew's man page update for
FAN_REPORT_FID, we should also add this as reason for EOPNOTSUPP/EINVAL.Good point.
I've followed up Michael in regards to the
FAN_REPORT_FIDpatch series, but no response as of yet. I'm happy to write the changes for this one if you like?
If you had time for that, that would be nice. Thanks!
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 54 lines · Jan Kara
Quoted 27 lines · Matthew Bobrowski
Quoted 26 lines · Jan Kara
Quoted 24 lines · Amir Goldstein
Quoted 12 lines
Signed-off-by Jan Kara <[email protected]>--- fs/notify/fanotify/fanotify_user.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)fs/notify/fanotify/fanotify_user.c +0
-0@@ -920,6 +920,20 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)return 0 ; }fs/notify/fanotify/fanotify_user.c static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) · line 931
Quoted 10 lines
fs/notify/fanotify/fanotify_user.c +9
-0+static int fanotify_events_supported (struct path *path,__u64 mask) +{ +/* +* Proc is special and various files have special locking rules so +* fanotify permission events have high chances of deadlocking the +* system. Just disallow them. +*/ +if (mask &FANOTIFY_PERM_EVENTS && + !strcmp (path->mnt->mnt_sb->s_type->name,"proc" )) {Better use an
SB_I_flag to forbid permission events on fs?Quoted 6 lines
Quoted 3 lines
So checking
s_type->nameindeed felt dirty. I don't think we need a superblock flag though. I'll probably just go withFS_XXXflag infile_system_type.Would the same apply for some files that backed by sysfs and reside in /sys?
So far I'm not aware of similar easy to trigger deadlocks with sysfs. So I opted for a cautious path and disabled permission events only for proc. We'll see how that fares.
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
fs/notify/fanotify/fanotify_user.c static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) · line 932
Quoted 1 line
fs/notify/fanotify/fanotify_user.c +1
-0+return -EOPNOTSUPP ;I would go with EINVAL following precedent of per filesystem flags check on rename(2), but not insisting.
I was undecided between EOPNOTSUPP and EINVAL. So let's go with EINVAL.
I was also thinking that EINVAL makes more sense in this particular case.
Good, that's what I used in v2.
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Anyway, following Matthew's man page update for
FAN_REPORT_FID, we should also add this as reason for EOPNOTSUPP/EINVAL.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Good point.
I've followed up Michael in regards to the
FAN_REPORT_FIDpatch series, but no response as of yet. I'm happy to write the changes for this one if you like?If you had time for that, that would be nice. Thanks!
Simple. I will write the changes and send it through for review.
Signature · 1 line
Matthew Bobrowski