fanotify: fix corruption preventing startup
Subsystems (2)
PATCH 1/1 fanotify: fix corruption preventing startup
Two of my machines couldn't boot mmotm with fanotify enabled:0x40000020 was being or'ed into a group's notification_waitq next pointer, with sad results. It comes from an over-simplification in fanotify_merge(): test_event isn't NULL when the loop finds no merge.
---
Fixes fsnotify-do-not-share-events-between-notification-groups.patch
fs/notify/fanotify/fanotify.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fs/notify/fanotify/fanotify.c +6 -3
@@ -37,16 +37,19 @@ static bool should_merge(struct fsnotifystatic struct fsnotify_event *fanotify_merge (struct list_head *list,struct fsnotify_event *event) { -struct fsnotify_event *test_event =NULL ; +struct fsnotify_event *test_event; +bool do_merge = false;pr_debug ("%s: list=%p event=%p\n" , __func__, list, event);list_for_each_entry_reverse (test_event, list, list) { -if (should_merge (test_event, event)) +if (should_merge (test_event, event)) { + do_merge = true;break ; + } } -if (!test_event) +if (!do_merge)return NULL ; test_event->mask |= event->mask;
Quoted 4 lines · Hugh Dickins
Two of my machines couldn't boot mmotm with fanotify enabled:
0x40000020was being or'ed into a group'snotification_waitqnext pointer, with sad results. It comes from an over-simplification infanotify_merge():test_eventisn't NULL when the loop finds no merge.
That's a really dumb bug. Thanks for the fix! It looks good, you can add:
I was wondering why I didn't see this problem during my testing. I was
always running my tests with various debug options enabled (in a hope to catch more problems ;), in particular with spinlock debugging enabled which shifted the waitqueue pointers further and the corruption landed in spinlock debugging fields and never got noticed... Ew :-|
Honza
Quoted 33 lines
Signed-off-by Hugh Dickins <[email protected]>---
Fixes fsnotify-do-not-share-events-between-notification-groups.patchfs/notify/fanotify/fanotify.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)fs/notify/fanotify/fanotify.c +6
-3@@ -37,16 +37,19 @@ static bool should_merge(struct fsnotifystatic struct fsnotify_event *fanotify_merge (struct list_head *list,struct fsnotify_event *event) { -struct fsnotify_event *test_event =NULL ; +struct fsnotify_event *test_event; +bool do_merge = false;pr_debug ("%s: list=%p event=%p\n" , __func__, list, event);list_for_each_entry_reverse (test_event, list, list) { -if (should_merge (test_event, event)) +if (should_merge (test_event, event)) { + do_merge = true;break ; + } } -if (!test_event) +if (!do_merge)return NULL ; test_event->mask |= event->mask;
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR