linux/fs
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
..
9p fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
adfs fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
affs fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
afs AFS: Correctly assemble the client UUID 2014-07-29 10:14:36 -07:00
autofs4 autofs4 copy_dev_ioctl(): keep the value of ->size we'd used for allocation 2015-03-02 15:04:38 +00:00
befs fs/befs: kernel-doc fixes 2014-06-06 16:08:09 -07:00
bfs write_iter variants of {__,}generic_file_aio_write() 2014-05-06 17:38:00 -04:00
btrfs btrfs: fix btrfs_compat_ioctl failures on non-compat ioctls 2017-03-16 02:27:11 +00:00
cachefiles FS-Cache: Add missing initialization of ret in cachefiles_write_page() 2015-12-18 16:06:16 +00:00
ceph ceph: fix recursion between ceph_set_acl() and __ceph_setattr() 2017-07-18 18:40:39 +01:00
cifs cifs: Do not send echoes before Negotiate is complete 2017-07-18 18:40:36 +01:00
coda move d_rcu from overlapping d_child to overlapping d_alias 2015-01-15 10:44:58 +00:00
configfs sysfs: Create mountpoints with sysfs_create_mount_point 2015-08-20 18:24:03 +01:00
cramfs Major changes for 3.14 include support for the newly added ZERO_RANGE 2014-04-04 15:39:39 -07:00
debugfs sysfs: Create mountpoints with sysfs_create_mount_point 2015-08-20 18:24:03 +01:00
devpts pty: make sure super_block is still valid in final /dev/tty close 2016-02-25 10:34:48 +00:00
dlm dlm: keep listening connection alive with sctp mode 2014-06-12 10:26:14 -05:00
ecryptfs fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
efivarfs efi: Make efivarfs entries immutable by default 2016-03-24 10:01:20 +00:00
efs fs/efs: convert printk(KERN_DEBUG to pr_debug 2014-06-04 16:54:21 -07:00
exofs fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
exportfs move d_rcu from overlapping d_child to overlapping d_alias 2015-01-15 10:44:58 +00:00
ext2 fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
ext3 fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
ext4 ext4: lock the xattr block before checksuming it 2017-07-18 18:40:23 +01:00
f2fs f2fs: add ovp valid_blocks check for bg gc victim to fg_gc 2017-06-05 21:17:15 +01:00
fat fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
freevxfs Major changes for 3.14 include support for the newly added ZERO_RANGE 2014-04-04 15:39:39 -07:00
fscache FS-Cache: Handle a write to the page immediately beyond the EOF marker 2015-12-13 17:49:53 +00:00
fuse fuse: add missing FR_FORCE 2017-06-05 21:17:13 +01:00
gfs2 fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
hfs fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
hfsplus fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
hostfs fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
hpfs fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
hppfs clean up scary strncpy(dst, src, strlen(src)) uses 2013-07-03 16:07:41 -07:00
hugetlbfs mm: larger stack guard gap, between vmas 2017-07-02 17:13:02 +01:00
isofs isofs: Do not return EACCES for unknown filesystems 2017-02-23 03:54:17 +00:00
jbd fs/jbd/revoke.c: replace shift loop by ilog2 2014-05-21 10:26:13 +02:00
jbd2 jbd2: don't leak modified metadata buffers on an aborted journal 2017-06-05 21:17:03 +01:00
jffs2 fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
jfs fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
kernfs fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
lockd lockd: create NSM handles per net namespace 2015-12-13 17:48:43 +00:00
logfs fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
minix fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
ncpfs fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
nfs NFS: Use GFP_NOIO for two allocations in writeback 2017-08-26 02:14:37 +01:00
nfs_common nfs_common: Update the translation between nfsv3 acls linux posix acls 2013-02-13 06:15:14 -08:00
nfsd ima: pass 'opened' flag to identify newly created files 2017-08-26 02:14:23 +01:00
nilfs2 fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
nls nls: have register_nls() set ->owner 2014-01-25 03:14:05 -05:00
notify fanotify: don't expose EOPENSTALE to userspace 2017-08-26 02:14:39 +01:00
ntfs fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
ocfs2 ocfs2: fix crash caused by stale lvb with fsdlm plugin 2017-03-16 02:26:55 +00:00
omfs fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
openpromfs fs: push sync_filesystem() down to the file system's remount_fs() 2014-03-13 10:14:33 -04:00
proc mm: larger stack guard gap, between vmas 2017-07-02 17:13:02 +01:00
pstore pstore/ram: Use memcpy_fromio() to save old buffer 2017-02-23 03:53:59 +00:00
qnx4 fs: push sync_filesystem() down to the file system's remount_fs() 2014-03-13 10:14:33 -04:00
qnx6 fs: push sync_filesystem() down to the file system's remount_fs() 2014-03-13 10:14:33 -04:00
quota quota: Store maximum space limit in bytes 2015-03-04 17:28:02 +00:00
ramfs fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
reiserfs reiserfs: Unlock superblock before calling reiserfs_quota_on_mount() 2017-02-23 03:54:00 +00:00
romfs switch simple generic_file_aio_read() users to ->read_iter() 2014-05-06 17:37:55 -04:00
squashfs fs/squashfs/squashfs.h: replace pr_warning by pr_warn 2014-06-04 16:53:52 -07:00
sysfs vfs: Commit to never having exectuables on proc and sysfs. 2017-04-04 22:21:56 +01:00
sysv fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
ubifs ubifs: Fix journal replay wrt. xattr nodes 2017-03-16 02:27:00 +00:00
udf fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
ufs fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
xfs xfs: set AGI buffer type in xlog_recover_clear_agi_bucket 2017-03-16 02:26:28 +00:00
aio.c aio: mark AIO pseudo-fs noexec 2017-04-04 22:21:57 +01:00
anon_inodes.c vfs: Allocate anon_inode_inode in anon_inode_init() 2014-03-27 09:52:54 -07:00
attr.c fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
bad_inode.c [readdir] ->readdir() is gone 2013-06-29 12:57:04 +04:00
binfmt_aout.c dump_skip(): dump_seek() replacement taking coredump_params 2013-11-09 00:16:26 -05:00
binfmt_elf.c binfmt_elf: Don't clobber passed executable's file header 2015-12-13 17:49:24 +00:00
binfmt_elf_fdpic.c elf{,_fdpic} coredump: get rid of pointless if (siginfo->si_signo) 2013-11-09 00:16:30 -05:00
binfmt_em86.c file->f_op is never NULL... 2013-10-24 23:34:54 -04:00
binfmt_flat.c fs/binfmt_flat.c: make old_reloc() static 2014-06-04 16:54:21 -07:00
binfmt_misc.c binfmt_misc: add missing 'break' statement 2014-04-03 16:21:16 -07:00
binfmt_script.c exec: do not leave bprm->interp on stack 2012-12-20 17:40:19 -08:00
binfmt_som.c get rid of pt_regs argument of ->load_binary() 2012-11-28 21:53:38 -05:00
block_dev.c block_dev: don't test bdev->bd_contains when it is not stable 2017-03-16 02:26:36 +00:00
buffer.c fs/buffer.c: support buffer cache allocations with gfp modifiers 2015-08-27 14:53:36 +01:00
char_dev.c Merge branch 'for-3.13/core' of git://git.kernel.dk/linux-block 2013-11-14 12:08:14 +09:00
compat.c fs: namespace: suppress 'may be used uninitialized' warnings 2017-04-04 22:21:52 +01:00
compat_binfmt_elf.c binfmt_elf: add ELF_HWCAP2 to compat auxv entries 2014-03-04 08:05:21 +00:00
compat_ioctl.c fs/compat: convert to COMPAT_SYSCALL_DEFINE with changing parameter types 2014-03-06 16:30:44 +01:00
coredump.c coredump: fix unfreezable coredumping task 2017-02-23 03:54:32 +00:00
dcache.c fix d_walk()/non-delayed __d_free() race 2016-08-22 22:38:10 +01:00
dcookies.c fs/compat: fix lookup_dcookie() parameter handling 2014-01-29 16:22:40 -08:00
direct-io.c fuse: honour max_read and max_write in direct_io mode 2014-11-03 10:46:27 +00:00
drop_caches.c fs: convert use of typedef ctl_table to struct ctl_table 2014-06-06 16:08:16 -07:00
eventfd.c eventfd_ctx_fdget(): use fdget() instead of fget() 2014-01-25 03:13:04 -05:00
eventpoll.c eventpoll: fix uninitialized variable in epoll_ctl 2014-10-05 13:41:07 -07:00
exec.c fs/exec.c: account for argv/envp pointers 2017-07-18 18:40:40 +01:00
fcntl.c locks: rename file-private locks to "open file description locks" 2014-04-22 08:23:58 -04:00
fhandle.c fs/coredump: prevent fsuid=0 dumps into user-controlled directories 2016-05-01 00:06:04 +02:00
file.c fs/file.c: don't open-code kvfree() 2014-05-06 17:31:10 -04:00
file_table.c Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2014-06-12 10:30:18 -07:00
filesystems.c sys_sysfs: Add CONFIG_SYSFS_SYSCALL 2014-04-03 16:21:05 -07:00
fs-writeback.c writeback: fix a subtle race condition in I_DIRTY clearing 2015-01-05 13:48:34 +00:00
fs_struct.c seqcount: Add lockdep functionality to seqcount/seqlock structures 2013-11-06 12:40:26 +01:00
inode.c fs: Fix S_NOSEC handling 2015-07-15 10:00:50 +01:00
internal.h fs: namespace: suppress 'may be used uninitialized' warnings 2017-04-04 22:21:52 +01:00
ioctl.c file->f_op is never NULL... 2013-10-24 23:34:54 -04:00
Kconfig kernfs: add CONFIG_KERNFS 2014-02-07 16:08:57 -08:00
Kconfig.binfmt fs: make binfmt support for #! scripts modular and removable 2013-04-30 17:04:04 -07:00
libfs.c fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
locks.c locks: fix unlock when fcntl_setlk races with a close 2016-02-02 19:09:20 +00:00
Makefile block: move ioprio.c from fs/ to block/ 2014-05-19 11:02:18 -06:00
mbcache.c fs/mbcache: replace __builtin_log2() with ilog2() 2014-06-25 22:08:29 -04:00
mount.h mnt: Add a per mount namespace limit on the number of mounts 2017-02-26 20:01:48 +00:00
mpage.c fs/block_dev.c: add bdev_read_page() and bdev_write_page() 2014-06-04 16:54:02 -07:00
namei.c ima: pass 'opened' flag to identify newly created files 2017-08-26 02:14:23 +01:00
namespace.c fs: namespace: suppress 'may be used uninitialized' warnings 2017-04-04 22:21:52 +01:00
no-block.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
open.c vfs: Commit to never having exectuables on proc and sysfs. 2017-04-04 22:21:56 +01:00
pipe.c pipe: limit the per-user amount of pages allocated in pipes 2016-02-25 10:51:03 +00:00
pnode.c mnt: Add a per mount namespace limit on the number of mounts 2017-02-26 20:01:48 +00:00
pnode.h mnt: Add a per mount namespace limit on the number of mounts 2017-02-26 20:01:48 +00:00
posix_acl.c tmpfs: clear S_ISGID when setting posix ACLs 2017-02-26 20:01:49 +00:00
proc_namespace.c vfs: show_vfsstat: do not ignore errors from show_devname method 2016-05-01 00:06:01 +02:00
read_write.c switch simple generic_file_aio_read() users to ->read_iter() 2014-05-06 17:37:55 -04:00
readdir.c fanotify: create FAN_ACCESS event for readdir 2014-06-04 16:53:52 -07:00
select.c Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-11-13 15:34:18 +09:00
seq_file.c fs/seq_file: fix out-of-bounds read 2016-11-20 01:17:18 +00:00
signalfd.c signalfd: fix information leak in signalfd_copyinfo 2015-09-03 16:43:54 +01:00
splice.c vfs: fix uninitialized flags in splice_to_pipe() 2017-03-16 02:27:14 +00:00
stack.c fs: reduce the use of module.h wherever possible 2012-02-28 19:31:58 -05:00
stat.c vfs: split out vfs_getattr_nosec 2013-11-09 00:16:31 -05:00
statfs.c vfs: allow O_PATH file descriptors for fstatfs() 2013-10-12 13:12:31 -07:00
super.c fs/super.c: fix race between freeze_super() and thaw_super() 2017-02-23 03:54:13 +00:00
sync.c Revert "writeback: do not sync data dirtied after sync start" 2014-02-22 02:02:28 +01:00
timerfd.c timerfd: support CLOCK_BOOTTIME clock 2014-01-23 16:57:40 -08:00
utimes.c fs: Give dentry to inode_change_ok() instead of inode 2017-02-23 03:53:52 +00:00
xattr.c simple_xattr: permit 0-size extended attributes 2014-07-23 15:10:55 -07:00