From: Marko Rauhamaa <marko.rauhamaa-xdZvthzU1HpWk0Htik3J/w@public.gmane.org>
To: Amir Goldstein <amir73il-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: Jeff Layton <jlayton-vpEMnDpepFuMZCB2o+C8xQ@public.gmane.org>,
Al Viro <viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org>,
linux-fsdevel
<linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
Jan Kara <jack-AlSwsSmVLrQ@public.gmane.org>,
Linux NFS Mailing List
<linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: fanotify read returns with errno == EOPENSTALE
Date: Wed, 19 Apr 2017 16:46:03 +0300 [thread overview]
Message-ID: <87lgqwa4tg.fsf@drapion.f-secure.com> (raw)
In-Reply-To: <CAOQ4uxja14p02jQurLTGv_fHrs+UBa5qfacrgY_-7tyv6UJqdw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> (Amir Goldstein's message of "Thu, 23 Mar 2017 09:47:07 -0400")
Amir Goldstein <amir73il-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:
> On Thu, Mar 23, 2017 at 8:43 AM, Marko Rauhamaa
> <marko.rauhamaa-xdZvthzU1HpWk0Htik3J/w@public.gmane.org> wrote:
>> Jeff Layton <jlayton-vpEMnDpepFuMZCB2o+C8xQ@public.gmane.org>:
>>
>>> It was definitely not the intention to leak this error code to
>>> userland. EOPENSTALE is not a POSIX sanctioned error code, so
>>> applications generally don't know anything about it and will be
>>> confused.
>>
>> Got it. I will try to work on a reproduction and make a proper bug
>> report.
>
> Try this:
>
> - watch a single file for permissions events (so you will only have
> one event in the queue)
> - open file from client to generate single event (don't read event yet)
> - remove file from server (to make it stale)
> - read event (with stale file)
I did that and reproduced the problem on a recent development kernel.
Happens every time.
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.
So what do we conclude? Is this a kernel bug or works as designed?
> Oh my. I completely misread your report before. I though you were
> trying to read from the event->fd. Now I understand that you mean read
> from fanotify fd. That will definitely return the error, but only in
> the special case where open error happened on the first event being
> read to the buffer. If error happens after adding some events to the
> buffer, fanotify process will not know about this. Regular event will
> be silently dropped and permission event will be denied.
>
> [...]
>
> You do NOT need to call fanotify_init() again, the next read will read
> the next event.
It does appear that reading the fanotify fd again does the trick.
However, the client gets an EPERM instead of ENOENT, which is a bit
weird.
> The fix seems trivial and I can post it once you have the test:
> - return EAGAIN for read in case of a single event in queue without fd
> so apps getting the read error will have a good idea what to do
> - in case of non single event, maybe copy event with error on event->fd
> to the buffer for specific errors that make sense to report (EMFILE)
> so a watcher checks the values of negative event->fd can maybe do
> something about it (e.g. provide a smaller buffer).
EAGAIN would be perfect for me since I'm using fanotify in a nonblocking
mode. It might be a bit surprising in the blocking case.
Marko
--
+358 44 990 4795
Skype: marko.rauhamaa_f-secure
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
WARNING: multiple messages have this Message-ID (diff)
From: Marko Rauhamaa <marko.rauhamaa@f-secure.com>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Jeff Layton <jlayton@poochiereds.net>,
Al Viro <viro@zeniv.linux.org.uk>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
Jan Kara <jack@suse.cz>,
Linux NFS Mailing List <linux-nfs@vger.kernel.org>,
<linux-api@vger.kernel.org>
Subject: Re: fanotify read returns with errno == EOPENSTALE
Date: Wed, 19 Apr 2017 16:46:03 +0300 [thread overview]
Message-ID: <87lgqwa4tg.fsf@drapion.f-secure.com> (raw)
In-Reply-To: <CAOQ4uxja14p02jQurLTGv_fHrs+UBa5qfacrgY_-7tyv6UJqdw@mail.gmail.com> (Amir Goldstein's message of "Thu, 23 Mar 2017 09:47:07 -0400")
Amir Goldstein <amir73il@gmail.com>:
> On Thu, Mar 23, 2017 at 8:43 AM, Marko Rauhamaa
> <marko.rauhamaa@f-secure.com> wrote:
>> Jeff Layton <jlayton@poochiereds.net>:
>>
>>> It was definitely not the intention to leak this error code to
>>> userland. EOPENSTALE is not a POSIX sanctioned error code, so
>>> applications generally don't know anything about it and will be
>>> confused.
>>
>> Got it. I will try to work on a reproduction and make a proper bug
>> report.
>
> Try this:
>
> - watch a single file for permissions events (so you will only have
> one event in the queue)
> - open file from client to generate single event (don't read event yet)
> - remove file from server (to make it stale)
> - read event (with stale file)
I did that and reproduced the problem on a recent development kernel.
Happens every time.
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.
So what do we conclude? Is this a kernel bug or works as designed?
> Oh my. I completely misread your report before. I though you were
> trying to read from the event->fd. Now I understand that you mean read
> from fanotify fd. That will definitely return the error, but only in
> the special case where open error happened on the first event being
> read to the buffer. If error happens after adding some events to the
> buffer, fanotify process will not know about this. Regular event will
> be silently dropped and permission event will be denied.
>
> [...]
>
> You do NOT need to call fanotify_init() again, the next read will read
> the next event.
It does appear that reading the fanotify fd again does the trick.
However, the client gets an EPERM instead of ENOENT, which is a bit
weird.
> The fix seems trivial and I can post it once you have the test:
> - return EAGAIN for read in case of a single event in queue without fd
> so apps getting the read error will have a good idea what to do
> - in case of non single event, maybe copy event with error on event->fd
> to the buffer for specific errors that make sense to report (EMFILE)
> so a watcher checks the values of negative event->fd can maybe do
> something about it (e.g. provide a smaller buffer).
EAGAIN would be perfect for me since I'm using fanotify in a nonblocking
mode. It might be a bit surprising in the blocking case.
Marko
--
+358 44 990 4795
Skype: marko.rauhamaa_f-secure
next prev parent reply other threads:[~2017-04-19 13:46 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-22 15:31 fanotify read returns with errno == EOPENSTALE Marko Rauhamaa
2017-03-22 18:01 ` Matthew Wilcox
2017-03-22 18:20 ` Amir Goldstein
2017-03-22 19:17 ` Amir Goldstein
2017-03-22 19:31 ` Al Viro
2017-03-22 19:39 ` Amir Goldstein
2017-03-23 8:13 ` Marko Rauhamaa
2017-03-23 11:46 ` Amir Goldstein
2017-03-23 11:56 ` Jeff Layton
2017-03-23 12:43 ` Marko Rauhamaa
[not found] ` <8760j02mfz.fsf-q6puBR44SRrF1m+2HNTUelaTQe2KTcn/@public.gmane.org>
2017-03-23 13:47 ` Amir Goldstein
2017-03-23 13:47 ` Amir Goldstein
2017-03-23 13:47 ` Amir Goldstein
[not found] ` <CAOQ4uxja14p02jQurLTGv_fHrs+UBa5qfacrgY_-7tyv6UJqdw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-04-19 13:46 ` Marko Rauhamaa [this message]
2017-04-19 13:46 ` Marko Rauhamaa
[not found] ` <87lgqwa4tg.fsf-q6puBR44SRrF1m+2HNTUelaTQe2KTcn/@public.gmane.org>
2017-04-20 11:06 ` Amir Goldstein
2017-04-20 11:06 ` Amir Goldstein
[not found] ` <CAOQ4uxirSfVVYBexXrWccDHnE5oqxNgUh3-X5Ey1w4R=nHXDjA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-04-20 11:33 ` Amir Goldstein
2017-04-20 11:33 ` Amir Goldstein
[not found] ` <CAOQ4uxjA8Z7wnwuHFCKeKT1xz0Gh-qS40Y6cfPi3fAM0MKsRuQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-04-20 12:43 ` Marko Rauhamaa
2017-04-20 12:43 ` Marko Rauhamaa
[not found] ` <87shl38d1x.fsf-q6puBR44SRrF1m+2HNTUelaTQe2KTcn/@public.gmane.org>
2017-04-20 13:34 ` Amir Goldstein
2017-04-20 13:34 ` Amir Goldstein
[not found] ` <CAOQ4uxiJyrvEJMhM1jhiE5pCgP0iA_LL4Eo_h7UY00wkTKhbTg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-04-21 13:13 ` Marko Rauhamaa
2017-04-21 13:13 ` Marko Rauhamaa
2017-04-20 14:20 ` Jan Kara
[not found] ` <20170420142035.GE22135-4I4JzKEfoa/jFM9bn6wA6Q@public.gmane.org>
2017-04-20 15:06 ` Amir Goldstein
2017-04-20 15:06 ` Amir Goldstein
[not found] ` <CAOQ4uxgAOJjWP6PHY6WgOkNK0vmaTWnFZN+Jvea7zpjJ_VU8Bw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-04-22 7:22 ` Amir Goldstein
2017-04-22 7:22 ` Amir Goldstein
[not found] ` <CAOQ4uxgkXz+8=m2o_faAh2g2Z21KhAf67WckgPNWhktz1=DaWA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-04-24 7:40 ` Marko Rauhamaa
2017-04-24 7:40 ` Marko Rauhamaa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87lgqwa4tg.fsf@drapion.f-secure.com \
--to=marko.rauhamaa-xdzvthzu1hpwk0htik3j/w@public.gmane.org \
--cc=amir73il-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=jack-AlSwsSmVLrQ@public.gmane.org \
--cc=jlayton-vpEMnDpepFuMZCB2o+C8xQ@public.gmane.org \
--cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.