• Amir Goldstein's avatar
    fanotify: don't expose EOPENSTALE to userspace · 3ea33dcc
    Amir Goldstein authored
    commit 4ff33aaf 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: default avatarMarko Rauhamaa <marko.rauhamaa@f-secure.com>
    Tested-by: default avatarMarko Rauhamaa <marko.rauhamaa@f-secure.com>
    Cc: <linux-api@vger.kernel.org>
    Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
    Signed-off-by: default avatarJan Kara <jack@suse.cz>
    [bwh: Backported to 3.16: adjust context]
    Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
    3ea33dcc
fanotify_user.c 23.5 KB