fsnotify: fix false positive warning on inode delete
Subsystems (2)
Amir Goldstein
reviewerPATCH 1/1 fsnotify: fix false positive warning on inode delete
---
Jan,
syzbot reported (in private email) that the reproducer did not trigger the warning, so added tested-by.
Thanks,
Amir.
fs/notify/mark.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/notify/mark.c +7 -0
@@ -236,6 +236,13 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)if (hlist_empty (&conn->list)) { inode =fsnotify_detach_connector_from_object (conn); free_conn = true; + }else if (conn->type ==FSNOTIFY_OBJ_TYPE_DETACHED ) { +/* +* fsnotify_destroy_marks() detaches conn from object before +* put on last mark of object list and other marks on the list +* may still have elevated refcounts. We don't need to recalc +* mask nor to free_conn in that case. +*/ }else {__fsnotify_recalc_mask (conn); }
Signature · 1 line
2.7.4
Jan Kara
maintainerQuoted 9 lines · Amir Goldstein
Reported-and-tested-by [email protected]Fixes 3ac70bfcde81 ("fsnotify: add helper to get mask from connector")Signed-off-by Amir Goldstein <[email protected]>---
Jan,
syzbot reported (in private email) that the reproducer did not trigger the warning, so added tested-by.
Thanks for looking into this Amir! I was thinking about this for a while and I'm not sure that __fsnotify_recalc_mask() call from fsnotify_put_mark() is the only place calling __fsnotify_recalc_mask() that can happen on detached connector. unlink(2) can get called pretty much at any time so places like inotify_update_existing_watch() can easily work on inode that is getting unlinked and by the time we get to fsnotify_recalc_mask(), we can pass detached connector to it AFAICT. conn->lock we hold in __fsnotify_recalc_mask() protecs us from fsnotify_detach_connector_from_object() so we can reliably check connector state in __fsnotify_recalc_mask() and just don't do anything when the connector is already detached without issuing a warning. What do you think?
Honza
Quoted 24 lines
fs/notify/mark.c | 7 +++++++ 1 file changed, 7 insertions(+)fs/notify/mark.c +7
-0@@ -236,6 +236,13 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)if (hlist_empty (&conn->list)) { inode =fsnotify_detach_connector_from_object (conn); free_conn = true; + }else if (conn->type ==FSNOTIFY_OBJ_TYPE_DETACHED ) { +/* +* fsnotify_destroy_marks() detaches conn from object before +* put on last mark of object list and other marks on the list +* may still have elevated refcounts. We don't need to recalc +* mask nor to free_conn in that case. +*/ }else {__fsnotify_recalc_mask (conn); }Signature · 1 line
2.7.4
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Amir Goldstein
reviewerQuoted 12 lines · Jan Kara
Quoted 9 lines · Amir Goldstein
Reported-and-tested-by [email protected]Fixes 3ac70bfcde81 ("fsnotify: add helper to get mask from connector")Signed-off-by Amir Goldstein <[email protected]>---
Jan,
syzbot reported (in private email) that the reproducer did not trigger the warning, so added tested-by.
Quoted 12 lines
Thanks for looking into this Amir! I was thinking about this for a while and I'm not sure that
__fsnotify_recalc_mask()call fromfsnotify_put_mark()is the only place calling__fsnotify_recalc_mask()that can happen on detached connector. unlink(2) can get called pretty much at any time so places likeinotify_update_existing_watch()can easily work on inode that is getting unlinked and by the time we get tofsnotify_recalc_mask(), we can pass detached connector to it AFAICT.conn->lockwe hold in__fsnotify_recalc_mask()protecs us fromfsnotify_detach_connector_from_object()so we can reliably check connector state in__fsnotify_recalc_mask()and just don't do anything when the connector is already detached without issuing a warning. What do you think?
Makes sense. WARN_ON() is a new addition by cleanup patches and the fact that disconnected state is valid in __fsnotify_recalc_mask() was an oversight.
Feel free to apply the simpler fix with reported-by attribution to syzbot ;-)
Thanks,
Amir.