fanotify: Do not ignore result of permission decisions
Subsystems (2)
PATCH 1/1 fanotify: Do not ignore result of permission decisions
Current code ignores access replies to permission decisions so fix it in a way which will allow all listeners to still receive non permission events.
--- fs/notify/fsnotify.c | 25 +++++++++++++++++-------- include/linux/fsnotify_backend.h | 4 ++++ 2 files changed, 21 insertions(+), 8 deletions(-)
fs/notify/fsnotify.c +17 -8
@@ -224,7 +224,7 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,struct fsnotify_group *inode_group, *vfsmount_group;struct fsnotify_event *event =NULL ;struct vfsmount *mnt; -int idx, ret =0 ; +int idx, ret =0 , res;/* global tests shouldn't care about events on child only the specific event */ __u32 test_mask = (mask & ~FS_EVENT_ON_CHILD );
@@ -275,18 +275,27 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,if (inode_group > vfsmount_group) {/* handle inode */ -send_to_group (to_tell,NULL , inode_mark,NULL , mask, data, - data_is, cookie, file_name, &event); + res =send_to_group (to_tell,NULL , inode_mark,NULL , mask, data, + data_is, cookie, file_name, &event);/* we didn't use the vfsmount_mark */ vfsmount_group =NULL ; }else if (vfsmount_group > inode_group) { -send_to_group (to_tell, mnt,NULL , vfsmount_mark, mask, data, - data_is, cookie, file_name, &event); + res =send_to_group (to_tell, mnt,NULL , vfsmount_mark, mask, data, + data_is, cookie, file_name, &event); inode_group =NULL ; }else { -send_to_group (to_tell, mnt, inode_mark, vfsmount_mark, - mask, data, data_is, cookie, file_name, - &event); + res =send_to_group (to_tell, mnt, inode_mark, vfsmount_mark, + mask, data, data_is, cookie, file_name, + &event); + } + +/* If a listener denied on a permission hook we will remember the reason +and run the rest with a non-permission mask only. This allows other +listeners to receive non-permission notifications but we do not care +about further permission checks. */ +if (unlikely ((res == -EPERM ) && (mask &FS_ALL_PERM_EVENTS ))) { + mask &= ~FS_ALL_PERM_EVENTS ; + ret = res; }if (inode_group)
include/linux/fsnotify_backend.h +4 -0
@@ -64,6 +64,10 @@#define FS_MOVE (FS_MOVED_FROM | FS_MOVED_TO) +/* All events which require a permission response from userspace */ +#define FS_ALL_PERM_EVENTS (FS_OPEN_PERM |\ + FS_ACCESS_PERM) +#define ALL_FSNOTIFY_EVENTS (FS_ACCESS | FS_MODIFY | FS_ATTRIB | \ FS_CLOSE_WRITE | FS_CLOSE_NOWRITE | FS_OPEN | \ FS_MOVED_FROM | FS_MOVED_TO | FS_CREATE | \
Sophos Plc, The Pentagon, Abingdon Science Park, Abingdon, OX14 3YP, United Kingdom. Company Reg No 2096520. VAT Reg No GB 348 3873 20.
Improved version of the fix which does not include the check when permission events are not enabled in configuration and stops processing if no interesting events remain.
Current code ignores access replies to permission decisions so fix it in a way which will allow all listeners to still receive non permission events.
--- fs/notify/fsnotify.c | 32 ++++++++++++++++++++++++-------- include/linux/fsnotify_backend.h | 4 ++++ 2 files changed, 28 insertions(+), 8 deletions(-)
fs/notify/fsnotify.c +24 -8
@@ -224,7 +224,7 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,struct fsnotify_group *inode_group, *vfsmount_group;struct fsnotify_event *event =NULL ;struct vfsmount *mnt; -int idx, ret =0 ; +int idx, ret =0 , res;/* global tests shouldn't care about events on child only the specific event */ __u32 test_mask = (mask & ~FS_EVENT_ON_CHILD );
@@ -275,20 +275,36 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,if (inode_group > vfsmount_group) {/* handle inode */ -send_to_group (to_tell,NULL , inode_mark,NULL , mask, data, - data_is, cookie, file_name, &event); + res =send_to_group (to_tell,NULL , inode_mark,NULL , mask, data, + data_is, cookie, file_name, &event);/* we didn't use the vfsmount_mark */ vfsmount_group =NULL ; }else if (vfsmount_group > inode_group) { -send_to_group (to_tell, mnt,NULL , vfsmount_mark, mask, data, - data_is, cookie, file_name, &event); + res =send_to_group (to_tell, mnt,NULL , vfsmount_mark, mask, data, + data_is, cookie, file_name, &event); inode_group =NULL ; }else { -send_to_group (to_tell, mnt, inode_mark, vfsmount_mark, - mask, data, data_is, cookie, file_name, - &event); + res =send_to_group (to_tell, mnt, inode_mark, vfsmount_mark, + mask, data, data_is, cookie, file_name, + &event); } +#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS +/* If a listener denied on a permission event we will remember the reason +and run the rest with a non-permission mask only. This allows other +listeners to receive non-permission notifications but we do not care +about further permission checks and want to deny this event. */ +if (unlikely ((res == -EPERM ) && (mask &FS_ALL_PERM_EVENTS ))) { + mask &= ~FS_ALL_PERM_EVENTS ; + ret = res; +/* Stop processing if no interesting events remains. */ +if (!(mask & (ALL_FSNOTIFY_EVENTS & ~FS_EVENT_ON_CHILD ))) +break ; + } +#else + (void )res; +#endif +if (inode_group) inode_node =srcu_dereference (inode_node->next, &fsnotify_mark_srcu);
include/linux/fsnotify_backend.h +4 -0
@@ -64,6 +64,10 @@#define FS_MOVE (FS_MOVED_FROM | FS_MOVED_TO) +/* All events which require a permission response from userspace */ +#define FS_ALL_PERM_EVENTS (FS_OPEN_PERM |\ + FS_ACCESS_PERM) +#define ALL_FSNOTIFY_EVENTS (FS_ACCESS | FS_MODIFY | FS_ATTRIB | \ FS_CLOSE_WRITE | FS_CLOSE_NOWRITE | FS_OPEN | \ FS_MOVED_FROM | FS_MOVED_TO | FS_CREATE | \
Sophos Plc, The Pentagon, Abingdon Science Park, Abingdon, OX14 3YP, United Kingdom. Company Reg No 2096520. VAT Reg No GB 348 3873 20.
Tvrtko,
Quoted 8 lines · On Wednesday 08 September 2010 10:24:04 Tvrtko Ursulin wrote:
Improved version of the fix which does not include the check when permission events are not enabled in configuration and stops processing if no interesting events remain.
Current code ignores access replies to permission decisions so fix it in a way which will allow all listeners to still receive non permission events.
I agree with the patch (see comments below), but this explanation is close to incomprehensible and not good as a commit message.
Quoted 40 lines
Signed-off-by Tvrtko Ursulin <[email protected]>--- fs/notify/fsnotify.c | 32 ++++++++++++++++++++++++-------- include/linux/fsnotify_backend.h | 4 ++++ 2 files changed, 28 insertions(+), 8 deletions(-)fs/notify/fsnotify.c +6
-8@@ -224,7 +224,7 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,struct fsnotify_group *inode_group, *vfsmount_group;struct fsnotify_event *event =NULL ;struct vfsmount *mnt; -int idx, ret =0 ; +int idx, ret =0 , res;/* global tests shouldn't care about events on child only the specific event */ __u32 test_mask = (mask & ~FS_EVENT_ON_CHILD );@@ -275,20 +275,36 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,if (inode_group > vfsmount_group) {/* handle inode */ -send_to_group (to_tell,NULL , inode_mark,NULL , mask, data, - data_is, cookie, file_name, &event); + res =send_to_group (to_tell,NULL , inode_mark,NULL , mask, data, + data_is, cookie, file_name, &event);/* we didn't use the vfsmount_mark */ vfsmount_group =NULL ; }else if (vfsmount_group > inode_group) { -send_to_group (to_tell, mnt,NULL , vfsmount_mark, mask, data, - data_is, cookie, file_name, &event); + res =send_to_group (to_tell, mnt,NULL , vfsmount_mark, mask, data, + data_is, cookie, file_name, &event); inode_group =NULL ; }else { -send_to_group (to_tell, mnt, inode_mark, vfsmount_mark, - mask, data, data_is, cookie, file_name, - &event); + res = send_to_group(to_tell, mnt, inode_mark, vfsmount_mark,
fs/notify/fsnotify.c int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is, · line 297
Quoted 10 lines
fs/notify/fsnotify.c +8
-0+ mask, data, data_is, cookie, file_name, + &event); } +#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS +/* If a listener denied on a permission event we will remember the reason +and run the rest with a non-permission mask only. This allows other +listeners to receive non-permission notifications but we do not care +about further permission checks and want to deny this event. */ +if (unlikely ((res == -EPERM ) && (mask &FS_ALL_PERM_EVENTS ))) {
We should probably stop processing here whenever res != 0, for any mask. (The fanotify and inotify handle_event callbacks can return -ENOMEM right now, but this doesn't seem very useful and should probably be fixed: fsnotify has no way of doing anything about -ENOMEM.
Quoted 18 lines
fs/notify/fsnotify.c +10
-0+ mask &= ~FS_ALL_PERM_EVENTS ; + ret = res; +/* Stop processing if no interesting events remains. */ +if (!(mask & (ALL_FSNOTIFY_EVENTS & ~FS_EVENT_ON_CHILD ))) + break; + } +#else + (void )res; +#endif +if (inode_group) inode_node =srcu_dereference (inode_node->next, &fsnotify_mark_srcu);include/linux/fsnotify_backend.h +0
-0
include/linux/fsnotify_backend.h line 69
Quoted 6 lines
include/linux/fsnotify_backend.h +3
-0@@ -64,6 +64,10 @@#define FS_MOVE (FS_MOVED_FROM | FS_MOVED_TO) +/* All events which require a permission response from userspace */ +#define FS_ALL_PERM_EVENTS (FS_OPEN_PERM |\ + FS_ACCESS_PERM)
When dealing with the result of ->handle_event as I propose, this definition isn't needed.
Thanks,
Andreas
Quoted 7 lines · On Friday 08 Oct 2010 14:00:40 Andreas Gruenbacher wrote:
Tvrtko,
Quoted 4 lines · On Wednesday 08 September 2010 10:24:04 Tvrtko Ursulin wrote:
Improved version of the fix which does not include the check when permission events are not enabled in configuration and stops processing if no interesting events remain.
Quoted 6 lines
Quoted 3 lines
Current code ignores access replies to permission decisions so fix it in a way which will allow all listeners to still receive non permission events.
I agree with the patch (see comments below), but this explanation is close to incomprehensible and not good as a commit message.
How about this:
Current code incorrectly ignores responses to permission decisions. When a single deny response has been received record it and do not send more permission events. However still send non-permission events to other clients.
Quoted 63 lines
Quoted 63 lines
Signed-off-by Tvrtko Ursulin <[email protected]>---
fs/notify/fsnotify.c | 32 ++++++++++++++++++++++++-------- include/linux/fsnotify_backend.h | 4 ++++ 2 files changed, 28 insertions(+), 8 deletions(-)fs/notify/fsnotify.c +1
-1@@ -224,7 +224,7 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is, struct fsnotify_group *inode_group, *vfsmount_group;struct fsnotify_event *event =NULL ;struct vfsmount *mnt; -int idx, ret =0 ; +int idx, ret =0 , res;/* global tests shouldn't care about events on child only the specific event */ __u32 test_mask = (mask & ~FS_EVENT_ON_CHILD);fs/notify/fsnotify.c +0
-1@@ -275,20 +275,36 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is, if (inode_group > vfsmount_group) {/* handle inode */ -send_to_group (to_tell ,NULL ,inode_mark ,NULL , mask, data, - data_is, cookie, file_name, &event); + res = send_to_group(to_tell,NULL,
inode_mark, NULL, mask, data, +data_is, cookie, file_name, &event); /* we didn't use the vfsmount_mark */ vfsmount_group = NULL; } else if (vfsmount_group > inode_group) {- send_to_group(to_tell, mnt, NULL,
vfsmount_mark,
mask, data, -data_is, cookie,file_name, &event); + res = send_to_group(to_tell,
mnt, NULL,vfsmount_mark, mask, data, +data_is, cookie, file_name, &event); inode_group = NULL; } else {- send_to_group(to_tell, mnt,
inode_mark,vfsmount_mark, - mask, data,data_is, cookie,file_name, -
&event);
+ res = send_to_group(to_tell, mnt,inode_mark,vfsmount_mark, + mask, data,data_is, cookie,file_name, +
&event);}
Quoted 13 lines
Quoted 8 lines
fs/notify/fsnotify.c +2
-0+#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS +/* If a listener denied on a permission event we will remember the reason + and run the rest with a
non-permission mask only. This allows other + listeners
to receive non-permission notifications but we do not care +
about further permission checks and want to deny this event. */ +
if (unlikely((res ==-EPERM) && (mask &FS_ALL_PERM_EVENTS))) {We should probably stop processing here whenever res != 0, for any mask. (The fanotify and inotify
handle_eventcallbacks can return-ENOMEMright now, but this doesn't seem very useful and should probably be fixed:
fsnotify has no way of doing anything about-ENOMEM.
I wasn't 100% sure of how fanotify works, or in other words can there be more events in this mask after perm events are removed. If it can then we should send them to other listeners. Eric?
Also if ENOMEM, why not try sending to other listeners?
Quoted 24 lines
Quoted 24 lines
fs/notify/fsnotify.c +3
-0+ mask &= ~FS_ALL_PERM_EVENTS ; + ret = res; +/* Stop processing if no interesting events remains. */ + if (!(mask & (
ALL_FSNOTIFY_EVENTS&
~FS_EVENT_ON_CHILD))) + break;fs/notify/fsnotify.c +5
-0+ } +#else + (void )res; +#endif +if (inode_group) inode_node =srcu_dereference (inode_node->next, &fsnotify_mark_srcu );(quoted diff) +0
-0
b/include/linux/fsnotify_backend.hindex e40190d..c8aea03 100644include/linux/fsnotify_backend.h +0
-0@@ -64,6 +64,10 @@
Quoted 8 lines
include/linux/fsnotify_backend.h line 69
Quoted 5 lines
include/linux/fsnotify_backend.h +3
-0#define FS_MOVE (FS_MOVED_FROM | FS_MOVED_TO) +/* All events which require a permission response from userspace */ +#define FS_ALL_PERM_EVENTS (FS_OPEN_PERM |\ + FS_ACCESS_PERM)When dealing with the result of ->handle_event as I propose, this definition isn't needed.
Yep, I am just unsure what is overall right thing to do. Lets see what Eric says..
Tvrtko
Sophos Plc, The Pentagon, Abingdon Science Park, Abingdon, OX14 3YP, United Kingdom. Company Reg No 2096520. VAT Reg No GB 348 3873 20.
Quoted 21 lines · Tvrtko Ursulin
Quoted 15 lines · On Friday 08 Oct 2010 14:00:40 Andreas Gruenbacher wrote:
Tvrtko,
Quoted 10 lines · On Wednesday 08 September 2010 10:24:04 Tvrtko Ursulin wrote:
}(quoted diff) +2
-0+#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS + /* If a listener denied on a permission event we willremember the reason + and run the rest with a
non-permission mask only. This allows other + listeners
to receive non-permission notifications but we do not care +
about further permission checks and want to deny this event. */ +
if (unlikely((res ==-EPERM) && (mask &FS_ALL_PERM_EVENTS))) {Quoted 4 lines
We should probably stop processing here whenever res != 0, for any mask. (The fanotify and inotify
handle_eventcallbacks can return-ENOMEMright now, but this doesn't seem very useful and should probably be fixed:
fsnotify has no way of doing anything about-ENOMEM.
Quoted 5 lines
I wasn't 100% sure of how fanotify works, or in other words can there be more events in this mask after perm events are removed. If it can then we should send them to other listeners. Eric?
Also if ENOMEM, why not try sending to other listeners?
No, you'll never have a PERM_EVENT and something else at the same time. If it's a PERM_EVENT denial we wouldn't really want to even notify others, since the operation won't have actually taken place (perm event denials should be passed all the way back up the stack)
As to ENOMEM that's a little harder I guess. We don't have to stop just because inotify got ENOMEM, but we should stop if PERM_EVENTS got an ENOMEM.
I'd really rather not put CONFIG_FANOTIFY_ACCESS_PERMISSIONS in this file. fsnotify.c should be notifier agnostic.
How about just:
if (unlikely(ret && (mask & ALL_PERM)))
return ret
Quoted 31 lines · On Friday 08 Oct 2010 17:51:00 Eric Paris wrote:
Quoted 30 lines · Tvrtko Ursulin
Quoted 17 lines · On Friday 08 Oct 2010 14:00:40 Andreas Gruenbacher wrote:
Tvrtko,
Quoted 14 lines · On Wednesday 08 September 2010 10:24:04 Tvrtko Ursulin wrote:
}(quoted diff) +2
-0+#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS + /* If a listener denied on a permission event we willremember the reason + and run the rest with a
non-permission mask only. This allows other +
listeners to receive non-permission notifications but we do not care +about further permission checks and want to deny this event. */ + if (unlikely((res == -EPERM) && (mask &Quoted 7 lines
Quoted 1 line
FS_ALL_PERM_EVENTS))) {We should probably stop processing here whenever res != 0, for any mask. (The fanotify and inotify
handle_eventcallbacks can return-ENOMEMright now, but this doesn't seem very useful and should probably be fixed: fsnotify has no way of doing anything about-ENOMEM.I wasn't 100% sure of how fanotify works, or in other words can there be more events in this mask after perm events are removed. If it can then we should send them to other listeners. Eric?
Quoted 6 lines
Quoted 1 line
Also if ENOMEM, why not try sending to other listeners?
No, you'll never have a
PERM_EVENTand something else at the same time. If it's aPERM_EVENTdenial we wouldn't really want to even notify others, since the operation won't have actually taken place (perm event denials should be passed all the way back up the stack)
Ok, I wasn't sure if event merging could somehow join more events on one object into one event here.
Quoted 11 lines
As to ENOMEM that's a little harder I guess. We don't have to stop just because inotify got ENOMEM, but we should stop if
PERM_EVENTSgot an ENOMEM.I'd really rather not put
CONFIG_FANOTIFY_ACCESS_PERMISSIONSin this file.fsnotify.cshould be notifier agnostic.How about just:
if (
unlikely(ret && (mask & ALL_PERM)))
return ret
Looks like it would work and on more thinking I also agree with the logic to stop the perm chain on ENOMEM.
Tvrtko
Sophos Plc, The Pentagon, Abingdon Science Park, Abingdon, OX14 3YP, United Kingdom. Company Reg No 2096520. VAT Reg No GB 348 3873 20.
Quoted 15 lines · On Friday 08 October 2010 18:11:23 Tvrtko Ursulin wrote:
Quoted 7 lines · On Friday 08 Oct 2010 14:00:40 Andreas Gruenbacher wrote:
Tvrtko,
Quoted 4 lines · On Wednesday 08 September 2010 10:24:04 Tvrtko Ursulin wrote:
Improved version of the fix which does not include the check when permission events are not enabled in configuration and stops processing if no interesting events remain.
Quoted 6 lines
Quoted 3 lines
Current code ignores access replies to permission decisions so fix it in a way which will allow all listeners to still receive non permission events.
I agree with the patch (see comments below), but this explanation is close to incomprehensible and not good as a commit message.
Quoted 6 lines
How about this:
Current code incorrectly ignores responses to permission decisions. When a single deny response has been received record it and do not send more permission events. However still send non-permission events to other clients.
Much better, thanks.
Quoted 1 line
Also if ENOMEM, why not try sending to other listeners?
My point, exactly.
Thanks,
Andreas