Skip to content

Commit

Permalink
[PATCH] inotify: read return val fix
Browse files Browse the repository at this point in the history
Fix for inotify read bug (bugzilla.kernel.org #6999)

Problem Description:
When reading from an inotify device with an insufficient sized buffer, read(2)
will return 0 with no errno set. This is because of an logically incorrect
action from the user program thus should return an more logical value. My
suggestion is return -EINVAL as for bind(2).

This patch is based on the proposal from Ryan <wolf0403@hotmail.com>, and
feedback from John McCutchan <john@johnmccutchan.com>.

Return -EINVAL if we have not passed in enough buffer space to read a single
inotify event, rather than 0 which indicates that there is nothing to read.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: "John McCutchan" <john@johnmccutchan.com>
Cc: Ryan <wolf0403@hotmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Nick Piggin authored and Linus Torvalds committed Feb 12, 2007
1 parent d003fb7 commit f9e4acf
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion fs/inotify_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,16 @@ static ssize_t inotify_read(struct file *file, char __user *buf,
break;

kevent = inotify_dev_get_event(dev);
if (event_size + kevent->event.len > count)
if (event_size + kevent->event.len > count) {
if (ret == 0 && count > 0) {
/*
* could not get a single event because we
* didn't have enough buffer space.
*/
ret = -EINVAL;
}
break;
}

if (copy_to_user(buf, &kevent->event, event_size)) {
ret = -EFAULT;
Expand Down

0 comments on commit f9e4acf

Please sign in to comment.