Skip to content

Commit

Permalink
fanotify: Avoid softlockups when reading many events
Browse files Browse the repository at this point in the history
When user provides large buffer for events and there are lots of events
available, we can try to copy them all to userspace without scheduling
which can softlockup the kernel (furthermore exacerbated by the
contention on notification_lock). Add a scheduling point after copying
each event.

Note that usually the real underlying problem is the cost of fanotify
event merging and the resulting contention on notification_lock but this
is a cheap way to somewhat reduce the problem until we can properly
address that.

Reported-by: Francesco Ruggeri <[email protected]>
Link: https://lore.kernel.org/lkml/[email protected]
Reviewed-by: Amir Goldstein <[email protected]>
Signed-off-by: Jan Kara <[email protected]>
  • Loading branch information
jankara committed Jul 15, 2020
1 parent 0bddd22 commit 47aaabd
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fs/notify/fanotify/fanotify_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,11 @@ static ssize_t fanotify_read(struct file *file, char __user *buf,

add_wait_queue(&group->notification_waitq, &wait);
while (1) {
/*
* User can supply arbitrarily large buffer. Avoid softlockups
* in case there are lots of available events.
*/
cond_resched();
event = get_one_event(group, count);
if (IS_ERR(event)) {
ret = PTR_ERR(event);
Expand Down

0 comments on commit 47aaabd

Please sign in to comment.