aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2014-04-03 17:46:36 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-04-03 19:20:51 -0400
commitd507816b58bebc8f9c1bed6a28affaf0729306e2 (patch)
treef82f5977b3a5e3b4e0c1b1f9bbf16b25e5a4c860
parentd8aaab4f619acfbfafc91d94b15c2932457c65fa (diff)
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 <jack@suse.cz> Cc: Eric Paris <eparis@redhat.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--fs/notify/fanotify/fanotify_user.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index f1097f56137e..4e565c814309 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -199,7 +199,7 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
199 199
200 ret = fill_event_metadata(group, &fanotify_event_metadata, event, &f); 200 ret = fill_event_metadata(group, &fanotify_event_metadata, event, &f);
201 if (ret < 0) 201 if (ret < 0)
202 goto out; 202 return ret;
203 203
204 fd = fanotify_event_metadata.fd; 204 fd = fanotify_event_metadata.fd;
205 ret = -EFAULT; 205 ret = -EFAULT;
@@ -208,16 +208,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
208 goto out_close_fd; 208 goto out_close_fd;
209 209
210#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS 210#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
211 if (event->mask & FAN_ALL_PERM_EVENTS) { 211 if (event->mask & FAN_ALL_PERM_EVENTS)
212 struct fanotify_perm_event_info *pevent; 212 FANOTIFY_PE(event)->fd = fd;
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 }
221#endif 213#endif
222 214
223 if (fd != FAN_NOFD) 215 if (fd != FAN_NOFD)
@@ -229,13 +221,6 @@ out_close_fd:
229 put_unused_fd(fd); 221 put_unused_fd(fd);
230 fput(f); 222 fput(f);
231 } 223 }
232out:
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
239 return ret; 224 return ret;
240} 225}
241 226
@@ -300,10 +285,23 @@ static ssize_t fanotify_read(struct file *file, char __user *buf,
300 * Permission events get queued to wait for response. Other 285 * Permission events get queued to wait for response. Other
301 * events can be destroyed now. 286 * events can be destroyed now.
302 */ 287 */
303 if (!(kevent->mask & FAN_ALL_PERM_EVENTS)) 288 if (!(kevent->mask & FAN_ALL_PERM_EVENTS)) {
304 fsnotify_destroy_event(group, kevent); 289 fsnotify_destroy_event(group, kevent);
305 if (ret < 0) 290 if (ret < 0)
306 break; 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 }
307 buf += ret; 305 buf += ret;
308 count -= ret; 306 count -= ret;
309 } 307 }