Skip to content

Commit d507816

Browse files
jankaratorvalds
authored andcommitted
fanotify: move unrelated handling from copy_event_to_user()
Move code moving event structure to access_list from copy_event_to_user() to fanotify_read() where it is more logical (so that we can immediately see in the main loop that we either move the event to a different list or free it). Also move special error handling for permission events from copy_event_to_user() to the main loop to have it in one place with error handling for normal events. This makes copy_event_to_user() really only copy the event to user without any side effects. Signed-off-by: Jan Kara <[email protected]> Cc: Eric Paris <[email protected]> Cc: Al Viro <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent d8aaab4 commit d507816

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

fs/notify/fanotify/fanotify_user.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
199199

200200
ret = fill_event_metadata(group, &fanotify_event_metadata, event, &f);
201201
if (ret < 0)
202-
goto out;
202+
return ret;
203203

204204
fd = fanotify_event_metadata.fd;
205205
ret = -EFAULT;
@@ -208,16 +208,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
208208
goto out_close_fd;
209209

210210
#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
211-
if (event->mask & FAN_ALL_PERM_EVENTS) {
212-
struct fanotify_perm_event_info *pevent;
213-
214-
pevent = FANOTIFY_PE(event);
215-
pevent->fd = fd;
216-
spin_lock(&group->fanotify_data.access_lock);
217-
list_add_tail(&pevent->fae.fse.list,
218-
&group->fanotify_data.access_list);
219-
spin_unlock(&group->fanotify_data.access_lock);
220-
}
211+
if (event->mask & FAN_ALL_PERM_EVENTS)
212+
FANOTIFY_PE(event)->fd = fd;
221213
#endif
222214

223215
if (fd != FAN_NOFD)
@@ -229,13 +221,6 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
229221
put_unused_fd(fd);
230222
fput(f);
231223
}
232-
out:
233-
#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
234-
if (event->mask & FAN_ALL_PERM_EVENTS) {
235-
FANOTIFY_PE(event)->response = FAN_DENY;
236-
wake_up(&group->fanotify_data.access_waitq);
237-
}
238-
#endif
239224
return ret;
240225
}
241226

@@ -300,10 +285,23 @@ static ssize_t fanotify_read(struct file *file, char __user *buf,
300285
* Permission events get queued to wait for response. Other
301286
* events can be destroyed now.
302287
*/
303-
if (!(kevent->mask & FAN_ALL_PERM_EVENTS))
288+
if (!(kevent->mask & FAN_ALL_PERM_EVENTS)) {
304289
fsnotify_destroy_event(group, kevent);
305-
if (ret < 0)
306-
break;
290+
if (ret < 0)
291+
break;
292+
} else {
293+
#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
294+
if (ret < 0) {
295+
FANOTIFY_PE(kevent)->response = FAN_DENY;
296+
wake_up(&group->fanotify_data.access_waitq);
297+
break;
298+
}
299+
spin_lock(&group->fanotify_data.access_lock);
300+
list_add_tail(&kevent->list,
301+
&group->fanotify_data.access_list);
302+
spin_unlock(&group->fanotify_data.access_lock);
303+
#endif
304+
}
307305
buf += ret;
308306
count -= ret;
309307
}

0 commit comments

Comments
 (0)