linux/fs/notify
Amir Goldstein 3ea33dcc6d fanotify: don't expose EOPENSTALE to userspace
commit 4ff33aafd3 upstream.

When delivering an event to userspace for a file on an NFS share,
if the file is deleted on server side before user reads the event,
user will not get the event.

If the event queue contained several events, the stale event is
quietly dropped and read() returns to user with events read so far
in the buffer.

If the event queue contains a single stale event or if the stale
event is a permission event, read() returns to user with the kernel
internal error code 518 (EOPENSTALE), which is not a POSIX error code.

Check the internal return value -EOPENSTALE in fanotify_read(), just
the same as it is checked in path_openat() and drop the event in the
cases that it is not already dropped.

This is a reproducer from Marko Rauhamaa:

Just take the example program listed under "man fanotify" ("fantest")
and follow these steps:

    ==============================================================
    NFS Server    NFS Client(1)     NFS Client(2)
    ==============================================================
    # echo foo >/nfsshare/bar.txt
                  # cat /nfsshare/bar.txt
                  foo
                                    # ./fantest /nfsshare
                                    Press enter key to terminate.
                                    Listening for events.
    # rm -f /nfsshare/bar.txt
                  # cat /nfsshare/bar.txt
                                    read: Unknown error 518
                  cat: /nfsshare/bar.txt: Operation not permitted
    ==============================================================

where NFS Client (1) and (2) are two terminal sessions on a single NFS
Client machine.

Reported-by: Marko Rauhamaa <marko.rauhamaa@f-secure.com>
Tested-by: Marko Rauhamaa <marko.rauhamaa@f-secure.com>
Cc: <linux-api@vger.kernel.org>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
[bwh: Backported to 3.16: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
History 2017-08-26 02:14:39 +01:00
..
dnotify inotify: Fix reporting of cookies for inotify events 2014-02-18 11:17:17 +01:00
fanotify fanotify: don't expose EOPENSTALE to userspace 2017-08-26 02:14:39 +01:00
inotify inotify: convert use of typedef ctl_table to struct ctl_table 2014-06-06 16:08:16 -07:00
fdinfo.c fs/notify: don't show f_handle if exportfs_encode_inode_fh failed 2014-10-05 13:41:07 -07:00
fdinfo.h fs, notify: add procfs fdinfo helper 2012-12-17 17:15:28 -08:00
fsnotify.c move d_rcu from overlapping d_child to overlapping d_alias 2015-01-15 10:44:58 +00:00
fsnotify.h fsnotify: remove global fsnotify groups lists 2010-07-28 10:18:54 -04:00
group.c fsnotify: add a way to stop queueing events on group shutdown 2016-11-20 01:17:33 +00:00
inode_mark.c fsnotify: Fix possible use-after-free in inode iteration on umount 2017-03-16 02:26:35 +00:00
Kconfig fanotify: allow fanotify to be built 2010-10-28 17:22:13 -04:00
Makefile fs, notify: add procfs fdinfo helper 2012-12-17 17:15:28 -08:00
mark.c fsnotify: fix oops in fsnotify_clear_marks_by_group_flags() 2015-08-27 12:08:16 +01:00
notification.c fanotify: fix list corruption in fanotify_get_response() 2016-11-20 01:17:33 +00:00
vfsmount_mark.c hlist: drop the node parameter from iterators 2013-02-27 19:10:24 -08:00