Skip to content

Commit 47aaabd

Browse files
committed
fanotify: Avoid softlockups when reading many events
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]>
1 parent 0bddd22 commit 47aaabd

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

fs/notify/fanotify/fanotify_user.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,11 @@ static ssize_t fanotify_read(struct file *file, char __user *buf,
412412

413413
add_wait_queue(&group->notification_waitq, &wait);
414414
while (1) {
415+
/*
416+
* User can supply arbitrarily large buffer. Avoid softlockups
417+
* in case there are lots of available events.
418+
*/
419+
cond_resched();
415420
event = get_one_event(group, count);
416421
if (IS_ERR(event)) {
417422
ret = PTR_ERR(event);

0 commit comments

Comments
 (0)